Author: marek
Date: 2007-09-25 11:11:55 -0400 (Tue, 25 Sep 2007)
New Revision: 86330
Modified:
trunk/mcs/gmcs/ChangeLog
trunk/mcs/gmcs/cs-parser.jay
trunk/mcs/gmcs/generic.cs
trunk/mcs/gmcs/linq.cs
Log:
2007-09-25 Marek Safar <[EMAIL PROTECTED]>
* cs-parser.jay: Use only one block per query expression.
* generics.cs (GenericMethod.Define): Moved local variables collision
check to Block.
* linq.cs: Introduced QueryBlock and removed all blocks from query
clauses.
Modified: trunk/mcs/gmcs/ChangeLog
===================================================================
--- trunk/mcs/gmcs/ChangeLog 2007-09-25 14:38:37 UTC (rev 86329)
+++ trunk/mcs/gmcs/ChangeLog 2007-09-25 15:11:55 UTC (rev 86330)
@@ -1,3 +1,13 @@
+2007-09-25 Marek Safar <[EMAIL PROTECTED]>
+
+ * cs-parser.jay: Use only one block per query expression.
+
+ * generics.cs (GenericMethod.Define): Moved local variables collision
+ check to Block.
+
+ * linq.cs: Introduced QueryBlock and removed all blocks from query
+ clauses.
+
2007-09-23 Marek Safar <[EMAIL PROTECTED]>
* generics.cs: Fixed lower-bound type inference issue for constructed
Modified: trunk/mcs/gmcs/cs-parser.jay
===================================================================
--- trunk/mcs/gmcs/cs-parser.jay 2007-09-25 14:38:37 UTC (rev 86329)
+++ trunk/mcs/gmcs/cs-parser.jay 2007-09-25 15:11:55 UTC (rev 86330)
@@ -46,8 +46,6 @@
Delegate current_delegate;
- Stack query_expression_blocks;
-
GenericMethod current_generic_method;
AnonymousMethodExpression current_anonymous_method;
@@ -5378,46 +5376,60 @@
// LINQ
query_expression
- : from_clause
+ : first_from_clause query_body
{
- query_expression_blocks = null;
- }
- query_body
- {
lexer.QueryParsing = false;
Linq.AQueryClause from = $1 as Linq.AQueryClause;
- if (from == null)
- from = new Linq.QueryStartClause ((Expression)$1);
- from.Tail.Next = (Linq.AQueryClause)$3;
- Block query_block = query_expression_blocks == null ?
- current_block : (Block)query_expression_blocks.Pop ();
- $$ = new Linq.QueryExpression (query_block, from);
- end_block (lexer.Location);
+ from.Tail.Next = (Linq.AQueryClause)$2;
+ $$ = from;
+
+ current_block.SetEndLocation (lexer.Location);
+ current_block = current_block.Parent;
}
;
-from_clause
+first_from_clause
: FROM IDENTIFIER IN expression
{
- start_block (lexer.Location);
+ current_block = new Linq.QueryBlock (current_block, GetLocation
($1));
LocatedToken lt = (LocatedToken) $2;
current_block.AddVariable
(Linq.ImplicitQueryParameter.ImplicitType.Instance, lt.Value, lt.Location);
- $$ = $4;
+ $$ = new Linq.QueryExpression (lt, new Linq.QueryStartClause
((Expression)$4));
}
| FROM type IDENTIFIER IN expression
{
- start_block (GetLocation ($1));
+ current_block = new Linq.QueryBlock (current_block, GetLocation
($1));
LocatedToken lt = (LocatedToken) $3;
Expression type = (Expression)$2;
current_block.AddVariable (type, lt.Value, lt.Location);
- $$ = new Linq.Cast (type, (Expression)$5);
+ $$ = new Linq.QueryExpression (lt, new Linq.Cast (type,
(Expression)$5));
}
;
+
+from_clause
+ : FROM IDENTIFIER IN expression
+ {
+ LocatedToken lt = (LocatedToken) $2;
+
+ current_block.AddVariable
(Linq.ImplicitQueryParameter.ImplicitType.Instance,
+ lt.Value, lt.Location);
+
+ $$ = new Linq.SelectMany (lt, (Expression)$4);
+ }
+ | FROM type IDENTIFIER IN expression
+ {
+ LocatedToken lt = (LocatedToken) $3;
+ Expression type = (Expression)$2;
+ current_block.AddVariable (type, lt.Value, lt.Location);
+ $$ = new Linq.SelectMany (lt, new Linq.Cast (type,
(Expression)$5));
+ }
+ ;
+
query_body
: opt_query_body_clauses select_or_group_clause opt_query_continuation
{
@@ -5463,10 +5475,6 @@
query_body_clause
: from_clause
- {
- $$ = new Linq.SelectMany (current_block, (Expression)$1);
- end_block (lexer.Location);
- }
| let_clause
| where_clause
| join_clause
@@ -5476,12 +5484,10 @@
let_clause
: LET IDENTIFIER ASSIGN expression
{
- start_block (GetLocation ($1));
LocatedToken lt = (LocatedToken) $2;
current_block.AddVariable
(Linq.ImplicitQueryParameter.ImplicitType.Instance,
lt.Value, lt.Location);
- $$ = new Linq.Let (current_block, (Expression)$4, GetLocation
($1));
- end_block (lexer.Location);
+ $$ = new Linq.Let (lt, (Expression)$4, GetLocation ($1));
}
;
@@ -5496,40 +5502,34 @@
: JOIN IDENTIFIER IN expression ON expression EQUALS expression
opt_join_into
{
Location loc = GetLocation ($1);
- start_block (loc);
LocatedToken lt = (LocatedToken) $2;
current_block.AddVariable
(Linq.ImplicitQueryParameter.ImplicitType.Instance,
lt.Value, lt.Location);
if ($9 == null) {
- $$ = new Linq.Join (current_block, (Expression)$4,
(Expression)$6,
+ $$ = new Linq.Join (lt, (Expression)$4, (Expression)$6,
(Expression)$8, loc);
} else {
- lt = (LocatedToken) $9;
- $$ = new Linq.GroupJoin (current_block, (Expression)$4,
(Expression)$6,
- (Expression)$8, lt.Value, loc);
+ LocatedToken lt_into = (LocatedToken) $9;
+ $$ = new Linq.GroupJoin (lt, (Expression)$4,
(Expression)$6,
+ (Expression)$8, lt_into, loc);
}
-
- end_block (lexer.Location);
}
| JOIN type IDENTIFIER IN expression ON expression EQUALS expression
opt_join_into
{
Location loc = GetLocation ($1);
- start_block (loc);
LocatedToken lt = (LocatedToken) $3;
current_block.AddVariable ((Expression)$2, lt.Value,
lt.Location);
Linq.Cast cast = new Linq.Cast ((Expression)$2, (Expression)$5);
if ($10 == null) {
- $$ = new Linq.Join (current_block, cast, (Expression)$7,
+ $$ = new Linq.Join (lt, cast, (Expression)$7,
(Expression)$9, loc);
} else {
- lt = (LocatedToken) $10;
- $$ = new Linq.GroupJoin (current_block, cast,
(Expression)$7,
- (Expression)$9, lt.Value, loc);
+ LocatedToken lt_into = (LocatedToken) $10;
+ $$ = new Linq.GroupJoin (lt, cast, (Expression)$7,
+ (Expression)$9, lt_into, loc);
}
-
- end_block (lexer.Location);
}
;
@@ -5607,21 +5607,19 @@
// query continuation block is not linked with query block but
with block
// before. This means each query can use same range variable
names for
// different identifiers.
-
- if (query_expression_blocks == null) {
- query_expression_blocks = new Stack ();
- query_expression_blocks.Push (current_block);
- }
- end_block (GetLocation ($1));
- start_block (GetLocation ($1));
- query_expression_blocks.Push (current_block);
+ current_block.SetEndLocation (GetLocation ($1));
+ current_block = current_block.Parent;
+ current_block = new Linq.QueryBlock (current_block, GetLocation
($1));
+
LocatedToken lt = (LocatedToken) $2;
- current_block.AddVariable
(Linq.ImplicitQueryParameter.ImplicitType.Instance, lt.Value, lt.Location);
+ current_block.AddVariable
(Linq.ImplicitQueryParameter.ImplicitType.Instance,
+ lt.Value, lt.Location);
}
query_body
{
- $$ = new Linq.QueryExpression
((Block)query_expression_blocks.Pop (), (Linq.AQueryClause)$4);
+ $$ = new Linq.QueryExpression ((LocatedToken) $2,
+ (Linq.AQueryClause)$4);
}
;
Modified: trunk/mcs/gmcs/generic.cs
===================================================================
--- trunk/mcs/gmcs/generic.cs 2007-09-25 14:38:37 UTC (rev 86329)
+++ trunk/mcs/gmcs/generic.cs 2007-09-25 15:11:55 UTC (rev 86330)
@@ -1887,15 +1887,7 @@
Error_ParameterNameCollision
(p.Location, type_argument_name, "method parameter");
return false;
}
-
- // FIXME: This is wrong, since it only looks at
the outermost set of variables
- if (block != null) {
- LocalInfo li =
(LocalInfo)block.Variables [type_argument_name];
- if (li != null) {
- Error_ParameterNameCollision
(li.Location, type_argument_name, "local variable");
- return false;
- }
- }
+
snames[i] = type_argument_name;
}
@@ -1914,7 +1906,7 @@
return true;
}
- static void Error_ParameterNameCollision (Location loc, string
name, string collisionWith)
+ internal static void Error_ParameterNameCollision (Location
loc, string name, string collisionWith)
{
Report.Error (412, loc, "The type parameter name `{0}'
is the same as `{1}'",
name, collisionWith);
Modified: trunk/mcs/gmcs/linq.cs
===================================================================
--- trunk/mcs/gmcs/linq.cs 2007-09-25 14:38:37 UTC (rev 86329)
+++ trunk/mcs/gmcs/linq.cs 2007-09-25 15:11:55 UTC (rev 86330)
@@ -22,28 +22,21 @@
public class QueryExpression : AQueryClause
{
- Block block;
+ LocatedToken variable;
- public QueryExpression (Block block, AQueryClause query)
+ public QueryExpression (LocatedToken variable, AQueryClause
query)
: base (null, query.Location)
{
- this.block = block;
+ this.variable = variable;
this.next = query;
}
public override Expression BuildQueryClause (EmitContext ec,
Expression lSide, Parameter parentParameter, TransparentIdentifiersScope ti)
{
- Parameter p = CreateBlockParameter (block);
+ Parameter p = CreateBlockParameter (variable);
return next.BuildQueryClause (ec, lSide, p, ti);
}
- protected override void CloneTo (CloneContext clonectx,
Expression target)
- {
- QueryExpression t = (QueryExpression) target;
- t.block = (Block)block.Clone (clonectx);
- base.CloneTo (clonectx, t);
- }
-
public override Expression DoResolve (EmitContext ec)
{
Expression e = BuildQueryClause (ec, null, null, null);
@@ -143,16 +136,8 @@
return lSide;
}
- protected static Parameter CreateBlockParameter (Block block)
+ protected static Parameter CreateBlockParameter (LocatedToken
li)
{
- ICollection values = block.Variables.Values;
- if (values.Count != 1)
- throw new NotImplementedException ("Count !=
1");
-
- IEnumerator enumerator = values.GetEnumerator ();
- enumerator.MoveNext ();
- LocalInfo li = (LocalInfo) enumerator.Current;
-
return new ImplicitQueryParameter (li);
}
@@ -221,13 +206,13 @@
//
public abstract class ARangeVariableQueryClause : AQueryClause
{
- Block block;
+ LocatedToken variable;
protected Expression element_selector;
- protected ARangeVariableQueryClause (Block block, Expression
expr, Location loc)
+ protected ARangeVariableQueryClause (LocatedToken variable,
Expression expr, Location loc)
: base (expr, loc)
{
- this.block = block;
+ this.variable = variable;
}
protected virtual void AddSelectorArguments (EmitContext ec,
ArrayList args, Parameter parentParameter,
@@ -244,7 +229,7 @@
//
public override Expression BuildQueryClause (EmitContext ec,
Expression lSide, Parameter parentParameter, TransparentIdentifiersScope ti)
{
- Parameter parameter = CreateBlockParameter (block);
+ Parameter parameter = CreateBlockParameter (variable);
if (next != null) {
//
@@ -284,8 +269,8 @@
protected override void CloneTo (CloneContext clonectx,
Expression target)
{
ARangeVariableQueryClause t =
(ARangeVariableQueryClause) target;
- t.block = (Block) block.Clone (clonectx);
- t.element_selector = element_selector.Clone (clonectx);
+ if (element_selector != null)
+ t.element_selector = element_selector.Clone
(clonectx);
base.CloneTo (clonectx, t);
}
@@ -389,8 +374,8 @@
Expression projection;
Expression inner_selector, outer_selector;
- public Join (Block block, Expression inner, Expression
outerSelector, Expression innerSelector, Location loc)
- : base (block, inner, loc)
+ public Join (LocatedToken variable, Expression inner,
Expression outerSelector, Expression innerSelector, Location loc)
+ : base (variable, inner, loc)
{
this.outer_selector = outerSelector;
this.inner_selector = innerSelector;
@@ -449,11 +434,11 @@
public class GroupJoin : Join
{
- string into_variable;
+ readonly LocatedToken into_variable;
- public GroupJoin (Block block, Expression inner, Expression
outerSelector, Expression innerSelector,
- string into, Location loc)
- : base (block, inner, outerSelector, innerSelector, loc)
+ public GroupJoin (LocatedToken variable, Expression inner,
Expression outerSelector, Expression innerSelector,
+ LocatedToken into, Location loc)
+ : base (variable, inner, outerSelector, innerSelector,
loc)
{
this.into_variable = into;
}
@@ -464,7 +449,7 @@
// into variable is used as result selector and it's
passed as
// transparent identifiers to the next clause
//
- return new ImplicitLambdaParameter (into_variable, loc);
+ return CreateBlockParameter (into_variable);
}
protected override string MethodName {
@@ -499,8 +484,8 @@
}
}
- public Let (Block block, Expression expr, Location loc)
- : base (block, expr, loc)
+ public Let (LocatedToken variable, Expression expr, Location
loc)
+ : base (variable, expr, loc)
{
}
@@ -547,8 +532,8 @@
public class SelectMany : ARangeVariableQueryClause
{
- public SelectMany (Block block, Expression expr)
- : base (block, expr, expr.Location)
+ public SelectMany (LocatedToken variable, Expression expr)
+ : base (variable, expr, expr.Location)
{
}
@@ -655,22 +640,10 @@
}
}
- readonly LocalInfo variable;
-
- public ImplicitQueryParameter (LocalInfo variable)
- : base (variable.Name, variable.Location)
+ public ImplicitQueryParameter (LocatedToken variable)
+ : base (variable.Value, variable.Location)
{
- this.variable = variable;
}
-
- public override bool Resolve (IResolveContext ec)
- {
- if (!base.Resolve (ec))
- return false;
-
- variable.VariableType = parameter_type;
- return true;
- }
}
//
@@ -758,10 +731,58 @@
public override Expression GetTransparentIdentifier (string
name)
{
- if (transparent_identifiers == null)
- return null;
+ Expression expr = null;
+ if (transparent_identifiers != null)
+ expr = transparent_identifiers.GetIdentifier
(name);
- return transparent_identifiers.GetIdentifier (name);
+ if (expr != null || Container == null)
+ return expr;
+
+ return Container.GetTransparentIdentifier (name);
}
}
+
+ //
+ // This block is actually never used, it is used by parser only
+ //
+ public class QueryBlock : Block
+ {
+ Hashtable range_variables = new Hashtable ();
+
+ public QueryBlock (Block parent, Location start)
+ : base (parent, start, Location.Null)
+ {
+ }
+
+ protected override void AddVariable (LocalInfo li)
+ {
+ string name = li.Name;
+ if (range_variables.Contains (name)) {
+ Location conflict = (Location)range_variables
[name];
+ Report.SymbolRelatedToPreviousError (conflict,
name);
+ Error_AlreadyDeclared (li.Location, name);
+ return;
+ }
+
+ range_variables.Add (name, li.Location);
+ }
+
+ protected override void Error_AlreadyDeclared (Location loc,
string var, string reason)
+ {
+ Report.Error (1931, loc, "A range variable `{0}'
conflicts with a previous declaration of `{0}'",
+ var);
+ }
+
+ protected override void Error_AlreadyDeclared (Location loc,
string var)
+ {
+ Report.Error (1930, loc, "A range variable `{0}' has
already been declared in this scope",
+ var);
+ }
+
+ protected override void Error_AlreadyDeclaredTypeParameter
(Location loc, string name)
+ {
+ Report.Error (1948, loc, "A range variable `{0}'
conflicts with a method type parameter",
+ name);
+ }
+ }
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches