;
opt_formal_parameter_list
- : /* empty */ { $$ = Parameters.GetEmptyReadOnlyParameters (); }
+ : /* empty */ { $$ = Parameters.EmptyReadOnlyParameters; }
| formal_parameter_list
;
;
parameter_modifier
- : REF { $$ = Parameter.Modifier.REF; }
- | OUT { $$ = Parameter.Modifier.OUT; }
+ : REF { $$ = Parameter.Modifier.REF | Parameter.Modifier.ISBYREF; }
+ | OUT { $$ = Parameter.Modifier.OUT | Parameter.Modifier.ISBYREF; }
;
parameter_array
constructor_initializer
: COLON BASE OPEN_PARENS opt_argument_list CLOSE_PARENS
{
- $$ = new ConstructorBaseInitializer ((ArrayList) $4, lexer.Location);
+ $$ = new ConstructorBaseInitializer ((ArrayList) $4, current_local_parameters, lexer.Location);
}
| COLON THIS OPEN_PARENS opt_argument_list CLOSE_PARENS
{
- $$ = new ConstructorThisInitializer ((ArrayList) $4, lexer.Location);
+ $$ = new ConstructorThisInitializer ((ArrayList) $4, current_local_parameters, lexer.Location);
}
;
this_access
: THIS
{
- $$ = new This (lexer.Location);
+ $$ = new This (current_block, lexer.Location);
}
;
checked_expression
: CHECKED OPEN_PARENS expression CLOSE_PARENS
{
- $$ = new CheckedExpr ((Expression) $3);
+ $$ = new CheckedExpr ((Expression) $3, lexer.Location);
}
;
unchecked_expression
: UNCHECKED OPEN_PARENS expression CLOSE_PARENS
{
- $$ = new UnCheckedExpr ((Expression) $3);
+ $$ = new UnCheckedExpr ((Expression) $3, lexer.Location);
}
;
block
: OPEN_BRACE
{
- current_block = new Block (current_block, lexer.Location, Location.Null);
+ current_block = new Block (current_block, current_local_parameters,
+ lexer.Location, Location.Null);
}
opt_statement_list CLOSE_BRACE
{
labeled_statement
: IDENTIFIER COLON
{
- LabeledStatement labeled = new LabeledStatement ((string) $1);
+ LabeledStatement labeled = new LabeledStatement ((string) $1, lexer.Location);
if (!current_block.AddLabel ((string) $1, labeled)){
Location l = lexer.Location;
vi = current_block.AddVariable (
type, decl.identifier, current_local_parameters, decl.Location);
- if (vi == null){
- Report.Error (128, decl.Location,
- "A local variable `" + decl.identifier +
- "' is already defined in this scope");
+ if (vi == null)
+ continue;
+
+ Location l = lexer.Location;
+ Expression expr;
+ if (decl.expression_or_array_initializer is Expression){
+ expr = (Expression) decl.expression_or_array_initializer;
} else {
- Location l = lexer.Location;
- Expression expr;
- if (decl.expression_or_array_initializer is Expression){
- expr = (Expression) decl.expression_or_array_initializer;
-
- } else {
- ArrayList init = (ArrayList) decl.expression_or_array_initializer;
- expr = new ArrayCreation (type, "", init, decl.Location);
- }
+ ArrayList init = (ArrayList) decl.expression_or_array_initializer;
+ expr = new ArrayCreation (type, "", init, decl.Location);
+ }
- LocalVariableReference var;
- var = new LocalVariableReference (
- assign_block, decl.identifier, l);
+ LocalVariableReference var;
+ var = new LocalVariableReference (assign_block, decl.identifier, l);
- Assign a = new Assign (var, expr, decl.Location);
+ Assign a = new Assign (var, expr, decl.Location);
- assign_block.AddStatement (new StatementExpression (a, lexer.Location));
- }
+ assign_block.AddStatement (new StatementExpression (a, lexer.Location));
}
$3 = null;
oob_stack.Push (current_block);
Block foreach_block = new Block (current_block, true);
- LocalVariableReference v;
+ LocalVariableReference v = null;
Location l = lexer.Location;
VariableInfo vi;
vi = foreach_block.AddVariable ((Expression) $3, (string) $4, current_local_parameters, l);
- vi.ReadOnly = true;
- if (vi == null){
- Report.Error (
- 128, l, "A local variable `" + (string) $4 + "' is already "+
- "defined in this scope");
- }
+ if (vi != null) {
+ vi.ReadOnly = true;
- v = new LocalVariableReference (foreach_block, (string) $4, l);
+ // Get a writable reference to this read-only variable.
+ v = new LocalVariableReference (foreach_block, (string) $4, l, vi, false);
+ }
current_block = foreach_block;
oob_stack.Push (v);
current_block = prev_block;
- Foreach f = new Foreach ((Expression) $3, v, (Expression) $7, (Statement) $10, l);
- foreach_block.AddStatement (f);
+ if (v != null) {
+ Foreach f = new Foreach ((Expression) $3, v, (Expression) $7, (Statement) $10, l);
+ foreach_block.AddStatement (f);
+ }
$$ = foreach_block;
}
ArrayList s = new ArrayList ();
foreach (Catch cc in (ArrayList) $3) {
- if (cc.Type == null)
+ if (cc.IsGeneral)
g = cc;
else
s.Add (cc);
// Now s contains the list of specific catch clauses
// and g contains the general one.
- $$ = new Try ((Block) $2, s, g, null);
+ $$ = new Try ((Block) $2, s, g, null, lexer.Location);
}
| TRY block opt_catch_clauses FINALLY block
{
if (catch_list != null){
foreach (Catch cc in catch_list) {
- if (cc.Type == null)
+ if (cc.IsGeneral)
g = cc;
else
s.Add (cc);
}
}
- $$ = new Try ((Block) $2, s, g, (Block) $5);
+ $$ = new Try ((Block) $2, s, g, (Block) $5, lexer.Location);
}
| TRY block error
{
VariableInfo v;
v = current_block.AddVariable (type, (string) p.First,current_local_parameters, l);
- if (v == null){
- Report.Error (
- 128, l, "A local variable `" + (string) p.First + "' is already "+
- "defined in this scope");
- }
+ if (v == null)
+ continue;
v.ReadOnly = true;
p.First = v;
list [i] = p;
Expression type = (Expression) de.Key;
ArrayList var_declarators = (ArrayList) de.Value;
- foreach (VariableDeclaration decl in var_declarators){
- if (current_block.AddVariable (
- type, decl.identifier,
- current_local_parameters, decl.Location) == null){
- Report.Error (128, decl.Location,
- "A local variable `" + decl.identifier + "' is already" +
- "defined in this scope");
- }
- }
-
ArrayList vars = new ArrayList ();
foreach (VariableDeclaration decl in var_declarators){
+ VariableInfo vi = current_block.AddVariable (
+ type, decl.identifier,
+ current_local_parameters, decl.Location);
+ if (vi == null)
+ continue;
+ vi.ReadOnly = true;
+
Expression expr;
if (decl.expression_or_array_initializer is Expression){
expr = (Expression) decl.expression_or_array_initializer;
}
LocalVariableReference var;
- VariableInfo vi;
- var = new LocalVariableReference (assign_block, decl.identifier, l);
- vi = var.VariableInfo;
- vi.ReadOnly = true;
+ // Get a writable reference to this read-only variable.
+ var = new LocalVariableReference (assign_block, decl.identifier, l, vi, false);
// This is so that it is not a warning on using variables
vi.Used = true;
CheckDef (AdditionResult.NameExists, name, l);
}
-//
-// This routine should be removed soon. I am in the process of making
-// changes to never keep anything but SimpleNames during parsing, as
-// that breaks some kinds of code (documented in the ChangeLog).
-//
-Expression
-SimpleLookup (string name, Location loc)
-{
- //
- // we need to check against current_block not being null
- // as `expression' is allowed in argument_lists, which
- // do not exist inside a block.
- //
-
- if (current_local_parameters != null){
- int idx;
- Parameter par = current_local_parameters.GetParameterByName (name, out idx);
- if (par != null)
- return new ParameterReference (current_local_parameters, idx, name);
- }
-
- return null;
-}
-
Expression DecomposeQI (string name, Location loc)
{
Expression o;
if (name.IndexOf ('.') == -1){
- o = SimpleLookup (name, loc);
- if (o == null)
- return new SimpleName (name, loc);
- return o;
+ return new SimpleName (name, loc);
} else {
int pos = name.LastIndexOf (".");
string left = name.Substring (0, pos);
string right = name.Substring (pos + 1);
o = DecomposeQI (left, loc);
+
return new MemberAccess (o, right, loc);
}
}
inits = new ArrayList ();
inits.Add (decl);
}
- } else {
- Report.Error (128, decl.Location, "A local variable `" + decl.identifier +
- "' is already defined in this scope");
}
}
if (!(implicit_block.AddConstant (type, decl.identifier, (Expression) decl.expression_or_array_initializer,
current_local_parameters, decl.Location))){
- Report.Error (128, decl.Location, "A local variable `" + decl.identifier +
- "' is already defined in this scope");
}
return implicit_block;