All = Ref | Out | This | Params | Arglist | DefaultValue
}
+
+ static readonly object ModifierNone = 0;
NamespaceEntry current_namespace;
TypeContainer current_container;
DeclSpace current_class;
+ PropertyBase current_property;
+ EventProperty current_event;
+ EventField current_event_field;
+ FieldBase current_field;
/// <summary>
/// Current block is used to add statements as we find
Delegate current_delegate;
- GenericMethod current_generic_method;
AnonymousMethodExpression current_anonymous_method;
/// <summary>
// on all places, especially when some parameters are autogenerated.
ParametersCompiled current_local_parameters;
- /// <summary>
- /// Using during property parsing to describe the implicit
- /// value parameter that is passed to the "set" and "get"accesor
- /// methods (properties and indexers).
- /// </summary>
- FullNamedExpression implicit_value_parameter_type;
- ParametersCompiled indexer_parameters;
-
- /// <summary>
- /// Used to determine if we are parsing the get/set pair
- /// of an indexer or a property
- /// </summmary>
- bool parsing_indexer;
-
bool parsing_anonymous_method;
///
/// assembly and module attribute definitions are enabled
bool global_attrs_enabled = true;
- bool has_get, has_set;
ParameterModifierType valid_param_mod;
//
public Undo undo;
- Stack<Block> linq_clause_blocks;
+ Stack<Linq.QueryBlock> linq_clause_blocks;
// A counter to create new class names in interactive mode
static int class_count;
//
static List<Parameter> parameters_bucket = new List<Parameter> (6);
static List<object> variables_bucket = new List<object> (6);
+
+ //
+ // Full AST support members
+ //
+ LocationsBag lbag;
+ List<Tuple<Modifiers, Location>> mod_locations;
%}
%token EOF
%token OPEN_PARENS_CAST
%token GENERIC_DIMENSION
%token DEFAULT_COLON
+%token OPEN_BRACKET_EXPR
// Make the parser go into eval mode parsing (statements and compilation units).
%token EVAL_STATEMENT_PARSER
;
named_attribute_argument
- : IDENTIFIER ASSIGN expression
+ : IDENTIFIER ASSIGN
+ {
+ ++lexer.parsing_block;
+ }
+ expression
{
+ --lexer.parsing_block;
var lt = (Tokenizer.LocatedToken) $1;
- $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $3);
+ $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4);
}
;
}
;
-class_body
- : OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
- ;
-
opt_class_member_declarations
: /* empty */
| class_member_declarations
if (RootContext.Documentation != null)
current_container.DocComment = Lexer.consume_doc_comment ();
+
+ lbag.AddMember (current_class, mod_locations, GetLocation ($4));
}
struct_body
{
}
opt_semicolon
{
+ lbag.AppendToMember (current_class, GetLocation ($13));
$$ = pop_current_class ();
}
| opt_attributes opt_modifiers opt_partial STRUCT error {
Lexer.doc_state = XmlCommentState.Allowed;
}
opt_struct_member_declarations CLOSE_BRACE
+ {
+ lbag.AppendToMember (current_class, GetLocation ($1), GetLocation ($4));
+ }
;
opt_struct_member_declarations
*/
| destructor_declaration
;
-
+
constant_declaration
: opt_attributes
opt_modifiers
- CONST
- type
- constant_declarators
- SEMICOLON
+ CONST type IDENTIFIER
{
- var modflags = (Modifiers) $2;
- foreach (VariableDeclaration constant in (List<object>) $5){
- Location l = constant.Location;
- if ((modflags & Modifiers.STATIC) != 0) {
- Report.Error (504, l, "The constant `{0}' cannot be marked static", current_container.GetSignatureForError () + "." + (string) constant.identifier);
- continue;
- }
-
- Const c = new Const (
- current_class, (FullNamedExpression) $4, (string) constant.identifier,
- constant.GetInitializer ((FullNamedExpression) $4), modflags,
- (Attributes) $1, l);
-
- if (RootContext.Documentation != null) {
- c.DocComment = Lexer.consume_doc_comment ();
- Lexer.doc_state = XmlCommentState.Allowed;
- }
- current_container.AddConstant (c);
+ var lt = (Tokenizer.LocatedToken) $5;
+ var mod = (Modifiers) $2;
+ current_field = new Const (current_class, (FullNamedExpression) $4, mod, new MemberName (lt.Value, lt.Location), (Attributes) $1);
+ current_container.AddConstant ((Const) current_field);
+
+ if ((mod & Modifiers.STATIC) != 0) {
+ Report.Error (504, current_field.Location, "The constant `{0}' cannot be marked static", current_field.GetSignatureForError ());
}
+
+ $$ = current_field;
+ }
+ constant_initializer opt_constant_declarators SEMICOLON
+ {
+ if (RootContext.Documentation != null) {
+ current_field.DocComment = Lexer.consume_doc_comment ();
+ Lexer.doc_state = XmlCommentState.Allowed;
+ }
+
+ current_field.Initializer = (ConstInitializer) $7;
+ lbag.AddMember (current_field, mod_locations, GetLocation ($3), GetLocation ($9));
+ current_field = null;
}
;
-
+
+opt_constant_declarators
+ : /* empty */
+ | constant_declarators
+ ;
+
constant_declarators
- : constant_declarator
+ : constant_declarator
{
- variables_bucket.Clear ();
- if ($1 != null)
- variables_bucket.Add ($1);
- $$ = variables_bucket;
+ current_field.AddDeclarator ((FieldDeclarator) $1);
}
- | constant_declarators COMMA constant_declarator
+ | constant_declarators constant_declarator
{
- if ($3 != null) {
- var constants = (List<object>) $1;
- constants.Add ($3);
- }
+ current_field.AddDeclarator ((FieldDeclarator) $2);
}
;
-
+
constant_declarator
- : IDENTIFIER ASSIGN
+ : COMMA IDENTIFIER constant_initializer
{
- ++lexer.parsing_block;
- }
- constant_initializer
+ var lt = (Tokenizer.LocatedToken) $2;
+ $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (ConstInitializer) $3);
+ lbag.AddLocation ($$, GetLocation ($1));
+ }
+ ;
+
+constant_initializer
+ : ASSIGN
{
- --lexer.parsing_block;
- $$ = new VariableDeclaration ((Tokenizer.LocatedToken) $1, (Expression) $4);
+ ++lexer.parsing_block;
}
- | IDENTIFIER
+ constant_initializer_expr
{
- // A const field requires a value to be provided
- Report.Error (145, GetLocation ($1), "A const field requires a value to be provided");
- $$ = null;
+ --lexer.parsing_block;
+ $$ = new ConstInitializer (current_field, (Expression) $3, GetLocation ($1));
}
+ | error
+ {
+ Report.Error (145, lexer.Location, "A const field requires a value to be provided");
+ $$ = null;
+ }
;
-constant_initializer
+constant_initializer_expr
: constant_expression
| array_initializer
;
field_declaration
: opt_attributes
opt_modifiers
- member_type
- variable_declarators
- SEMICOLON
- {
+ member_type IDENTIFIER
+ {
+ lexer.parsing_generic_declaration = false;
+
FullNamedExpression type = (FullNamedExpression) $3;
- if (type == TypeManager.system_void_expr)
+ if (type.Type == TypeManager.void_type)
Report.Error (670, GetLocation ($3), "Fields cannot have void type");
-
- var mod = (Modifiers) $2;
-
- foreach (VariableMemberDeclaration var in (List<object>) $4){
- Field field = new Field (current_class, type, mod, var.MemberName, (Attributes) $1);
-
- field.Initializer = var.GetInitializer (type);
-
- if (RootContext.Documentation != null) {
- field.DocComment = Lexer.consume_doc_comment ();
- Lexer.doc_state = XmlCommentState.Allowed;
- }
- current_container.AddField (field);
- $$ = field; // FIXME: might be better if it points to the top item
+
+ var lt = (Tokenizer.LocatedToken) $4;
+ current_field = new Field (current_class, type, (Modifiers) $2, new MemberName (lt.Value, lt.Location), (Attributes) $1);
+ current_container.AddField (current_field);
+ $$ = current_field;
+ }
+ opt_field_initializer
+ opt_field_declarators
+ SEMICOLON
+ {
+ if (RootContext.Documentation != null) {
+ current_field.DocComment = Lexer.consume_doc_comment ();
+ Lexer.doc_state = XmlCommentState.Allowed;
}
+
+ lbag.AddMember (current_field, mod_locations, GetLocation ($8));
+ $$ = current_field;
+ current_field = null;
}
| opt_attributes
opt_modifiers
- FIXED
- member_type
- fixed_variable_declarators
- SEMICOLON
+ FIXED simple_type IDENTIFIER
{
- FullNamedExpression type = (FullNamedExpression) $4;
-
- var mod = (Modifiers) $2;
+ if (RootContext.Version < LanguageVersion.ISO_2)
+ Report.FeatureIsNotAvailable (GetLocation ($3), "fixed size buffers");
- foreach (VariableDeclaration var in (List<VariableDeclaration>) $5) {
- FixedField field = new FixedField (current_class, type, mod, var.identifier,
- var.GetInitializer (type), (Attributes) $1, var.Location);
+ var lt = (Tokenizer.LocatedToken) $5;
+ current_field = new FixedField (current_class, (FullNamedExpression) $4, (Modifiers) $2,
+ new MemberName (lt.Value, lt.Location), (Attributes) $1);
+
+ current_container.AddField (current_field);
+ }
+ fixed_field_size opt_fixed_field_declarators SEMICOLON
+ {
+ if (RootContext.Documentation != null) {
+ current_field.DocComment = Lexer.consume_doc_comment ();
+ Lexer.doc_state = XmlCommentState.Allowed;
+ }
- if (RootContext.Documentation != null) {
- field.DocComment = Lexer.consume_doc_comment ();
- Lexer.doc_state = XmlCommentState.Allowed;
- }
- current_container.AddField (field);
- $$ = field; // FIXME: might be better if it points to the top item
- }
+ current_field.Initializer = (ConstInitializer) $7;
+ lbag.AddMember (current_field, mod_locations, GetLocation ($9));
+ $$ = current_field;
+ current_field = null;
}
| opt_attributes
opt_modifiers
- FIXED
- member_type
- error
+ FIXED simple_type error
+ SEMICOLON
+ {
+ Report.Error (1641, GetLocation ($5), "A fixed size buffer field must have the array size specifier after the field name");
+ }
+ ;
+
+opt_field_initializer
+ : /* empty */
+ | ASSIGN
{
- Report.Error (1641, GetLocation ($4), "A fixed size buffer field must have the array size specifier after the field name");
+ ++lexer.parsing_block;
+ }
+ variable_initializer
+ {
+ --lexer.parsing_block;
+ current_field.Initializer = (Expression) $3;
+ }
+ ;
+
+opt_field_declarators
+ : /* empty */
+ | field_declarators
+ ;
+
+field_declarators
+ : field_declarator
+ {
+ current_field.AddDeclarator ((FieldDeclarator) $1);
+ }
+ | field_declarators field_declarator
+ {
+ current_field.AddDeclarator ((FieldDeclarator) $2);
}
;
+
+field_declarator
+ : COMMA IDENTIFIER
+ {
+ var lt = (Tokenizer.LocatedToken) $2;
+ $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
+ lbag.AddLocation ($$, GetLocation ($1));
+ }
+ | COMMA IDENTIFIER ASSIGN
+ {
+ ++lexer.parsing_block;
+ }
+ variable_initializer
+ {
+ --lexer.parsing_block;
+ var lt = (Tokenizer.LocatedToken) $2;
+ $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
+ lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
+ }
+ ;
-fixed_variable_declarators
- : fixed_variable_declarator
+opt_fixed_field_declarators
+ : /* empty */
+ | fixed_field_declarators
+ ;
+
+fixed_field_declarators
+ : fixed_field_declarator
{
- var decl = new List<VariableDeclaration> (2);
- decl.Add ((VariableDeclaration)$1);
- $$ = decl;
- }
- | fixed_variable_declarators COMMA fixed_variable_declarator
+ current_field.AddDeclarator ((FieldDeclarator) $1);
+ }
+ | fixed_field_declarators fixed_field_declarator
{
- var decls = (List<VariableDeclaration>) $1;
- decls.Add ((VariableDeclaration)$3);
- $$ = $1;
+ current_field.AddDeclarator ((FieldDeclarator) $2);
+ }
+ ;
+
+fixed_field_declarator
+ : COMMA IDENTIFIER fixed_field_size
+ {
+ var lt = (Tokenizer.LocatedToken) $2;
+ $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (ConstInitializer) $3);
+ lbag.AddLocation ($$, GetLocation ($1));
}
;
-fixed_variable_declarator
- : IDENTIFIER OPEN_BRACKET expression CLOSE_BRACKET
+fixed_field_size
+ : OPEN_BRACKET
{
- $$ = new VariableDeclaration ((Tokenizer.LocatedToken) $1, (Expression) $3);
+ ++lexer.parsing_block;
}
- | IDENTIFIER OPEN_BRACKET CLOSE_BRACKET
+ expression CLOSE_BRACKET
{
- Report.Error (443, lexer.Location, "Value or constant expected");
- $$ = new VariableDeclaration ((Tokenizer.LocatedToken) $1, null);
+ --lexer.parsing_block;
+ $$ = new ConstInitializer (current_field, (Expression) $3, GetLocation ($1));
+ lbag.AddLocation ($$, GetLocation ($4));
}
+ | OPEN_BRACKET error
+ {
+ Report.Error (443, lexer.Location, "Value or constant expected");
+ $$ = null;
+ }
;
{
var decls = (List<object>) $1;
decls.Add ($3);
+ lbag.AppendTo ($3, GetLocation ($2));
$$ = $1;
}
;
: IDENTIFIER ASSIGN local_variable_initializer
{
$$ = new VariableDeclaration ((Tokenizer.LocatedToken) $1, (Expression) $3);
+ lbag.AddLocation ($$, GetLocation ($2));
}
| IDENTIFIER
{
local_variable_initializer
: expression
| array_initializer
- | STACKALLOC simple_type OPEN_BRACKET expression CLOSE_BRACKET
+ | STACKALLOC simple_type OPEN_BRACKET_EXPR expression CLOSE_BRACKET
{
$$ = new StackAlloc ((Expression) $2, (Expression) $4, GetLocation ($1));
+ lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
}
| ARGLIST
{
}
;
-variable_declarators
- : variable_declarator
- {
- variables_bucket.Clear ();
- if ($1 != null)
- variables_bucket.Add ($1);
- $$ = variables_bucket;
- }
- | variable_declarators COMMA variable_declarator
- {
- var decls = (List<object>) $1;
- decls.Add ($3);
- $$ = $1;
- }
- ;
-
-variable_declarator
- : member_declaration_name ASSIGN
- {
- ++lexer.parsing_block;
- lexer.parsing_generic_declaration = false;
- }
- variable_initializer
- {
- --lexer.parsing_block;
- $$ = new VariableMemberDeclaration ((MemberName) $1, (Expression) $4);
- }
- | member_declaration_name
- {
- lexer.parsing_generic_declaration = false;
- $$ = new VariableMemberDeclaration ((MemberName) $1, null);
- }
- | member_declaration_name variable_bad_array
- {
- lexer.parsing_generic_declaration = false;
- $$ = null;
- }
- ;
-
variable_bad_array
- : OPEN_BRACKET opt_expression CLOSE_BRACKET
+ : OPEN_BRACKET_EXPR opt_expression CLOSE_BRACKET
{
Report.Error (650, GetLocation ($1), "Syntax error, bad array declarator. To declare a managed array the rank specifier precedes the variable's identifier. " +
"To declare a fixed size buffer field, use the fixed keyword before the field type");
Report.Error (531, method.Location, "`{0}': interface members cannot have a definition", method.GetSignatureForError ());
}
- current_generic_method = null;
current_local_parameters = null;
if (RootContext.Documentation != null)
MemberName name = (MemberName) $4;
current_local_parameters = (ParametersCompiled) $7;
- if ($10 != null && name.TypeArguments == null)
- Report.Error (80, lexer.Location,
- "Constraints are not allowed on non-generic declarations");
-
- Method method;
-
GenericMethod generic = null;
if (name.TypeArguments != null) {
generic = new GenericMethod (current_namespace, current_class, name,
(FullNamedExpression) $3, current_local_parameters);
generic.SetParameterInfo ((List<Constraints>) $10);
+ } else if ($10 != null) {
+ Report.Error (80, GetLocation ($10),
+ "Constraints are not allowed on non-generic declarations");
}
- method = new Method (current_class, generic, (FullNamedExpression) $3, (Modifiers) $2,
+ Method method = new Method (current_class, generic, (FullNamedExpression) $3, (Modifiers) $2,
name, current_local_parameters, (Attributes) $1);
-
- current_generic_method = generic;
+
+ if ($10 != null && ((method.ModFlags & Modifiers.OVERRIDE) != 0 || method.IsExplicitImpl)) {
+ Report.Error (460, method.Location,
+ "`{0}': Cannot specify constraints for overrides and explicit interface implementation methods",
+ method.GetSignatureForError ());
+ }
if (RootContext.Documentation != null)
method.DocComment = Lexer.consume_doc_comment ();
+ lbag.AddMember (method, mod_locations, GetLocation ($5), GetLocation ($8));
$$ = method;
}
| opt_attributes
GenericMethod generic = null;
if (name.TypeArguments != null) {
generic = new GenericMethod (current_namespace, current_class, name,
- TypeManager.system_void_expr, current_local_parameters);
+ new TypeExpression (TypeManager.void_type, GetLocation ($4)),
+ current_local_parameters);
generic.SetParameterInfo ((List<Constraints>) $11);
}
modifiers |= Modifiers.PARTIAL | Modifiers.PRIVATE;
- method = new Method (current_class, generic, TypeManager.system_void_expr,
+ method = new Method (current_class, generic, new TypeExpression (TypeManager.void_type, GetLocation ($4)),
modifiers, name, current_local_parameters, (Attributes) $1);
- current_generic_method = generic;
-
if (RootContext.Documentation != null)
method.DocComment = Lexer.consume_doc_comment ();
+ // TODO: lbag, push void
+ StoreModifierLocation (Modifiers.PARTIAL, GetLocation ($3));
+ lbag.AddMember (method, mod_locations, GetLocation ($6), GetLocation ($9));
$$ = method;
}
| opt_attributes
Report.Error (1585, name.Location,
"Member modifier `{0}' must precede the member type and name", ModifiersExtensions.Name ((Modifiers) $4));
- Method method = new Method (current_class, null, TypeManager.system_void_expr,
+ Method method = new Method (current_class, null, (FullNamedExpression) $3,
0, name, (ParametersCompiled) $7, (Attributes) $1);
current_local_parameters = (ParametersCompiled) $7;
default_parameter_used |= p.HasDefaultValue;
pars.Add (p);
+
+ lbag.AddLocation (p, GetLocation ($2));
}
+
$$ = $1;
}
;
parameter_type
IDENTIFIER
ASSIGN
+ {
+ ++lexer.parsing_block;
+ }
constant_expression
{
+ --lexer.parsing_block;
if (RootContext.Version <= LanguageVersion.V_3) {
Report.FeatureIsNotAvailable (GetLocation ($5), "optional parameter");
}
}
if ((valid_param_mod & ParameterModifierType.DefaultValue) == 0)
- Report.Error (1065, GetLocation ($6), "Optional parameter is not valid in this context");
+ Report.Error (1065, GetLocation ($5), "Optional parameter is not valid in this context");
var lt = (Tokenizer.LocatedToken) $4;
$$ = new Parameter ((FullNamedExpression) $3, lt.Value, mod, (Attributes) $1, lt.Location);
- if ($6 != null)
- ((Parameter) $$).DefaultValue = (Expression) $6;
+ lbag.AddLocation ($$, GetLocation ($5));
+
+ if ($7 != null)
+ ((Parameter) $$).DefaultValue = (Expression) $7;
}
;
var lt = (Tokenizer.LocatedToken) $4;
$$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
}
- | opt_attributes params_modifier type error {
+ | opt_attributes params_modifier type error
+ {
CheckIdentifierToken (yyToken, GetLocation ($4));
$$ = null;
}
if (RootContext.Documentation != null)
tmpComment = Lexer.consume_doc_comment ();
}
- OPEN_BRACE
+ OPEN_BRACE
{
- implicit_value_parameter_type = (FullNamedExpression) $3;
+ current_property = new Property (current_class, (FullNamedExpression) $3, (Modifiers) $2,
+ (MemberName) $4, (Attributes) $1);
+
+ if (current_property.TypeExpression.Type == TypeManager.void_type)
+ Report.Error (547, GetLocation ($3), "`{0}': property or indexer cannot have void type", current_property.GetSignatureForError ());
+
+ current_container.AddProperty ((Property)current_property);
+ lbag.AddMember (current_property, mod_locations, GetLocation ($6));
+
lexer.PropertyParsing = true;
}
accessor_declarations
{
lexer.PropertyParsing = false;
- has_get = has_set = false;
+
+ if (RootContext.Documentation != null)
+ current_property.DocComment = ConsumeStoredComment ();
}
CLOSE_BRACE
- {
- Property prop;
- Accessors accessors = (Accessors) $8;
- Accessor get_block = accessors != null ? accessors.get_or_add : null;
- Accessor set_block = accessors != null ? accessors.set_or_remove : null;
- bool order = accessors != null ? accessors.declared_in_reverse : false;
-
- MemberName name = (MemberName) $4;
- FullNamedExpression ptype = (FullNamedExpression) $3;
+ {
+ lbag.AppendToMember (current_property, GetLocation ($10));
+ current_property = null;
+ }
+ ;
- prop = new Property (current_class, ptype, (Modifiers) $2,
- name, (Attributes) $1, get_block, set_block, order, current_block);
- if (ptype == TypeManager.system_void_expr)
- Report.Error (547, name.Location, "`{0}': property or indexer cannot have void type", prop.GetSignatureForError ());
+indexer_declaration
+ : opt_attributes opt_modifiers
+ member_type indexer_declaration_name OPEN_BRACKET
+ {
+ valid_param_mod = ParameterModifierType.Params | ParameterModifierType.DefaultValue;
+ }
+ opt_formal_parameter_list CLOSE_BRACKET OPEN_BRACE
+ {
+ valid_param_mod = 0;
+
+ Indexer indexer = new Indexer (current_class, (FullNamedExpression) $3,
+ (MemberName)$4, (Modifiers) $2, (ParametersCompiled) $7, (Attributes) $1);
- if (accessors == null)
- Report.Error (548, prop.Location, "`{0}': property or indexer must have at least one accessor", prop.GetSignatureForError ());
+ current_property = indexer;
- if (current_container.Kind == MemberKind.Interface) {
- if (prop.Get.Block != null)
- Report.Error (531, prop.Location, "`{0}.get': interface members cannot have a definition", prop.GetSignatureForError ());
+ current_container.AddIndexer (indexer);
+ lbag.AddMember (current_property, mod_locations, GetLocation ($5), GetLocation ($8), GetLocation ($9));
+
+ if (indexer.TypeExpression.Type == TypeManager.void_type)
+ Report.Error (620, GetLocation ($3), "`{0}': indexer return type cannot be `void'", indexer.GetSignatureForError ());
- if (prop.Set.Block != null)
- Report.Error (531, prop.Location, "`{0}.set': interface members cannot have a definition", prop.GetSignatureForError ());
+ if (indexer.Parameters.IsEmpty) {
+ Report.Error (1551, GetLocation ($5), "Indexers must have at least one parameter");
}
- current_container.AddProperty (prop);
- implicit_value_parameter_type = null;
+ if (RootContext.Documentation != null) {
+ tmpComment = Lexer.consume_doc_comment ();
+ Lexer.doc_state = XmlCommentState.Allowed;
+ }
+ lexer.PropertyParsing = true;
+ }
+ accessor_declarations
+ {
+ lexer.PropertyParsing = false;
+ }
+ CLOSE_BRACE
+ {
if (RootContext.Documentation != null)
- prop.DocComment = ConsumeStoredComment ();
-
+ current_property.DocComment = ConsumeStoredComment ();
+
+ lbag.AppendToMember (current_property, GetLocation ($12));
+ current_property = null;
}
;
+
accessor_declarations
: get_accessor_declaration
- {
- $$ = new Accessors ((Accessor) $1, null);
- }
| get_accessor_declaration accessor_declarations
- {
- Accessors accessors = (Accessors) $2;
- accessors.get_or_add = (Accessor) $1;
- $$ = accessors;
- }
| set_accessor_declaration
- {
- $$ = new Accessors (null, (Accessor) $1);
- }
| set_accessor_declaration accessor_declarations
- {
- Accessors accessors = (Accessors) $2;
- accessors.set_or_remove = (Accessor) $1;
- accessors.declared_in_reverse = true;
- $$ = accessors;
- }
| error
{
if (yyToken == Token.CLOSE_BRACE) {
- $$ = null;
+ Report.Error (548, lexer.Location, "`{0}': property or indexer must have at least one accessor", current_property.GetSignatureForError ());
} else {
if (yyToken == Token.SEMICOLON)
Report.Error (1597, lexer.Location, "Semicolon after method or accessor block is not valid");
else
Report.Error (1014, GetLocation ($1), "A get or set accessor expected");
-
- $$ = new Accessors (null, null);
}
}
;
get_accessor_declaration
: opt_attributes opt_modifiers GET
{
- // If this is not the case, then current_local_parameters has already
- // been set in indexer_declaration
- if (parsing_indexer == false)
- current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
- else
- current_local_parameters = indexer_parameters;
- lexer.PropertyParsing = false;
- }
- accessor_body
- {
- if (has_get) {
+ if ($2 != ModifierNone && RootContext.Version == LanguageVersion.ISO_1) {
+ Report.FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
+ }
+
+ if (current_property.Get != null) {
Report.Error (1007, GetLocation ($3), "Property accessor already defined");
- break;
}
- Accessor accessor = new Accessor ((ToplevelBlock) $5, (Modifiers) $2, (Attributes) $1, current_local_parameters, GetLocation ($3));
- has_get = true;
+
+ if (current_property is Indexer) {
+ current_property.Get = new Indexer.GetIndexerMethod (current_property, (Modifiers) $2, ((Indexer)current_property).ParameterInfo.Clone (),
+ (Attributes) $1, GetLocation ($3));
+ } else {
+ current_property.Get = new Property.GetMethod (current_property,
+ (Modifiers) $2, (Attributes) $1, GetLocation ($3));
+ }
+
+ current_local_parameters = current_property.Get.ParameterInfo;
+ lbag.AddMember (current_property.Get, mod_locations);
+ lexer.PropertyParsing = false;
+ }
+ accessor_body
+ {
+ if ($5 != null) {
+ current_property.Get.Block = (ToplevelBlock) $5;
+
+ if (current_container.Kind == MemberKind.Interface) {
+ Report.Error (531, current_property.Get.Block.StartLocation,
+ "`{0}': interface members cannot have a definition", current_property.Get.GetSignatureForError ());
+ }
+ }
+
current_local_parameters = null;
lexer.PropertyParsing = true;
if (RootContext.Documentation != null)
if (Lexer.doc_state == XmlCommentState.Error)
Lexer.doc_state = XmlCommentState.NotAllowed;
-
- $$ = accessor;
}
;
set_accessor_declaration
: opt_attributes opt_modifiers SET
{
- Parameter implicit_value_parameter = new Parameter (
- implicit_value_parameter_type, "value",
- Parameter.Modifier.NONE, null, GetLocation ($3));
-
- if (!parsing_indexer) {
- current_local_parameters = new ParametersCompiled (compiler, new Parameter [] { implicit_value_parameter });
+ if ($2 != ModifierNone && RootContext.Version == LanguageVersion.ISO_1) {
+ Report.FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
+ }
+
+ if (current_property.Set != null) {
+ Report.Error (1007, GetLocation ($3), "Property accessor already defined");
+ }
+
+ if (current_property is Indexer) {
+ current_property.Set = new Indexer.SetIndexerMethod (current_property, (Modifiers) $2,
+ ParametersCompiled.MergeGenerated (compiler,
+ ((Indexer)current_property).ParameterInfo, true, new Parameter (
+ current_property.TypeExpression, "value", Parameter.Modifier.NONE, null, GetLocation ($3)),
+ null),
+ (Attributes) $1, GetLocation ($3));
} else {
- current_local_parameters = ParametersCompiled.MergeGenerated (compiler,
- indexer_parameters, true, implicit_value_parameter, null);
+ current_property.Set = new Property.SetMethod (current_property, (Modifiers) $2,
+ ParametersCompiled.CreateImplicitParameter (current_property.TypeExpression, GetLocation ($3)),
+ (Attributes) $1, GetLocation ($3));
}
+ current_local_parameters = current_property.Set.ParameterInfo;
+ lbag.AddMember (current_property.Set, mod_locations);
lexer.PropertyParsing = false;
}
accessor_body
{
- if (has_set) {
- Report.Error (1007, GetLocation ($3), "Property accessor already defined");
- break;
+ if ($5 != null) {
+ current_property.Set.Block = (ToplevelBlock) $5;
+
+ if (current_container.Kind == MemberKind.Interface) {
+ Report.Error (531, current_property.Set.Block.StartLocation,
+ "`{0}': interface members cannot have a definition", current_property.Set.GetSignatureForError ());
+ }
}
- Accessor accessor = new Accessor ((ToplevelBlock) $5, (Modifiers) $2, (Attributes) $1, current_local_parameters, GetLocation ($3));
- has_set = true;
+
current_local_parameters = null;
lexer.PropertyParsing = true;
if (RootContext.Documentation != null
&& Lexer.doc_state == XmlCommentState.Error)
Lexer.doc_state = XmlCommentState.NotAllowed;
-
- $$ = accessor;
}
;
: block
| SEMICOLON
{
+ // TODO: lbag
$$ = null;
}
| error
{
MemberName name = MakeName ((MemberName) $6);
push_current_class (new Interface (current_namespace, current_class, name, (Modifiers) $2, (Attributes) $1), $3);
+ lbag.AddMember (current_class, mod_locations, GetLocation ($4));
}
opt_class_base
opt_type_parameter_constraints_clauses
Lexer.doc_state = XmlCommentState.Allowed;
}
}
- interface_body
+ OPEN_BRACE opt_interface_member_declarations CLOSE_BRACE
{
--lexer.parsing_declaration;
if (RootContext.Documentation != null)
}
opt_semicolon
{
+ lbag.AppendToMember (current_class, GetLocation ($11), GetLocation ($13));
$$ = pop_current_class ();
}
| opt_attributes opt_modifiers opt_partial INTERFACE error {
}
;
-interface_body
- : OPEN_BRACE
- opt_interface_member_declarations
- CLOSE_BRACE
- ;
-
opt_interface_member_declarations
: /* empty */
| interface_member_declarations
// Note again, checking is done in semantic analysis
current_container.AddOperator (op);
+ lbag.AddMember (op, mod_locations, lbag.GetLocations (decl));
current_local_parameters = null;
}
;
| VOID
{
Report.Error (590, GetLocation ($1), "User-defined operators cannot return void");
- $$ = TypeManager.system_void_expr;
+ $$ = new TypeExpression (TypeManager.void_type, GetLocation ($1));
}
;
}
$$ = new OperatorDeclaration (op, (FullNamedExpression) $1, loc);
+ lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3), GetLocation ($4), GetLocation ($7));
}
| conversion_operator_declarator
;
}
$$ = new OperatorDeclaration (Operator.OpType.Implicit, (FullNamedExpression) $3, loc);
+ lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
}
| EXPLICIT OPERATOR type OPEN_PARENS
{
}
$$ = new OperatorDeclaration (Operator.OpType.Explicit, (FullNamedExpression) $3, loc);
+ lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
}
| IMPLICIT error
{
}
}
+ lbag.AddMember (c, mod_locations, GetLocation ($5), GetLocation ($7));
$$ = c;
}
;
{
--lexer.parsing_block;
$$ = new ConstructorBaseInitializer ((Arguments) $5, GetLocation ($2));
+ lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
}
| COLON THIS OPEN_PARENS
{
{
--lexer.parsing_block;
$$ = new ConstructorThisInitializer ((Arguments) $5, GetLocation ($2));
+ lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
}
| COLON error {
Report.Error (1018, GetLocation ($1), "Keyword `this' or `base' expected");
Report.Error (574, lt.Location, "Name of destructor must match name of class");
} else if (current_container.Kind != MemberKind.Class){
Report.Error (575, lt.Location, "Only class types can contain destructor");
- } else {
- Destructor d = new Destructor (current_class, (Modifiers) $2,
- ParametersCompiled.EmptyReadOnlyParameters, (Attributes) $1, lt.Location);
- if (RootContext.Documentation != null)
- d.DocComment = ConsumeStoredComment ();
-
- d.Block = (ToplevelBlock) $8;
- current_container.AddMethod (d);
}
+
+ Destructor d = new Destructor (current_class, (Modifiers) $2,
+ ParametersCompiled.EmptyReadOnlyParameters, (Attributes) $1, lt.Location);
+ if (RootContext.Documentation != null)
+ d.DocComment = ConsumeStoredComment ();
+
+ d.Block = (ToplevelBlock) $8;
+ current_container.AddMethod (d);
+ lbag.AddMember (d, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($7));
current_local_parameters = null;
}
event_declaration
: opt_attributes
opt_modifiers
- EVENT type variable_declarators SEMICOLON
+ EVENT type member_declaration_name
{
- foreach (VariableMemberDeclaration var in (List<object>) $5) {
-
- EventField e = new EventField (
- current_class, (FullNamedExpression) $4, (Modifiers) $2, var.MemberName, (Attributes) $1);
-
- e.Initializer = var.GetInitializer ((FullNamedExpression) $4);
- if (current_container.Kind == MemberKind.Interface && e.Initializer != null) {
- Report.Error (68, e.Location, "`{0}': event in interface cannot have initializer", e.GetSignatureForError ());
- }
-
- if (var.MemberName.Left != null) {
- Report.Error (71, e.Location,
- "`{0}': An explicit interface implementation of an event must use property syntax",
- e.GetSignatureForError ());
- }
-
- current_container.AddEvent (e);
-
- if (RootContext.Documentation != null) {
- e.DocComment = Lexer.consume_doc_comment ();
- Lexer.doc_state = XmlCommentState.Allowed;
- }
+ current_event_field = new EventField (current_class, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
+ current_container.AddEvent (current_event_field);
+
+ if (current_event_field.MemberName.Left != null) {
+ Report.Error (71, current_event_field.Location, "`{0}': An explicit interface implementation of an event must use property syntax",
+ current_event_field.GetSignatureForError ());
}
+
+ $$ = current_event_field;
+ }
+ opt_event_initializer
+ opt_event_declarators
+ SEMICOLON
+ {
+ if (RootContext.Documentation != null) {
+ current_event_field.DocComment = Lexer.consume_doc_comment ();
+ Lexer.doc_state = XmlCommentState.Allowed;
+ }
+
+ lbag.AddMember (current_event_field, mod_locations, GetLocation ($3), GetLocation ($9));
+ current_event_field = null;
}
| opt_attributes
opt_modifiers
EVENT type member_declaration_name
OPEN_BRACE
{
- implicit_value_parameter_type = (FullNamedExpression) $4;
- current_local_parameters = new ParametersCompiled (compiler,
- new Parameter (implicit_value_parameter_type, "value",
- Parameter.Modifier.NONE, null, GetLocation ($3)));
-
+ current_event = new EventProperty (current_class, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
+ current_container.AddEvent (current_event);
+ lbag.AddMember (current_event, mod_locations, GetLocation ($3), GetLocation ($6));
+
lexer.EventParsing = true;
}
event_accessor_declarations
{
- lexer.EventParsing = false;
+ if (current_container.Kind == MemberKind.Interface)
+ Report.Error (69, GetLocation ($6), "Event in interface cannot have add or remove accessors");
+
+ lexer.EventParsing = false;
}
CLOSE_BRACE
{
- MemberName name = (MemberName) $5;
-
- if (current_container.Kind == MemberKind.Interface) {
- Report.Error (69, GetLocation ($3), "Event in interface cannot have add or remove accessors");
- $8 = new Accessors (null, null);
- } else if ($8 == null) {
- Report.Error (65, GetLocation ($3), "`{0}.{1}': event property must have both add and remove accessors",
- current_container.GetSignatureForError (), name.GetSignatureForError ());
- $8 = new Accessors (null, null);
+ if (RootContext.Documentation != null) {
+ current_event.DocComment = Lexer.consume_doc_comment ();
+ Lexer.doc_state = XmlCommentState.Allowed;
}
- Accessors accessors = (Accessors) $8;
-
- if (accessors.get_or_add == null || accessors.set_or_remove == null)
- // CS0073 is already reported, so no CS0065 here.
- $$ = null;
- else {
- Event e = new EventProperty (
- current_class, (FullNamedExpression) $4, (Modifiers) $2, name,
- (Attributes) $1, accessors.get_or_add, accessors.set_or_remove);
- if (RootContext.Documentation != null) {
- e.DocComment = Lexer.consume_doc_comment ();
- Lexer.doc_state = XmlCommentState.Allowed;
- }
-
- current_container.AddEvent (e);
- implicit_value_parameter_type = null;
- }
+ lbag.AppendToMember (current_event, GetLocation ($9));
+ current_event = null;
current_local_parameters = null;
}
- | opt_attributes opt_modifiers EVENT type member_declaration_name error
+ ;
+
+opt_event_initializer
+ : /* empty */
+ | ASSIGN
{
- MemberName mn = (MemberName) $5;
- if (mn.Left != null)
- Report.Error (71, mn.Location, "An explicit interface implementation of an event must use property syntax");
-
- if (RootContext.Documentation != null)
- Lexer.doc_state = XmlCommentState.Allowed;
-
- Error_SyntaxError (yyToken);
- $$ = null;
+ ++lexer.parsing_block;
+ }
+ event_variable_initializer
+ {
+ --lexer.parsing_block;
+ current_event_field.Initializer = (Expression) $3;
}
;
-
-event_accessor_declarations
- : add_accessor_declaration remove_accessor_declaration
+
+opt_event_declarators
+ : /* empty */
+ | event_declarators
+ ;
+
+event_declarators
+ : event_declarator
{
- $$ = new Accessors ((Accessor) $1, (Accessor) $2);
+ current_event_field.AddDeclarator ((FieldDeclarator) $1);
}
- | remove_accessor_declaration add_accessor_declaration
+ | event_declarators event_declarator
{
- Accessors accessors = new Accessors ((Accessor) $2, (Accessor) $1);
- accessors.declared_in_reverse = true;
- $$ = accessors;
- }
- | add_accessor_declaration { $$ = null; }
- | remove_accessor_declaration { $$ = null; }
- | error
- {
- Report.Error (1055, GetLocation ($1), "An add or remove accessor expected");
- $$ = null;
+ current_event_field.AddDeclarator ((FieldDeclarator) $2);
}
- | { $$ = null; }
;
-
-add_accessor_declaration
- : opt_attributes ADD
+
+event_declarator
+ : COMMA IDENTIFIER
{
- lexer.EventParsing = false;
+ var lt = (Tokenizer.LocatedToken) $2;
+ $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
+ lbag.AddLocation ($$, GetLocation ($1));
}
- block
+ | COMMA IDENTIFIER ASSIGN
{
- Accessor accessor = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, null, GetLocation ($2));
- lexer.EventParsing = true;
- $$ = accessor;
- }
- | opt_attributes ADD error {
- Report.Error (73, GetLocation ($2), "An add or remove accessor must have a body");
- $$ = null;
+ ++lexer.parsing_block;
}
- | opt_attributes modifiers ADD {
- Report.Error (1609, GetLocation ($3), "Modifiers cannot be placed on event accessor declarations");
- $$ = null;
+ event_variable_initializer
+ {
+ --lexer.parsing_block;
+ var lt = (Tokenizer.LocatedToken) $2;
+ $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
+ lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
}
;
-
-remove_accessor_declaration
- : opt_attributes REMOVE
- {
- lexer.EventParsing = false;
+
+event_variable_initializer
+ : {
+ if (current_container.Kind == MemberKind.Interface) {
+ Report.Error (68, lexer.Location, "`{0}': event in interface cannot have an initializer",
+ current_event_field.GetSignatureForError ());
+ }
+
+ if ((current_event_field.ModFlags & Modifiers.ABSTRACT) != 0) {
+ Report.Error (74, lexer.Location, "`{0}': abstract event cannot have an initializer",
+ current_event_field.GetSignatureForError ());
+ }
}
- block
+ variable_initializer
{
- $$ = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, null, GetLocation ($2));
- lexer.EventParsing = true;
- }
- | opt_attributes REMOVE error {
- Report.Error (73, GetLocation ($2), "An add or remove accessor must have a body");
- $$ = null;
+ $$ = $2;
}
- | opt_attributes modifiers REMOVE {
- Report.Error (1609, GetLocation ($3), "Modifiers cannot be placed on event accessor declarations");
+ ;
+
+event_accessor_declarations
+ : add_accessor_declaration remove_accessor_declaration
+ | remove_accessor_declaration add_accessor_declaration
+ | add_accessor_declaration
+ {
+ Report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
+ current_event.GetSignatureForError ());
+ }
+ | remove_accessor_declaration
+ {
+ Report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
+ current_event.GetSignatureForError ());
+ }
+ | error
+ {
+ Report.Error (1055, GetLocation ($1), "An add or remove accessor expected");
$$ = null;
}
;
-indexer_declaration
- : opt_attributes opt_modifiers
- member_type indexer_declaration_name OPEN_BRACKET
+add_accessor_declaration
+ : opt_attributes opt_modifiers ADD
{
- valid_param_mod = ParameterModifierType.Params | ParameterModifierType.DefaultValue;
+ if ($2 != ModifierNone) {
+ Report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
+ }
+
+ current_event.Add = new EventProperty.AddDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
+ current_local_parameters = current_event.Add.ParameterInfo;
+
+ lbag.AddMember (current_event.Add, mod_locations);
+ lexer.EventParsing = false;
}
- opt_formal_parameter_list CLOSE_BRACKET
- OPEN_BRACE
+ event_accessor_block
{
- valid_param_mod = 0;
- implicit_value_parameter_type = (FullNamedExpression) $3;
- indexer_parameters = (ParametersCompiled) $7;
+ lexer.EventParsing = true;
+
+ current_event.Add.Block = (ToplevelBlock) $5;
- if (indexer_parameters.IsEmpty) {
- Report.Error (1551, GetLocation ($5), "Indexers must have at least one parameter");
- }
-
- if (RootContext.Documentation != null) {
- tmpComment = Lexer.consume_doc_comment ();
- Lexer.doc_state = XmlCommentState.Allowed;
+ if (current_container.Kind == MemberKind.Interface) {
+ Report.Error (531, current_event.Add.Block.StartLocation,
+ "`{0}': interface members cannot have a definition", current_event.Add.GetSignatureForError ());
}
-
- lexer.PropertyParsing = true;
- parsing_indexer = true;
+ current_local_parameters = null;
}
- accessor_declarations
+ ;
+
+remove_accessor_declaration
+ : opt_attributes opt_modifiers REMOVE
{
- lexer.PropertyParsing = false;
- has_get = has_set = false;
- parsing_indexer = false;
- }
- CLOSE_BRACE
- {
- Accessors accessors = (Accessors) $11;
- Accessor get_block = accessors != null ? accessors.get_or_add : null;
- Accessor set_block = accessors != null ? accessors.set_or_remove : null;
- bool order = accessors != null ? accessors.declared_in_reverse : false;
-
- Indexer indexer = new Indexer (current_class, (FullNamedExpression) $3,
- (MemberName)$4, (Modifiers) $2, (ParametersCompiled) $7, (Attributes) $1,
- get_block, set_block, order);
-
- if ($3 == TypeManager.system_void_expr)
- Report.Error (620, GetLocation ($3), "`{0}': indexer return type cannot be `void'", indexer.GetSignatureForError ());
-
- if (accessors == null)
- Report.Error (548, indexer.Location, "`{0}': property or indexer must have at least one accessor", indexer.GetSignatureForError ());
+ if ($2 != ModifierNone) {
+ Report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
+ }
+
+ current_event.Remove = new EventProperty.RemoveDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
+ current_local_parameters = current_event.Remove.ParameterInfo;
+ lbag.AddMember (current_event.Remove, mod_locations);
+ lexer.EventParsing = false;
+ }
+ event_accessor_block
+ {
+ lexer.EventParsing = true;
+
+ current_event.Remove.Block = (ToplevelBlock) $5;
+
if (current_container.Kind == MemberKind.Interface) {
- if (indexer.Get.Block != null)
- Report.Error (531, indexer.Location, "`{0}.get': interface members cannot have a definition", indexer.GetSignatureForError ());
-
- if (indexer.Set.Block != null)
- Report.Error (531, indexer.Location, "`{0}.set': interface members cannot have a definition", indexer.GetSignatureForError ());
+ Report.Error (531, current_event.Remove.Block.StartLocation,
+ "`{0}': interface members cannot have a definition", current_event.Remove.GetSignatureForError ());
}
-
- if (RootContext.Documentation != null)
- indexer.DocComment = ConsumeStoredComment ();
-
- current_container.AddIndexer (indexer);
current_local_parameters = null;
- implicit_value_parameter_type = null;
- indexer_parameters = null;
}
;
+event_accessor_block
+ : opt_semicolon
+ {
+ Report.Error (73, lexer.Location, "An add or remove accessor must have a body");
+ $$ = null;
+ }
+ | block;
+ ;
+
enum_declaration
: opt_attributes
opt_modifiers
ENUM type_declaration_name
- opt_enum_base {
+ opt_enum_base
+ {
if (RootContext.Documentation != null)
enumTypeComment = Lexer.consume_doc_comment ();
}
- enum_body
- opt_semicolon
+ OPEN_BRACE
{
+ if (RootContext.Documentation != null)
+ Lexer.doc_state = XmlCommentState.Allowed;
+
MemberName name = (MemberName) $4;
if (name.IsGeneric) {
Report.Error (1675, name.Location, "Enums cannot have type parameters");
}
-
- name = MakeName (name);
- Enum e = new Enum (current_namespace, current_class, (TypeExpr) $5, (Modifiers) $2,
- name, (Attributes) $1);
+ push_current_class (new Enum (current_namespace, current_class, (TypeExpression) $5, (Modifiers) $2, MakeName (name), (Attributes) $1), null);
+ }
+ opt_enum_member_declarations
+ {
+ // here will be evaluated after CLOSE_BLACE is consumed.
if (RootContext.Documentation != null)
- e.DocComment = enumTypeComment;
-
-
- EnumMember em = null;
- foreach (VariableDeclaration ev in (IList<VariableDeclaration>) $7) {
- em = new EnumMember (
- e, em, ev.identifier, ev.GetInitializer ((FullNamedExpression) $5),
- ev.OptAttributes, ev.Location);
+ Lexer.doc_state = XmlCommentState.Allowed;
+ }
+ CLOSE_BRACE opt_semicolon
+ {
+ if (RootContext.Documentation != null)
+ current_class.DocComment = enumTypeComment;
+
+ --lexer.parsing_declaration;
// if (RootContext.Documentation != null)
- em.DocComment = ev.DocComment;
-
- e.AddEnumMember (em);
- }
- if (RootContext.EvalMode)
- undo.AddTypeContainer (current_container, e);
-
- current_container.AddTypeContainer (e);
-
- $$ = e;
+// em.DocComment = ev.DocComment;
+ lbag.AddMember (current_class, mod_locations, GetLocation ($3), GetLocation ($7), GetLocation ($11));
+ $$ = pop_current_class ();
}
;
opt_enum_base
: /* empty */
- {
- $$ = TypeManager.system_int32_expr;
- }
| COLON type
{
- if ($2 != TypeManager.system_int32_expr && $2 != TypeManager.system_uint32_expr &&
- $2 != TypeManager.system_int64_expr && $2 != TypeManager.system_uint64_expr &&
- $2 != TypeManager.system_int16_expr && $2 != TypeManager.system_uint16_expr &&
- $2 != TypeManager.system_byte_expr && $2 != TypeManager.system_sbyte_expr) {
+ var te = $2 as TypeExpression;
+ if (te == null ||
+ (te.Type != TypeManager.int32_type && te.Type != TypeManager.uint32_type &&
+ te.Type != TypeManager.int64_type && te.Type != TypeManager.uint64_type &&
+ te.Type != TypeManager.short_type && te.Type != TypeManager.ushort_type &&
+ te.Type != TypeManager.byte_type && te.Type != TypeManager.sbyte_type)) {
Enum.Error_1008 (GetLocation ($2), Report);
- $2 = TypeManager.system_int32_expr;
+ $$ = null;
+ } else {
+ $$ = $2;
}
-
- $$ = $2;
}
| COLON error
{
- Error_TypeExpected (lexer.Location);
- $$ = TypeManager.system_int32_expr;
+ Error_TypeExpected (GetLocation ($1));
+ $$ = null;
}
;
-enum_body
- : OPEN_BRACE
- {
- if (RootContext.Documentation != null)
- Lexer.doc_state = XmlCommentState.Allowed;
- }
- opt_enum_member_declarations
- {
- // here will be evaluated after CLOSE_BLACE is consumed.
- if (RootContext.Documentation != null)
- Lexer.doc_state = XmlCommentState.Allowed;
- }
- CLOSE_BRACE
+opt_enum_member_declarations
+ : /* empty */
+ | enum_member_declarations
+ | enum_member_declarations COMMA
{
- $$ = $3;
+ lbag.AddLocation ($1, GetLocation ($2));
}
;
-opt_enum_member_declarations
- : /* empty */ { $$ = new VariableDeclaration [0]; }
- | enum_member_declarations opt_comma { $$ = $1; }
- ;
-
enum_member_declarations
- : enum_member_declaration
- {
- var l = new List<VariableDeclaration> (4);
- l.Add ((VariableDeclaration) $1);
- $$ = l;
- }
+ : enum_member_declaration
| enum_member_declarations COMMA enum_member_declaration
{
- var l = (List<VariableDeclaration>) $1;
- l.Add ((VariableDeclaration) $3);
- $$ = l;
+ lbag.AddLocation ($1, GetLocation ($2));
+ $$ = $3;
}
;
enum_member_declaration
- : opt_attributes IDENTIFIER
+ : opt_attributes IDENTIFIER
{
- VariableDeclaration vd = new VariableDeclaration (
- (Tokenizer.LocatedToken) $2, null, (Attributes) $1);
+ var lt = (Tokenizer.LocatedToken) $2;
+ var em = new EnumMember ((Enum) current_class, new MemberName (lt.Value, lt.Location), (Attributes) $1);
+ ((Enum) current_class).AddEnumMember (em);
if (RootContext.Documentation != null) {
- vd.DocComment = Lexer.consume_doc_comment ();
+ em.DocComment = Lexer.consume_doc_comment ();
Lexer.doc_state = XmlCommentState.Allowed;
}
- $$ = vd;
+ $$ = em;
}
| opt_attributes IDENTIFIER
{
}
ASSIGN constant_expression
{
- --lexer.parsing_block;
- VariableDeclaration vd = new VariableDeclaration (
- (Tokenizer.LocatedToken) $2, (Expression) $5, (Attributes) $1);
-
+ --lexer.parsing_block;
+
+ var lt = (Tokenizer.LocatedToken) $2;
+ var em = new EnumMember ((Enum) current_class, new MemberName (lt.Value, lt.Location), (Attributes) $1);
+ em.Initializer = new ConstInitializer (em, (Expression) $5, GetLocation ($4));
+ ((Enum) current_class).AddEnumMember (em);
+
if (RootContext.Documentation != null)
- vd.DocComment = ConsumeStoredComment ();
+ em.DocComment = ConsumeStoredComment ();
- $$ = vd;
+ $$ = em;
}
;
SEMICOLON
{
current_delegate.SetParameterInfo ((List<Constraints>) $11);
+ lbag.AddMember (current_delegate, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($13));
+
$$ = current_delegate;
current_delegate = null;
else if (RootContext.Version < LanguageVersion.ISO_2)
Report.FeatureIsNotAvailable (GetLocation ($1), "nullable types");
- $$ = this;
+ $$ = ComposedTypeSpecifier.CreateNullable (GetLocation ($1));
}
;
{
var lt = (Tokenizer.LocatedToken) $3;
$$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $4, lt.Location);
+ lbag.AddLocation ($$, GetLocation ($2));
}
;
{
var lt = (Tokenizer.LocatedToken) $1;
$$ = new MemberName (lt.Value, (TypeArguments) $2, lt.Location);
+ lbag.AddLocation ($$, GetLocation ($3));
}
| qualified_alias_member IDENTIFIER opt_type_argument_list DOT
{
var lt2 = (Tokenizer.LocatedToken) $2;
$$ = new MemberName (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
+ lbag.AddLocation ($$, GetLocation ($4));
}
| explicit_interface IDENTIFIER opt_type_argument_list DOT
{
var lt = (Tokenizer.LocatedToken) $2;
$$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $3, lt.Location);
+ lbag.AddLocation ($$, GetLocation ($4));
}
;
Report.FeatureIsNotAvailable (GetLocation ($1), "generics");
$$ = $2;
+ lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
}
;
TypeArguments type_args = (TypeArguments) $1;
type_args.Add ((FullNamedExpression)$3);
$$ = type_args;
+ lbag.AddLocation ($3, GetLocation ($3));
}
;
: type_expression_or_array
| VOID
{
- $$ = TypeManager.system_void_expr;
+ $$ = new TypeExpression (TypeManager.void_type, GetLocation ($1));
}
;
lexer.parsing_generic_declaration = true;
}
;
-
+
//
// A type which does not allow `void' to be used
//
| VOID
{
Expression.Error_VoidInvalidInTheContext (GetLocation ($1), Report);
- $$ = TypeManager.system_void_expr;
+ $$ = new TypeExpression (TypeManager.void_type, GetLocation ($1));
}
;
| VOID
{
Expression.Error_VoidInvalidInTheContext (GetLocation ($1), Report);
- $$ = TypeManager.system_void_expr;
+ $$ = new TypeExpression (TypeManager.void_type, GetLocation ($1));
}
;
| VOID
{
Report.Error (1536, GetLocation ($1), "Invalid parameter type `void'");
- $$ = TypeManager.system_void_expr;
+ $$ = new TypeExpression (TypeManager.void_type, GetLocation ($1));
}
;
: type_expression
| type_expression rank_specifiers
{
- string rank_specifiers = (string) $2;
- $$ = new ComposedCast ((FullNamedExpression) $1, rank_specifiers);
+ $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
}
;
MemberName name = (MemberName) $1;
if ($2 != null) {
- $$ = new ComposedCast (name.GetTypeExpression (), "?", lexer.Location);
+ $$ = new ComposedCast (name.GetTypeExpression (), (ComposedTypeSpecifier) $2);
} else {
if (name.Left == null && name.Name == "var")
$$ = new VarExpr (name.Location);
| builtin_types opt_nullable
{
if ($2 != null)
- $$ = new ComposedCast ((FullNamedExpression) $1, "?", lexer.Location);
+ $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
}
| type_expression STAR
{
// can't perform checks during this phase - we do it during
// semantic analysis.
//
- $$ = new ComposedCast ((FullNamedExpression) $1, "*", Lexer.Location);
+ $$ = new ComposedCast ((FullNamedExpression) $1, ComposedTypeSpecifier.CreatePointer (GetLocation ($2)));
}
| VOID STAR
{
- $$ = new ComposedCast (TypeManager.system_void_expr, "*", GetLocation ($1));
+ $$ = new ComposedCast (new TypeExpression (TypeManager.void_type, GetLocation ($1)), ComposedTypeSpecifier.CreatePointer (GetLocation ($2)));
}
;
base_type_name
: type
{
- if ($1 is ComposedCast)
+ if ($1 is ComposedCast) {
Report.Error (1521, GetLocation ($1), "Invalid base type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
+ }
$$ = $1;
}
| error
* simple types, but we need this to reuse it easily in variable_type
*/
builtin_types
- : OBJECT { $$ = TypeManager.system_object_expr; }
- | STRING { $$ = TypeManager.system_string_expr; }
- | BOOL { $$ = TypeManager.system_boolean_expr; }
- | DECIMAL { $$ = TypeManager.system_decimal_expr; }
- | FLOAT { $$ = TypeManager.system_single_expr; }
- | DOUBLE { $$ = TypeManager.system_double_expr; }
+ : OBJECT { $$ = new TypeExpression (TypeManager.object_type, GetLocation ($1)); }
+ | STRING { $$ = new TypeExpression (TypeManager.string_type, GetLocation ($1)); }
+ | BOOL { $$ = new TypeExpression (TypeManager.bool_type, GetLocation ($1)); }
+ | DECIMAL { $$ = new TypeExpression (TypeManager.decimal_type, GetLocation ($1)); }
+ | FLOAT { $$ = new TypeExpression (TypeManager.float_type, GetLocation ($1)); }
+ | DOUBLE { $$ = new TypeExpression (TypeManager.double_type, GetLocation ($1)); }
| integral_type
;
integral_type
- : SBYTE { $$ = TypeManager.system_sbyte_expr; }
- | BYTE { $$ = TypeManager.system_byte_expr; }
- | SHORT { $$ = TypeManager.system_int16_expr; }
- | USHORT { $$ = TypeManager.system_uint16_expr; }
- | INT { $$ = TypeManager.system_int32_expr; }
- | UINT { $$ = TypeManager.system_uint32_expr; }
- | LONG { $$ = TypeManager.system_int64_expr; }
- | ULONG { $$ = TypeManager.system_uint64_expr; }
- | CHAR { $$ = TypeManager.system_char_expr; }
- ;
-
-predefined_type
- : builtin_types
- | VOID
- {
- $$ = TypeManager.system_void_expr;
- }
+ : SBYTE { $$ = new TypeExpression (TypeManager.sbyte_type, GetLocation ($1)); }
+ | BYTE { $$ = new TypeExpression (TypeManager.byte_type, GetLocation ($1)); }
+ | SHORT { $$ = new TypeExpression (TypeManager.short_type, GetLocation ($1)); }
+ | USHORT { $$ = new TypeExpression (TypeManager.ushort_type, GetLocation ($1)); }
+ | INT { $$ = new TypeExpression (TypeManager.int32_type, GetLocation ($1)); }
+ | UINT { $$ = new TypeExpression (TypeManager.uint32_type, GetLocation ($1)); }
+ | LONG { $$ = new TypeExpression (TypeManager.int64_type, GetLocation ($1)); }
+ | ULONG { $$ = new TypeExpression (TypeManager.uint64_type, GetLocation ($1)); }
+ | CHAR { $$ = new TypeExpression (TypeManager.char_type, GetLocation ($1)); }
;
//
| IDENTIFIER opt_type_argument_list
{
var lt = (Tokenizer.LocatedToken) $1;
- $$ = new SimpleName (MemberName.MakeName (lt.Value, (TypeArguments)$2), (TypeArguments)$2, lt.Location);
+ $$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location);
}
| IDENTIFIER GENERATE_COMPLETION {
var lt = (Tokenizer.LocatedToken) $1;
open_parens_any
: OPEN_PARENS
| OPEN_PARENS_CAST
- | OPEN_PARENS_LAMBDA
;
//
: OPEN_PARENS expression CLOSE_PARENS
{
$$ = new ParenthesizedExpression ((Expression) $2);
+ lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
}
| OPEN_PARENS expression COMPLETE_COMPLETION
{
{
var lt = (Tokenizer.LocatedToken) $3;
$$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
+ lbag.AddLocation ($$, GetLocation ($2));
}
- | predefined_type DOT IDENTIFIER opt_type_argument_list
+ | builtin_types DOT IDENTIFIER opt_type_argument_list
{
var lt = (Tokenizer.LocatedToken) $3;
- // TODO: Location is wrong as some predefined types doesn't hold a location
$$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
+ lbag.AddLocation ($$, GetLocation ($2));
+ }
+ | BASE DOT IDENTIFIER opt_type_argument_list
+ {
+ var lt = (Tokenizer.LocatedToken) $3;
+ $$ = new MemberAccess (new BaseThis (GetLocation ($1)), lt.Value, (TypeArguments) $4, lt.Location);
+ lbag.AddLocation ($$, GetLocation ($2));
}
| qualified_alias_member IDENTIFIER opt_type_argument_list
{
var lt = (Tokenizer.LocatedToken) $3;
$$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
}
- | predefined_type DOT GENERATE_COMPLETION
+ | builtin_types DOT GENERATE_COMPLETION
{
- // TODO: Location is wrong as some predefined types doesn't hold a location
$$ = new CompletionMemberAccess ((Expression) $1, null, lexer.Location);
}
- | predefined_type DOT IDENTIFIER GENERATE_COMPLETION {
+ | builtin_types DOT IDENTIFIER GENERATE_COMPLETION {
var lt = (Tokenizer.LocatedToken) $3;
$$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
}
: primary_expression open_parens_any opt_argument_list close_parens
{
$$ = new Invocation ((Expression) $1, (Arguments) $3);
+ lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
}
;
object_or_collection_initializer
: OPEN_BRACE opt_member_initializer_list close_brace_or_complete_completion
{
- if ($2 == null)
+ if ($2 == null) {
$$ = CollectionOrObjectInitializers.Empty;
- else
+ // TODO: lbag
+ } else {
$$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
+ lbag.AddLocation ($$, GetLocation ($3));
+ }
}
| OPEN_BRACE member_initializer_list COMMA CLOSE_BRACE
{
$$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
+ lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
}
;
a.Add ((Expression) $3);
$$ = a;
}
+ | member_initializer_list error {
+ Error_SyntaxError (yyToken);
+ $$ = $1;
+ }
;
member_initializer
{
var lt = (Tokenizer.LocatedToken) $1;
$$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
+ lbag.AddLocation ($$, GetLocation ($2));
}
| GENERATE_COMPLETION
{
}
| OPEN_BRACE expression_list CLOSE_BRACE
{
- $$ = new CollectionElementInitializer ((List<Expression>)$2, GetLocation ($1));
+ if ($2 == null)
+ $$ = null;
+ else
+ $$ = new CollectionElementInitializer ((List<Expression>)$2, GetLocation ($1));
}
| OPEN_BRACE CLOSE_BRACE
{
| argument_list COMMA
{
Report.Error (839, GetLocation ($2), "An argument is missing");
- $$ = null;
+ $$ = $1;
}
- | COMMA argument_or_named_argument
+ | COMMA error
{
Report.Error (839, GetLocation ($1), "An argument is missing");
$$ = null;
: REF variable_reference
{
$$ = new Argument ((Expression) $2, Argument.AType.Ref);
+ lbag.AddLocation ($$, GetLocation ($1));
}
| OUT variable_reference
{
$$ = new Argument ((Expression) $2, Argument.AType.Out);
+ lbag.AddLocation ($$, GetLocation ($1));
}
- | ARGLIST open_parens_any argument_list CLOSE_PARENS
+ | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
{
$$ = new Argument (new Arglist ((Arguments) $3, GetLocation ($1)));
+ lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
}
- | ARGLIST open_parens_any CLOSE_PARENS
+ | ARGLIST OPEN_PARENS CLOSE_PARENS
{
$$ = new Argument (new Arglist (GetLocation ($1)));
+ lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
}
| ARGLIST
{
;
element_access
- : primary_expression_no_array_creation OPEN_BRACKET expression_list_arguments CLOSE_BRACKET
+ : primary_expression OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
{
- $$ = new ElementAccess ((Expression) $1, (Arguments) $3);
- }
- | array_creation_expression OPEN_BRACKET expression_list_arguments CLOSE_BRACKET
- {
- // LAMESPEC: Not allowed according to specification
- $$ = new ElementAccess ((Expression) $1, (Arguments) $3);
- }
- | primary_expression_no_array_creation rank_specifiers
- {
- // So the super-trick is that primary_expression
- // can only be either a SimpleName or a MemberAccess.
- // The MemberAccess case arises when you have a fully qualified type-name like :
- // Foo.Bar.Blah i;
- // SimpleName is when you have
- // Blah i;
-
- Expression expr = (Expression) $1;
- if (expr is ComposedCast){
- $$ = new ComposedCast ((ComposedCast)expr, (string) $2);
- } else if (expr is ATypeNameExpression){
- //
- // So we extract the string corresponding to the SimpleName
- // or MemberAccess
- //
- $$ = new ComposedCast ((ATypeNameExpression)expr, (string) $2);
- } else {
- Error_ExpectingTypeName (expr);
- $$ = TypeManager.system_object_expr;
- }
+ $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
+ lbag.AddLocation ($$, GetLocation ($4));
}
;
list.Add ((Expression) $3);
$$ = list;
}
+ | expression_list error {
+ Error_SyntaxError (yyToken);
+ $$ = $1;
+ }
;
expression_list_arguments
this_access
: THIS
{
- $$ = new This (current_block, GetLocation ($1));
+ $$ = new This (GetLocation ($1));
}
;
base_access
- : BASE DOT IDENTIFIER opt_type_argument_list
- {
- var lt = (Tokenizer.LocatedToken) $3;
- $$ = new BaseAccess (lt.Value, (TypeArguments) $4, lt.Location);
- }
- | BASE OPEN_BRACKET expression_list_arguments CLOSE_BRACKET
+ : BASE OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
{
- $$ = new BaseIndexerAccess ((Arguments) $3, GetLocation ($1));
+ $$ = new ElementAccess (new BaseThis (GetLocation ($1)), (Arguments) $3, GetLocation ($2));
+ lbag.AddLocation ($$, GetLocation ($4));
}
- | BASE error
+ | BASE OPEN_BRACKET error
{
Error_SyntaxError (yyToken);
- $$ = new BaseAccess (null, GetLocation ($2));
+ $$ = new ElementAccess (null, null, GetLocation ($2));
}
;
post_increment_expression
: primary_expression OP_INC
{
- $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement, (Expression) $1);
+ $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement, (Expression) $1, GetLocation ($2));
}
;
post_decrement_expression
: primary_expression OP_DEC
{
- $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement, (Expression) $1);
+ $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement, (Expression) $1, GetLocation ($2));
}
;
-
+
object_or_delegate_creation_expression
- : new_expr_start open_parens_any opt_argument_list CLOSE_PARENS opt_object_or_collection_initializer
+ : NEW new_expr_type open_parens_any opt_argument_list CLOSE_PARENS opt_object_or_collection_initializer
{
- if ($5 != null) {
+ if ($6 != null) {
if (RootContext.Version <= LanguageVersion.ISO_2)
Report.FeatureIsNotAvailable (GetLocation ($1), "object initializers");
- $$ = new NewInitialize ((Expression) $1, (Arguments) $3, (CollectionOrObjectInitializers) $5, GetLocation ($1));
+ $$ = new NewInitialize ((FullNamedExpression) $2, (Arguments) $4, (CollectionOrObjectInitializers) $6, GetLocation ($1));
+ } else {
+ $$ = new New ((FullNamedExpression) $2, (Arguments) $4, GetLocation ($1));
}
- else
- $$ = new New ((Expression) $1, (Arguments) $3, GetLocation ($1));
+
+ lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
}
- | new_expr_start object_or_collection_initializer
+ | NEW new_expr_type object_or_collection_initializer
{
if (RootContext.Version <= LanguageVersion.ISO_2)
Report.FeatureIsNotAvailable (GetLocation ($1), "collection initializers");
- $$ = new NewInitialize ((Expression) $1, null, (CollectionOrObjectInitializers) $2, GetLocation ($1));
+ $$ = new NewInitialize ((FullNamedExpression) $2, null, (CollectionOrObjectInitializers) $3, GetLocation ($1));
}
;
array_creation_expression
- : new_expr_start OPEN_BRACKET expression_list CLOSE_BRACKET
- opt_rank_specifier // shift/reduce on OPEN_BRACE
+ : NEW new_expr_type OPEN_BRACKET_EXPR expression_list CLOSE_BRACKET
+ opt_rank_specifier
opt_array_initializer
{
- $$ = new ArrayCreation ((FullNamedExpression) $1, (List<Expression>) $3, (string) $5, (ArrayInitializer) $6, GetLocation ($1));
+ $$ = new ArrayCreation ((FullNamedExpression) $2, (List<Expression>) $4,
+ new ComposedTypeSpecifier (((List<Expression>) $4).Count, GetLocation ($3)) {
+ Next = (ComposedTypeSpecifier) $6
+ }, (ArrayInitializer) $7, GetLocation ($1));
+ lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
}
- | new_expr_start rank_specifiers opt_array_initializer
+ | NEW new_expr_type rank_specifiers opt_array_initializer
{
- if ($3 == null)
+ if ($4 == null)
Report.Error (1586, GetLocation ($1), "Array creation must have array size or array initializer");
- $$ = new ArrayCreation ((FullNamedExpression) $1, (string) $2, (ArrayInitializer) $3, GetLocation ($1));
+ $$ = new ArrayCreation ((FullNamedExpression) $2, (ComposedTypeSpecifier) $3, (ArrayInitializer) $4, GetLocation ($1));
}
| NEW rank_specifiers array_initializer
{
if (RootContext.Version <= LanguageVersion.ISO_2)
Report.FeatureIsNotAvailable (GetLocation ($1), "implicitly typed arrays");
- $$ = new ImplicitlyTypedArrayCreation ((string) $2, (ArrayInitializer) $3, GetLocation ($1));
+ $$ = new ImplicitlyTypedArrayCreation ((ComposedTypeSpecifier) $2, (ArrayInitializer) $3, GetLocation ($1));
+ }
+ | NEW new_expr_type OPEN_BRACKET CLOSE_BRACKET OPEN_BRACKET_EXPR error CLOSE_BRACKET
+ {
+ Report.Error (178, GetLocation ($6), "Invalid rank specifier, expecting `,' or `]'");
+ $$ = new ArrayCreation ((FullNamedExpression) $2, null, GetLocation ($1));
}
- | new_expr_start error
+ | NEW new_expr_type error
{
- Report.Error (1526, GetLocation ($1), "A new expression requires () or [] after type");
- $$ = new ArrayCreation ((FullNamedExpression) $1, "[]", null, GetLocation ($1));
+ Error_SyntaxError (1526, yyToken, "Unexpected symbol");
+ $$ = new ArrayCreation ((FullNamedExpression) $2, null, GetLocation ($1));
}
;
-new_expr_start
- : NEW
- {
+new_expr_type
+ : {
++lexer.parsing_type;
}
simple_type
{
--lexer.parsing_type;
- $$ = $3;
+ $$ = $2;
}
;
Report.FeatureIsNotAvailable (GetLocation ($1), "anonymous types");
$$ = new NewAnonymousType ((List<AnonymousTypeParameter>) $3, current_container, GetLocation ($1));
+
+ // TODO: lbag comma location
+ lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
}
;
{
var lt = (Tokenizer.LocatedToken)$1;
$$ = new AnonymousTypeParameter ((Expression)$3, lt.Value, lt.Location);
+ lbag.AddLocation ($$, GetLocation ($2));
}
| IDENTIFIER
{
$$ = new AnonymousTypeParameter (new SimpleName (lt.Value, lt.Location),
lt.Value, lt.Location);
}
- | BASE DOT IDENTIFIER opt_type_argument_list
- {
- var lt = (Tokenizer.LocatedToken) $3;
- BaseAccess ba = new BaseAccess (lt.Value, (TypeArguments) $4, lt.Location);
- $$ = new AnonymousTypeParameter (ba, lt.Value, lt.Location);
- }
| member_access
{
MemberAccess ma = (MemberAccess) $1;
opt_rank_specifier
: /* empty */
{
- $$ = "";
+ $$ = null;
}
| rank_specifiers
- {
- $$ = $1;
- }
;
opt_rank_specifier_or_nullable
: opt_nullable
- {
- if ($1 != null)
- $$ = "?";
- else
- $$ = string.Empty;
- }
| opt_nullable rank_specifiers
{
- if ($1 != null)
- $$ = "?" + (string) $2;
- else
+ if ($1 != null) {
+ ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
+ $$ = $1;
+ } else {
$$ = $2;
+ }
}
;
: rank_specifier
| rank_specifier rank_specifiers
{
- $$ = (string) $2 + (string) $1;
+ ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
+ $$ = $1;
}
;
rank_specifier
: OPEN_BRACKET CLOSE_BRACKET
{
- $$ = "[]";
+ $$ = ComposedTypeSpecifier.CreateArrayDimension (1, GetLocation ($1));
}
| OPEN_BRACKET dim_separators CLOSE_BRACKET
{
- $$ = "[" + (string) $2 + "]";
- }
- | OPEN_BRACKET error
- {
- Error_SyntaxError (178, yyToken, "Invalid rank specifier");
- $$ = "[]";
+ $$ = ComposedTypeSpecifier.CreateArrayDimension ((int)$2, GetLocation ($1));
}
;
dim_separators
: COMMA
{
- $$ = ",";
+ $$ = 2;
}
| dim_separators COMMA
{
- $$ = (string) $1 + ",";
+ $$ = ((int) $1) + 1;
}
;
: OPEN_BRACE CLOSE_BRACE
{
$$ = new ArrayInitializer (0, GetLocation ($1));
+ lbag.AddLocation ($$, GetLocation ($2));
}
| OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
{
$$ = new ArrayInitializer ((List<Expression>) $2, GetLocation ($1));
+ lbag.AddLocation ($$, GetLocation ($3));
}
;
open_parens_any typeof_type_expression CLOSE_PARENS
{
lexer.TypeOfParsing = false;
- Expression type = (Expression)$4;
- if (type == TypeManager.system_void_expr)
- $$ = new TypeOfVoid (GetLocation ($1));
- else
- $$ = new TypeOf (type, GetLocation ($1));
+ $$ = new TypeOf ((FullNamedExpression) $4, GetLocation ($1));
+ lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
}
;
{
var lt = (Tokenizer.LocatedToken) $1;
- $$ = new SimpleName (MemberName.MakeName (lt.Value, (int)$2), lt.Location);
+ $$ = new SimpleName (lt.Value, (int) $2, lt.Location);
}
| qualified_alias_member IDENTIFIER generic_dimension
{
var lt1 = (Tokenizer.LocatedToken) $1;
var lt2 = (Tokenizer.LocatedToken) $2;
- $$ = new QualifiedAliasMember (lt1.Value, MemberName.MakeName (lt2.Value, (int) $3), lt1.Location);
+ $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location);
}
| unbound_type_name DOT IDENTIFIER
{
{
var lt = (Tokenizer.LocatedToken) $3;
- $$ = new MemberAccess ((Expression) $1, MemberName.MakeName (lt.Value, (int) $4), lt.Location);
+ $$ = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location);
}
| namespace_or_type_name DOT IDENTIFIER generic_dimension
{
var lt = (Tokenizer.LocatedToken) $3;
MemberName name = (MemberName) $1;
- $$ = new MemberAccess (name.GetTypeExpression (), MemberName.MakeName (lt.Value, (int) $4), lt.Location);
+ $$ = new MemberAccess (name.GetTypeExpression (), lt.Value, (int) $4, lt.Location);
}
;
;
sizeof_expression
- : SIZEOF open_parens_any type CLOSE_PARENS {
+ : SIZEOF open_parens_any type CLOSE_PARENS
+ {
$$ = new SizeOf ((Expression) $3, GetLocation ($1));
+ lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
}
;
: CHECKED open_parens_any expression CLOSE_PARENS
{
$$ = new CheckedExpr ((Expression) $3, GetLocation ($1));
+ lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
}
;
: UNCHECKED open_parens_any expression CLOSE_PARENS
{
$$ = new UnCheckedExpr ((Expression) $3, GetLocation ($1));
+ lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
}
;
pointer_member_access
: primary_expression OP_PTR IDENTIFIER
{
- Expression deref;
var lt = (Tokenizer.LocatedToken) $3;
-
- deref = new Indirection ((Expression) $1, lt.Location);
- $$ = new MemberAccess (deref, lt.Value);
+ $$ = new MemberAccess (new Indirection ((Expression) $1, GetLocation ($2)), lt.Value, lt.Location);
}
;
Report.FeatureIsNotAvailable (GetLocation ($1), "default value expression");
$$ = new DefaultValueExpression ((Expression) $3, GetLocation ($1));
+ lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
}
;
: primary_expression
| BANG prefixed_unary_expression
{
- $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2);
+ $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, GetLocation ($1));
}
| TILDE prefixed_unary_expression
{
- $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2);
+ $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, GetLocation ($1));
}
| cast_expression
;
: OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
{
$$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
+ lbag.AddLocation ($$, GetLocation ($3));
}
- | OPEN_PARENS predefined_type CLOSE_PARENS prefixed_unary_expression
+ | OPEN_PARENS builtin_types CLOSE_PARENS prefixed_unary_expression
{
$$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
+ lbag.AddLocation ($$, GetLocation ($3));
}
;
: unary_expression
| PLUS prefixed_unary_expression
{
- $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2);
+ $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, GetLocation ($1));
}
| MINUS prefixed_unary_expression
{
- $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2);
+ $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, GetLocation ($1));
}
| OP_INC prefixed_unary_expression
{
- $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, (Expression) $2);
+ $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, (Expression) $2, GetLocation ($1));
}
| OP_DEC prefixed_unary_expression
{
- $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, (Expression) $2);
+ $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, (Expression) $2, GetLocation ($1));
}
| STAR prefixed_unary_expression
{
}
| BITWISE_AND prefixed_unary_expression
{
- $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2);
+ $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, GetLocation ($1));
}
;
| multiplicative_expression STAR prefixed_unary_expression
{
$$ = new Binary (Binary.Operator.Multiply,
- (Expression) $1, (Expression) $3);
+ (Expression) $1, (Expression) $3, GetLocation ($2));
}
| multiplicative_expression DIV prefixed_unary_expression
{
$$ = new Binary (Binary.Operator.Division,
- (Expression) $1, (Expression) $3);
+ (Expression) $1, (Expression) $3, GetLocation ($2));
}
| multiplicative_expression PERCENT prefixed_unary_expression
{
$$ = new Binary (Binary.Operator.Modulus,
- (Expression) $1, (Expression) $3);
+ (Expression) $1, (Expression) $3, GetLocation ($2));
}
;
| additive_expression PLUS multiplicative_expression
{
$$ = new Binary (Binary.Operator.Addition,
- (Expression) $1, (Expression) $3);
+ (Expression) $1, (Expression) $3, GetLocation ($2));
}
| additive_expression MINUS multiplicative_expression
{
- $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
+ $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3, GetLocation ($2));
}
| parenthesized_expression MINUS multiplicative_expression
{
// Shift/Reduce conflict
- $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
+ $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3, GetLocation ($2));
}
| additive_expression AS type
{
| shift_expression OP_SHIFT_LEFT additive_expression
{
$$ = new Binary (Binary.Operator.LeftShift,
- (Expression) $1, (Expression) $3);
+ (Expression) $1, (Expression) $3, GetLocation ($2));
}
| shift_expression OP_SHIFT_RIGHT additive_expression
{
$$ = new Binary (Binary.Operator.RightShift,
- (Expression) $1, (Expression) $3);
+ (Expression) $1, (Expression) $3, GetLocation ($2));
}
;
| relational_expression OP_LT shift_expression
{
$$ = new Binary (Binary.Operator.LessThan,
- (Expression) $1, (Expression) $3);
+ (Expression) $1, (Expression) $3, GetLocation ($2));
}
| relational_expression OP_GT shift_expression
{
$$ = new Binary (Binary.Operator.GreaterThan,
- (Expression) $1, (Expression) $3);
+ (Expression) $1, (Expression) $3, GetLocation ($2));
}
| relational_expression OP_LE shift_expression
{
$$ = new Binary (Binary.Operator.LessThanOrEqual,
- (Expression) $1, (Expression) $3);
+ (Expression) $1, (Expression) $3, GetLocation ($2));
}
| relational_expression OP_GE shift_expression
{
$$ = new Binary (Binary.Operator.GreaterThanOrEqual,
- (Expression) $1, (Expression) $3);
+ (Expression) $1, (Expression) $3, GetLocation ($2));
}
;
| equality_expression OP_EQ relational_expression
{
$$ = new Binary (Binary.Operator.Equality,
- (Expression) $1, (Expression) $3);
+ (Expression) $1, (Expression) $3, GetLocation ($2));
}
| equality_expression OP_NE relational_expression
{
$$ = new Binary (Binary.Operator.Inequality,
- (Expression) $1, (Expression) $3);
+ (Expression) $1, (Expression) $3, GetLocation ($2));
}
;
| and_expression BITWISE_AND equality_expression
{
$$ = new Binary (Binary.Operator.BitwiseAnd,
- (Expression) $1, (Expression) $3);
+ (Expression) $1, (Expression) $3, GetLocation ($2));
}
;
| exclusive_or_expression CARRET and_expression
{
$$ = new Binary (Binary.Operator.ExclusiveOr,
- (Expression) $1, (Expression) $3);
+ (Expression) $1, (Expression) $3, GetLocation ($2));
}
;
| inclusive_or_expression BITWISE_OR exclusive_or_expression
{
$$ = new Binary (Binary.Operator.BitwiseOr,
- (Expression) $1, (Expression) $3);
+ (Expression) $1, (Expression) $3, GetLocation ($2));
}
;
| conditional_and_expression OP_AND inclusive_or_expression
{
$$ = new Binary (Binary.Operator.LogicalAnd,
- (Expression) $1, (Expression) $3);
+ (Expression) $1, (Expression) $3, GetLocation ($2));
}
;
| conditional_or_expression OP_OR conditional_and_expression
{
$$ = new Binary (Binary.Operator.LogicalOr,
- (Expression) $1, (Expression) $3);
+ (Expression) $1, (Expression) $3, GetLocation ($2));
}
;
: null_coalescing_expression
| null_coalescing_expression INTERR expression COLON expression
{
- $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, (Expression) $5);
+ $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, (Expression) $5, GetLocation ($2));
+ lbag.AddLocation ($$, GetLocation ($4));
}
;
assignment_expression
: prefixed_unary_expression ASSIGN expression
{
- $$ = new SimpleAssign ((Expression) $1, (Expression) $3);
+ $$ = new SimpleAssign ((Expression) $1, (Expression) $3, GetLocation ($2));
}
| prefixed_unary_expression OP_MULT_ASSIGN expression
{
$$ = new CompoundAssign (
- Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
+ Binary.Operator.Multiply, (Expression) $1, (Expression) $3, GetLocation ($2));
}
| prefixed_unary_expression OP_DIV_ASSIGN expression
{
$$ = new CompoundAssign (
- Binary.Operator.Division, (Expression) $1, (Expression) $3);
+ Binary.Operator.Division, (Expression) $1, (Expression) $3, GetLocation ($2));
}
| prefixed_unary_expression OP_MOD_ASSIGN expression
{
$$ = new CompoundAssign (
- Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
+ Binary.Operator.Modulus, (Expression) $1, (Expression) $3, GetLocation ($2));
}
| prefixed_unary_expression OP_ADD_ASSIGN expression
{
$$ = new CompoundAssign (
- Binary.Operator.Addition, (Expression) $1, (Expression) $3);
+ Binary.Operator.Addition, (Expression) $1, (Expression) $3, GetLocation ($2));
}
| prefixed_unary_expression OP_SUB_ASSIGN expression
{
$$ = new CompoundAssign (
- Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
+ Binary.Operator.Subtraction, (Expression) $1, (Expression) $3, GetLocation ($2));
}
| prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
{
$$ = new CompoundAssign (
- Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
+ Binary.Operator.LeftShift, (Expression) $1, (Expression) $3, GetLocation ($2));
}
| prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
{
$$ = new CompoundAssign (
- Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
+ Binary.Operator.RightShift, (Expression) $1, (Expression) $3, GetLocation ($2));
}
| prefixed_unary_expression OP_AND_ASSIGN expression
{
$$ = new CompoundAssign (
- Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
+ Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3, GetLocation ($2));
}
| prefixed_unary_expression OP_OR_ASSIGN expression
{
$$ = new CompoundAssign (
- Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
+ Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3, GetLocation ($2));
}
| prefixed_unary_expression OP_XOR_ASSIGN expression
{
$$ = new CompoundAssign (
- Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
+ Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3, GetLocation ($2));
}
;
lambda_expression_body
{
$$ = end_anonymous ((ToplevelBlock) $4);
+ lbag.AddLocation ($$, GetLocation ($2));
}
| OPEN_PARENS_LAMBDA
{
+ if (RootContext.Version <= LanguageVersion.ISO_2)
+ Report.FeatureIsNotAvailable (GetLocation ($1), "lambda expressions");
+
valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
}
opt_lambda_parameter_list CLOSE_PARENS ARROW
lambda_expression_body
{
$$ = end_anonymous ((ToplevelBlock) $7);
+ lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
}
;
non_assignment_expression
: conditional_expression
| lambda_expression
- | query_expression
+ | query_expression
;
constant_expression
lexer.ConstraintsParsing = false;
current_class.SetParameterInfo ((List<Constraints>) $9);
+ lbag.AddMember (current_class, mod_locations, GetLocation ($4));
if (RootContext.Documentation != null) {
current_container.DocComment = Lexer.consume_doc_comment ();
Lexer.doc_state = XmlCommentState.Allowed;
}
}
- class_body
+ OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
{
- --lexer.parsing_declaration;
+ --lexer.parsing_declaration;
if (RootContext.Documentation != null)
Lexer.doc_state = XmlCommentState.Allowed;
}
opt_semicolon
{
+ lbag.AppendToMember (current_class, GetLocation ($11), GetLocation ($13), GetLocation ($15));
$$ = pop_current_class ();
}
;
;
opt_modifiers
- : /* empty */ { $$ = (int) 0; }
+ : /* empty */
+ {
+ mod_locations = null;
+ $$ = ModifierNone;
+ }
| modifiers
;
var m2 = (Modifiers) $2;
if ((m1 & m2) != 0) {
- Location l = lexer.Location;
- Report.Error (1004, l, "Duplicate `{0}' modifier", ModifiersExtensions.Name (m2));
+ Report.Error (1004, lexer.Location - ModifiersExtensions.Name (m2).Length,
+ "Duplicate `{0}' modifier", ModifiersExtensions.Name (m2));
+ } else if ((m2 & Modifiers.AccessibilityMask) != 0 && (m1 & Modifiers.AccessibilityMask) != 0 &&
+ ((m2 | m1 & Modifiers.AccessibilityMask) != (Modifiers.PROTECTED | Modifiers.INTERNAL))) {
+ Report.Error (107, lexer.Location - ModifiersExtensions.Name (m2).Length,
+ "More than one protection modifier specified");
}
+
$$ = m1 | m2;
}
;
: NEW
{
$$ = Modifiers.NEW;
+ StoreModifierLocation ($$, GetLocation ($1));
+
if (current_container == RootContext.ToplevelTypes)
Report.Error (1530, GetLocation ($1), "Keyword `new' is not allowed on namespace elements");
}
- | PUBLIC { $$ = Modifiers.PUBLIC; }
- | PROTECTED { $$ = Modifiers.PROTECTED; }
- | INTERNAL { $$ = Modifiers.INTERNAL; }
- | PRIVATE { $$ = Modifiers.PRIVATE; }
- | ABSTRACT { $$ = Modifiers.ABSTRACT; }
- | SEALED { $$ = Modifiers.SEALED; }
- | STATIC { $$ = Modifiers.STATIC; }
- | READONLY { $$ = Modifiers.READONLY; }
- | VIRTUAL { $$ = Modifiers.VIRTUAL; }
- | OVERRIDE { $$ = Modifiers.OVERRIDE; }
- | EXTERN { $$ = Modifiers.EXTERN; }
- | VOLATILE { $$ = Modifiers.VOLATILE; }
- | UNSAFE { $$ = Modifiers.UNSAFE; }
+ | PUBLIC
+ {
+ $$ = Modifiers.PUBLIC;
+ StoreModifierLocation ($$, GetLocation ($1));
+ }
+ | PROTECTED
+ {
+ $$ = Modifiers.PROTECTED;
+ StoreModifierLocation ($$, GetLocation ($1));
+ }
+ | INTERNAL
+ {
+ $$ = Modifiers.INTERNAL;
+ StoreModifierLocation ($$, GetLocation ($1));
+ }
+ | PRIVATE
+ {
+ $$ = Modifiers.PRIVATE;
+ StoreModifierLocation ($$, GetLocation ($1));
+ }
+ | ABSTRACT
+ {
+ $$ = Modifiers.ABSTRACT;
+ StoreModifierLocation ($$, GetLocation ($1));
+ }
+ | SEALED
+ {
+ $$ = Modifiers.SEALED;
+ StoreModifierLocation ($$, GetLocation ($1));
+ }
+ | STATIC
+ {
+ $$ = Modifiers.STATIC;
+ StoreModifierLocation ($$, GetLocation ($1));
+ }
+ | READONLY
+ {
+ $$ = Modifiers.READONLY;
+ StoreModifierLocation ($$, GetLocation ($1));
+ }
+ | VIRTUAL
+ {
+ $$ = Modifiers.VIRTUAL;
+ StoreModifierLocation ($$, GetLocation ($1));
+ }
+ | OVERRIDE
+ {
+ $$ = Modifiers.OVERRIDE;
+ StoreModifierLocation ($$, GetLocation ($1));
+ }
+ | EXTERN
+ {
+ $$ = Modifiers.EXTERN;
+ StoreModifierLocation ($$, GetLocation ($1));
+ }
+ | VOLATILE
+ {
+ $$ = Modifiers.VOLATILE;
+ StoreModifierLocation ($$, GetLocation ($1));
+ }
+ | UNSAFE
+ {
+ $$ = Modifiers.UNSAFE;
+ StoreModifierLocation ($$, GetLocation ($1));
+ if (!RootContext.Unsafe)
+ Error_UnsafeCodeNotAllowed (GetLocation ($1));
+ }
;
opt_class_base
: /* empty */
- | class_base
- ;
-
-class_base
- : COLON type_list
+ | COLON type_list
{
current_container.AddBasesForPart (current_class, (List<FullNamedExpression>) $2);
}
opt_type_parameter_constraints_clauses
: /* empty */ { $$ = null; }
| type_parameter_constraints_clauses
- { $$ = $1; }
+ {
+ $$ = $1;
+ }
;
type_parameter_constraints_clauses
- : type_parameter_constraints_clause {
+ : type_parameter_constraints_clause
+ {
var constraints = new List<Constraints> (1);
constraints.Add ((Constraints) $1);
$$ = constraints;
}
- | type_parameter_constraints_clauses type_parameter_constraints_clause {
+ | type_parameter_constraints_clauses type_parameter_constraints_clause
+ {
var constraints = (List<Constraints>) $1;
Constraints new_constraint = (Constraints)$2;
foreach (Constraints c in constraints) {
- if (new_constraint.TypeParameter == c.TypeParameter) {
- Report.Error (409, new_constraint.Location, "A constraint clause has already been specified for type parameter `{0}'",
- new_constraint.TypeParameter);
+ if (new_constraint.TypeParameter.Value == c.TypeParameter.Value) {
+ Report.Error (409, new_constraint.Location,
+ "A constraint clause has already been specified for type parameter `{0}'",
+ new_constraint.TypeParameter.Value);
}
}
;
type_parameter_constraints_clause
- : WHERE IDENTIFIER COLON type_parameter_constraints {
+ : WHERE IDENTIFIER COLON type_parameter_constraints
+ {
var lt = (Tokenizer.LocatedToken) $2;
- $$ = new Constraints (lt.Value, (List<object>) $4, lt.Location);
+ $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), (List<FullNamedExpression>) $4, GetLocation ($1));
}
;
type_parameter_constraints
- : type_parameter_constraint {
- var constraints = new List<object> (1);
- constraints.Add ($1);
+ : type_parameter_constraint
+ {
+ var constraints = new List<FullNamedExpression> (1);
+ constraints.Add ((FullNamedExpression) $1);
$$ = constraints;
}
- | type_parameter_constraints COMMA type_parameter_constraint {
- var constraints = (List<object>) $1;
+ | type_parameter_constraints COMMA type_parameter_constraint
+ {
+ var constraints = (List<FullNamedExpression>) $1;
+ var prev = constraints [constraints.Count - 1] as SpecialContraintExpr;
+ if (prev != null && (prev.Constraint & SpecialConstraint.Constructor) != 0) {
+ Report.Error (401, GetLocation ($2), "The `new()' constraint must be the last constraint specified");
+ }
+
+ prev = $3 as SpecialContraintExpr;
+ if (prev != null) {
+ if ((prev.Constraint & (SpecialConstraint.Class | SpecialConstraint.Struct)) != 0) {
+ Report.Error (449, prev.Location, "The `class' or `struct' constraint must be the first constraint specified");
+ } else {
+ prev = constraints [0] as SpecialContraintExpr;
+ if (prev != null && (prev.Constraint & SpecialConstraint.Struct) != 0) {
+ Report.Error (451, GetLocation ($3), "The `new()' constraint cannot be used with the `struct' constraint");
+ }
+ }
+ }
- constraints.Add ($3);
+ constraints.Add ((FullNamedExpression) $3);
$$ = constraints;
}
;
type_parameter_constraint
: type
- | NEW OPEN_PARENS CLOSE_PARENS {
- $$ = SpecialConstraint.Constructor;
+ {
+ if ($1 is ComposedCast)
+ Report.Error (706, GetLocation ($1), "Invalid constraint type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
+
+ $$ = $1;
+ }
+ | NEW OPEN_PARENS CLOSE_PARENS
+ {
+ $$ = new SpecialContraintExpr (SpecialConstraint.Constructor, GetLocation ($1));
+ lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
}
- | CLASS {
- $$ = SpecialConstraint.ReferenceType;
+ | CLASS
+ {
+ $$ = new SpecialContraintExpr (SpecialConstraint.Class, GetLocation ($1));
}
- | STRUCT {
- $$ = SpecialConstraint.ValueType;
+ | STRUCT
+ {
+ $$ = new SpecialContraintExpr (SpecialConstraint.Struct, GetLocation ($1));
}
;
valid_declaration_statement
: block
| empty_statement
- | expression_statement
+ | expression_statement
| selection_statement
| iteration_statement
| jump_statement
empty_statement
: SEMICOLON
{
- $$ = EmptyStatement.Value;
+ $$ = new EmptyStatement (GetLocation ($1));
}
;
variable_type
: primary_expression_no_array_creation opt_rank_specifier_or_nullable
{
- // FIXME: Do something smart here regarding the composition of the type.
-
// Ok, the above "primary_expression" is there to get rid of
// both reduce/reduce and shift/reduces in the grammar, it should
// really just be "type_name". If you use type_name, a reduce/reduce
// Blah i;
Expression expr = (Expression) $1;
- string rank_or_nullable = (string) $2;
-
- if (expr is ComposedCast){
- $$ = new ComposedCast ((ComposedCast)expr, rank_or_nullable);
- } else if (expr is ATypeNameExpression){
- //
- // So we extract the string corresponding to the SimpleName
- // or MemberAccess
- //
- if (rank_or_nullable.Length == 0) {
- SimpleName sn = expr as SimpleName;
- if (sn != null && sn.Name == "var")
- $$ = new VarExpr (sn.Location);
- else
- $$ = $1;
- } else {
- $$ = new ComposedCast ((ATypeNameExpression)expr, rank_or_nullable);
- }
+ if ($2 == null) {
+ SimpleName sn = expr as SimpleName;
+ if (sn != null && sn.Name == "var")
+ $$ = new VarExpr (sn.Location);
+ else
+ $$ = $1;
+ } else if (expr is ATypeNameExpression) {
+ $$ = new ComposedCast ((ATypeNameExpression)expr, (ComposedTypeSpecifier) $2);
} else {
Error_ExpectingTypeName (expr);
- $$ = TypeManager.system_object_expr;
+ $$ = null;
}
}
| builtin_types opt_rank_specifier_or_nullable
{
- if ((string) $2 == "")
+ if ($2 == null)
$$ = $1;
else
- $$ = new ComposedCast ((FullNamedExpression) $1, (string) $2, lexer.Location);
+ $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
}
| VOID opt_rank_specifier
{
Expression.Error_VoidInvalidInTheContext (GetLocation ($1), Report);
- $$ = TypeManager.system_void_expr;
+ $$ = new TypeExpression (TypeManager.void_type, GetLocation ($1));
}
;
ATypeNameExpression expr = $1 as ATypeNameExpression;
if (expr != null) {
- $$ = new ComposedCast (expr, "*");
+ $$ = new ComposedCast (expr, ComposedTypeSpecifier.CreatePointer (GetLocation ($2)));
} else {
Error_ExpectingTypeName ((Expression)$1);
$$ = expr;
}
| builtin_types STAR
{
- $$ = new ComposedCast ((FullNamedExpression) $1, "*", GetLocation ($1));
+ $$ = new ComposedCast ((FullNamedExpression) $1, ComposedTypeSpecifier.CreatePointer (GetLocation ($2)));
}
| VOID STAR
{
- $$ = new ComposedCast (TypeManager.system_void_expr, "*", GetLocation ($1));
+ $$ = new ComposedCast (new TypeExpression (TypeManager.void_type, GetLocation ($1)), ComposedTypeSpecifier.CreatePointer (GetLocation ($2)));
}
| local_variable_pointer_type STAR
{
- $$ = new ComposedCast ((FullNamedExpression) $1, "*");
+ $$ = new ComposedCast ((FullNamedExpression) $1, ComposedTypeSpecifier.CreatePointer (GetLocation ($2)));
}
;
| local_variable_pointer_type opt_rank_specifier
{
if ($1 != null){
- string rank = (string)$2;
-
- if (rank == "")
+ if ($2 == null)
$$ = $1;
else
- $$ = new ComposedCast ((FullNamedExpression) $1, rank);
+ $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
} else {
$$ = null;
}
;
local_constant_declaration
- : CONST variable_type constant_declarators
+ : CONST variable_type local_constant_declarators
{
if ($2 != null)
$$ = new Tuple<FullNamedExpression, List<object>> ((FullNamedExpression) $2, (List<object>) $3);
$$ = null;
}
;
+
+local_constant_declarators
+ : local_constant_declarator
+ {
+ variables_bucket.Clear ();
+ if ($1 != null)
+ variables_bucket.Add ($1);
+ $$ = variables_bucket;
+ }
+ | local_constant_declarators COMMA local_constant_declarator
+ {
+ if ($3 != null) {
+ var constants = (List<object>) $1;
+ constants.Add ($3);
+ }
+ }
+ ;
+
+local_constant_declarator
+ : IDENTIFIER ASSIGN constant_initializer_expr
+ {
+ $$ = new VariableDeclaration ((Tokenizer.LocatedToken) $1, (Expression) $3);
+ }
+ | IDENTIFIER error
+ {
+ Report.Error (145, GetLocation ($1), "A const field requires a value to be provided");
+ $$ = null;
+ }
+ ;
expression_statement
- : statement_expression SEMICOLON { $$ = $1; }
+ : statement_expression SEMICOLON
+ {
+ $$ = $1;
+ lbag.AddStatement ($$, GetLocation ($2));
+ }
| statement_expression COMPLETE_COMPLETION { $$ = $1; }
;
| error
{
Error_SyntaxError (yyToken);
- $$ = EmptyStatement.Value;
+ $$ = new EmptyStatement (GetLocation ($1));
}
;
: IF open_parens_any boolean_expression CLOSE_PARENS
embedded_statement
{
- Location l = GetLocation ($1);
-
- $$ = new If ((BooleanExpression) $3, (Statement) $5, l);
-
- // FIXME: location for warning should be loc property of $5.
- if ($5 == EmptyStatement.Value)
- Report.Warning (642, 3, l, "Possible mistaken empty statement");
-
+ if ($5 is EmptyStatement)
+ Report.Warning (642, 3, GetLocation ($5), "Possible mistaken empty statement");
+
+ $$ = new If ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
+ lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
}
| IF open_parens_any boolean_expression CLOSE_PARENS
embedded_statement ELSE embedded_statement
{
- Location l = GetLocation ($1);
-
- $$ = new If ((BooleanExpression) $3, (Statement) $5, (Statement) $7, l);
-
- // FIXME: location for warning should be loc property of $5 and $7.
- if ($5 == EmptyStatement.Value)
- Report.Warning (642, 3, l, "Possible mistaken empty statement");
- if ($7 == EmptyStatement.Value)
- Report.Warning (642, 3, l, "Possible mistaken empty statement");
+ $$ = new If ((BooleanExpression) $3, (Statement) $5, (Statement) $7, GetLocation ($1));
+ lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
+
+ if ($5 is EmptyStatement)
+ Report.Warning (642, 3, GetLocation ($5), "Possible mistaken empty statement");
+ if ($7 is EmptyStatement)
+ Report.Warning (642, 3, GetLocation ($7), "Possible mistaken empty statement");
}
;
switch_stack.Push (current_block);
}
expression CLOSE_PARENS
- switch_block
+ OPEN_BRACE opt_switch_sections CLOSE_BRACE
{
- $$ = new Switch ((Expression) $4, (List<SwitchSection>) $6, GetLocation ($1));
+ $$ = new Switch ((Expression) $4, (List<SwitchSection>) $7, GetLocation ($1));
+ lbag.AddStatement ($$, GetLocation ($2), GetLocation ($5), GetLocation ($6), GetLocation ($8));
+
current_block = (Block) switch_stack.Pop ();
}
;
-switch_block
- : OPEN_BRACE
- opt_switch_sections
- CLOSE_BRACE
- {
- $$ = $2;
- }
- ;
-
opt_switch_sections
: /* empty */
- {
- Report.Warning (1522, 1, lexer.Location, "Empty switch block");
+ {
+ Report.Warning (1522, 1, lexer.Location, "Empty switch block");
$$ = new List<SwitchSection> ();
}
| switch_sections
: CASE constant_expression COLON
{
$$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
+ lbag.AddLocation ($$, GetLocation ($3));
}
| DEFAULT_COLON
{
while_statement
: WHILE open_parens_any boolean_expression CLOSE_PARENS embedded_statement
{
- Location l = GetLocation ($1);
- $$ = new While ((BooleanExpression) $3, (Statement) $5, l);
+ $$ = new While ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
+ lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
}
;
: DO embedded_statement
WHILE open_parens_any boolean_expression CLOSE_PARENS SEMICOLON
{
- Location l = GetLocation ($1);
-
- $$ = new Do ((Statement) $2, (BooleanExpression) $5, l);
+ $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1));
+ lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4), GetLocation ($6), GetLocation ($7));
}
;
opt_for_iterator CLOSE_PARENS
embedded_statement
{
- Location l = GetLocation ($1);
-
- For f = new For ((Statement) $5, (BooleanExpression) $6, (Statement) $8, (Statement) $10, l);
-
+ For f = new For ((Statement) $5, (BooleanExpression) $6, (Statement) $8, (Statement) $10, GetLocation ($1));
current_block.AddStatement (f);
+
+ lbag.AddStatement (f, GetLocation ($2), GetLocation ($4), GetLocation ($7), GetLocation ($9));
$$ = end_block (lexer.Location);
}
;
opt_for_initializer
- : /* empty */ { $$ = EmptyStatement.Value; }
+ : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
| for_initializer
;
;
opt_for_iterator
- : /* empty */ { $$ = EmptyStatement.Value; }
+ : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
| for_iterator
;
;
statement_expression_list
- : statement_expression
- {
- // CHANGE: was `null'
- Statement s = (Statement) $1;
- Block b = new Block (current_block, s.loc, lexer.Location);
-
- b.AddStatement (s);
- $$ = b;
- }
+ : statement_expression
| statement_expression_list COMMA statement_expression
{
- Block b = (Block) $1;
-
- b.AddStatement ((Statement) $3);
- $$ = $1;
+ var sl = $1 as StatementList;
+ if (sl == null)
+ sl = new StatementList ((Statement) $1, (Statement) $3);
+ else
+ sl.Add ((Statement) $3);
+
+ lbag.AddStatement (sl, GetLocation ($2));
+ $$ = sl;
}
;
}
embedded_statement
{
- LocalVariableReference v = (LocalVariableReference) $8;
- Location l = GetLocation ($1);
-
- if (v != null) {
- Foreach f = new Foreach ((Expression) $3, v, (Expression) $6, (Statement) $9, l);
+ if ($8 != null) {
+ Foreach f = new Foreach ((Expression) $3, (LocalVariableReference) $8, (Expression) $6, (Statement) $9, GetLocation ($1));
+ lbag.AddStatement (f, GetLocation ($2), GetLocation ($5), GetLocation ($7));
+
current_block.AddStatement (f);
}
: BREAK SEMICOLON
{
$$ = new Break (GetLocation ($1));
+ lbag.AddStatement ($$, GetLocation ($2));
}
;
: CONTINUE SEMICOLON
{
$$ = new Continue (GetLocation ($1));
+ lbag.AddStatement ($$, GetLocation ($2));
}
;
{
var lt = (Tokenizer.LocatedToken) $2;
$$ = new Goto (lt.Value, lt.Location);
+ lbag.AddStatement ($$, GetLocation ($1), GetLocation ($3));
}
| GOTO CASE constant_expression SEMICOLON
{
$$ = new GotoCase ((Expression) $3, GetLocation ($1));
+ lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
}
| GOTO DEFAULT SEMICOLON
{
$$ = new GotoDefault (GetLocation ($1));
+ lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
}
;
: RETURN opt_expression SEMICOLON
{
$$ = new Return ((Expression) $2, GetLocation ($1));
+ lbag.AddStatement ($$, GetLocation ($3));
}
;
: THROW opt_expression SEMICOLON
{
$$ = new Throw ((Expression) $2, GetLocation ($1));
+ lbag.AddStatement ($$, GetLocation ($3));
}
;
yield_statement
- : IDENTIFIER RETURN expression SEMICOLON
+ : IDENTIFIER RETURN opt_expression SEMICOLON
{
var lt = (Tokenizer.LocatedToken) $1;
string s = lt.Value;
if (s != "yield"){
Report.Error (1003, lt.Location, "; expected");
- $$ = null;
- }
- if (RootContext.Version == LanguageVersion.ISO_1){
- Report.FeatureIsNotAvailable (lt.Location, "yield statement");
- $$ = null;
+ } else if ($3 == null) {
+ Report.Error (1627, GetLocation ($4), "Expression expected after yield return");
+ } else if (RootContext.Version == LanguageVersion.ISO_1){
+ Report.FeatureIsNotAvailable (lt.Location, "iterators");
}
+
current_block.Toplevel.IsIterator = true;
- $$ = new Yield ((Expression) $3, lt.Location);
- }
- | IDENTIFIER RETURN SEMICOLON
- {
- Report.Error (1627, GetLocation ($2), "Expression expected after yield return");
- $$ = null;
+ $$ = new Yield ((Expression) $3, lt.Location);
+ lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
}
| IDENTIFIER BREAK SEMICOLON
{
string s = lt.Value;
if (s != "yield"){
Report.Error (1003, lt.Location, "; expected");
- $$ = null;
- }
- if (RootContext.Version == LanguageVersion.ISO_1){
- Report.FeatureIsNotAvailable (lt.Location, "yield statement");
- $$ = null;
+ } else if (RootContext.Version == LanguageVersion.ISO_1){
+ Report.FeatureIsNotAvailable (lt.Location, "iterators");
}
current_block.Toplevel.IsIterator = true;
$$ = new YieldBreak (lt.Location);
+ lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
}
;
| TRY block FINALLY block
{
$$ = new TryFinally ((Statement) $2, (Block) $4, GetLocation ($1));
+ lbag.AddStatement ($$, GetLocation ($3));
}
| TRY block catch_clauses FINALLY block
{
$$ = new TryFinally (new TryCatch ((Block) $2, (List<Catch>) $3, GetLocation ($1), true), (Block) $5, GetLocation ($1));
+ lbag.AddStatement ($$, GetLocation ($4));
}
| TRY block error
{
}
$$ = new Catch (type, id, (Block) $4, var_block, ((Block) $4).loc);
+ lbag.AddLocation ($$, GetLocation ($1));
+ lbag.AppendTo ($$, lbag.GetLocations ($2));
}
;
: open_parens_any type opt_identifier CLOSE_PARENS
{
$$ = new Tuple<FullNamedExpression, Tokenizer.LocatedToken> ((FullNamedExpression)$2, (Tokenizer.LocatedToken) $3);
+ lbag.AddLocation ($$, GetLocation ($1), GetLocation ($4));
}
| open_parens_any CLOSE_PARENS
{
checked_statement
: CHECKED block
{
- $$ = new Checked ((Block) $2);
+ $$ = new Checked ((Block) $2, GetLocation ($1));
}
;
unchecked_statement
: UNCHECKED block
{
- $$ = new Unchecked ((Block) $2);
+ $$ = new Unchecked ((Block) $2, GetLocation ($1));
}
;
unsafe_statement
- : UNSAFE
+ : UNSAFE
{
- RootContext.CheckUnsafeOption (GetLocation ($1), Report);
+ if (!RootContext.Unsafe)
+ Error_UnsafeCodeNotAllowed (GetLocation ($1));
} block {
- $$ = new Unsafe ((Block) $3);
+ $$ = new Unsafe ((Block) $3, GetLocation ($1));
}
;
return v;
}), (Statement) $7, GetLocation ($1));
+ lbag.AddStatement (f, GetLocation ($2), GetLocation ($5));
+
current_block.AddStatement (f);
$$ = end_block (lexer.Location);
;
lock_statement
- : LOCK open_parens_any expression CLOSE_PARENS
- {
- //
- }
- embedded_statement
+ : LOCK open_parens_any expression CLOSE_PARENS embedded_statement
{
- $$ = new Lock ((Expression) $3, (Statement) $6, GetLocation ($1));
+ $$ = new Lock ((Expression) $3, (Statement) $5, GetLocation ($1));
+ lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
}
;
var vars = new Stack<Tuple<LocalVariableReference, Expression>> ();
+ lbag.AddStatement (assign_block, GetLocation ($1), GetLocation ($2), GetLocation ($4));
+
foreach (VariableDeclaration decl in de.Item2) {
LocalInfo vi = current_block.AddVariable (de.Item1, decl.identifier, decl.Location);
if (vi == null)
}
embedded_statement
{
- current_block.AddStatement (new UsingTemporary ((Expression) $3, (Statement) $6, GetLocation ($1)));
+ UsingTemporary usingTemporary = new UsingTemporary ((Expression) $3, (Statement) $6, GetLocation ($1));
+ lbag.AddStatement (usingTemporary, GetLocation ($2), GetLocation ($4));
+ current_block.AddStatement (usingTemporary);
$$ = end_block (lexer.Location);
}
;
// LINQ
query_expression
- : first_from_clause query_body
+ : first_from_clause query_body
{
lexer.query_parsing = false;
current_block.SetEndLocation (lexer.Location);
current_block = current_block.Parent;
}
+
+ // Bubble up COMPLETE_COMPLETION productions
+ | first_from_clause COMPLETE_COMPLETION {
+ lexer.query_parsing = false;
+ $$ = $1;
+
+ current_block.SetEndLocation (lexer.Location);
+ current_block = current_block.Parent;
+ }
+ | nested_from_clause COMPLETE_COMPLETION {
+ $$ = $1;
+ current_block.SetEndLocation (lexer.Location);
+ current_block = current_block.Parent;
+ }
;
first_from_clause
: FROM_FIRST IDENTIFIER IN expression
{
- $$ = new Linq.QueryExpression (current_block, new Linq.QueryStartClause ((Expression)$4));
- var lt = (Tokenizer.LocatedToken) $2;
- current_block = new Linq.QueryBlock (compiler, current_block, new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1));
+ current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+
+ var lt = (Tokenizer.LocatedToken) $2;
+ $$ = new Linq.QueryExpression (new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1)));
}
| FROM_FIRST type IDENTIFIER IN expression
{
+ current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+
var lt = (Tokenizer.LocatedToken) $3;
- $$ = new Linq.QueryExpression (current_block, new Linq.Cast ((FullNamedExpression)$2, (Expression)$5));
- current_block = new Linq.QueryBlock (compiler, current_block, new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1));
+ $$ = new Linq.QueryExpression (
+ new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1)) {
+ IdentifierType = (FullNamedExpression)$2
+ }
+ );
}
;
nested_from_clause
: FROM IDENTIFIER IN expression
{
- $$ = new Linq.QueryExpression (current_block, new Linq.QueryStartClause ((Expression)$4));
- var lt = (Tokenizer.LocatedToken) $2;
- current_block = new Linq.QueryBlock (compiler, current_block, new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1));
+ current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+
+ var lt = (Tokenizer.LocatedToken) $2;
+ $$ = new Linq.QueryExpression (new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1)));
}
| FROM type IDENTIFIER IN expression
{
- $$ = new Linq.QueryExpression (current_block, new Linq.Cast ((FullNamedExpression)$2, (Expression)$5));
+ current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+
var lt = (Tokenizer.LocatedToken) $3;
- current_block = new Linq.QueryBlock (compiler, current_block, new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1));
+ $$ = new Linq.QueryExpression (
+ new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1)) {
+ IdentifierType = (FullNamedExpression)$2
+ }
+ );
}
;
from_clause
: FROM IDENTIFIER IN
{
- current_block = new Linq.QueryBlock (compiler, current_block, GetLocation ($1));
+ current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
}
expression
{
var lt = (Tokenizer.LocatedToken) $2;
var sn = new SimpleMemberName (lt.Value, lt.Location);
- $$ = new Linq.SelectMany (current_block.Toplevel, sn, (Expression)$5);
+ $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$5, GetLocation ($1));
current_block.SetEndLocation (lexer.Location);
current_block = current_block.Parent;
- ((Linq.QueryBlock)current_block).AddTransparentParameter (compiler, sn);
+ ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
}
| FROM type IDENTIFIER IN
{
- current_block = new Linq.QueryBlock (compiler, current_block, GetLocation ($1));
+ current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
}
expression
{
var lt = (Tokenizer.LocatedToken) $3;
var sn = new SimpleMemberName (lt.Value, lt.Location);
- FullNamedExpression type = (FullNamedExpression)$2;
-
- $$ = new Linq.SelectMany (current_block.Toplevel, sn, new Linq.Cast (type, (FullNamedExpression)$6));
+ $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$6, GetLocation ($1)) {
+ IdentifierType = (FullNamedExpression)$2
+ };
current_block.SetEndLocation (lexer.Location);
current_block = current_block.Parent;
- ((Linq.QueryBlock)current_block).AddTransparentParameter (compiler, sn);
+ ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
}
;
query_body
- : opt_query_body_clauses select_or_group_clause opt_query_continuation
+ : opt_query_body_clauses select_or_group_clause opt_query_continuation
{
Linq.AQueryClause head = (Linq.AQueryClause)$2;
$$ = head;
}
+ | opt_query_body_clauses COMPLETE_COMPLETION
;
select_or_group_clause
}
expression
{
- $$ = new Linq.Select (current_block.Toplevel, (Expression)$3, GetLocation ($1));
+ $$ = new Linq.Select ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
current_block.SetEndLocation (lexer.Location);
current_block = current_block.Parent;
| GROUP
{
if (linq_clause_blocks == null)
- linq_clause_blocks = new Stack<Block> ();
+ linq_clause_blocks = new Stack<Linq.QueryBlock> ();
current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
- linq_clause_blocks.Push (current_block);
+ linq_clause_blocks.Push ((Linq.QueryBlock)current_block);
}
expression
{
}
BY expression
{
- $$ = new Linq.GroupBy (current_block.Toplevel, (Expression)$3, (ToplevelBlock) linq_clause_blocks.Pop (), (Expression)$6, GetLocation ($1));
+ $$ = new Linq.GroupBy ((Linq.QueryBlock)current_block, (Expression)$3, linq_clause_blocks.Pop (), (Expression)$6, GetLocation ($1));
current_block.SetEndLocation (lexer.Location);
current_block = current_block.Parent;
query_body_clause
: from_clause
- | let_clause
+ | let_clause
| where_clause
| join_clause
| orderby_clause
let_clause
: LET IDENTIFIER ASSIGN
{
- current_block = new Linq.QueryBlock (compiler, current_block, GetLocation ($1));
+ current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
}
expression
{
var lt = (Tokenizer.LocatedToken) $2;
var sn = new SimpleMemberName (lt.Value, lt.Location);
- $$ = new Linq.Let (current_block.Toplevel, current_container, sn, (Expression)$5);
+ $$ = new Linq.Let ((Linq.QueryBlock) current_block, sn, (Expression)$5, GetLocation ($1));
current_block.SetEndLocation (lexer.Location);
current_block = current_block.Parent;
- ((Linq.QueryBlock)current_block).AddTransparentParameter (compiler, sn);
+ ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
}
;
}
boolean_expression
{
- $$ = new Linq.Where (current_block.Toplevel, (BooleanExpression)$3, GetLocation ($1));
+ $$ = new Linq.Where ((Linq.QueryBlock)current_block, (BooleanExpression)$3, GetLocation ($1));
current_block.SetEndLocation (lexer.Location);
current_block = current_block.Parent;
: JOIN IDENTIFIER IN
{
if (linq_clause_blocks == null)
- linq_clause_blocks = new Stack<Block> ();
+ linq_clause_blocks = new Stack<Linq.QueryBlock> ();
current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
- linq_clause_blocks.Push (current_block);
+ linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
}
expression ON
{
current_block = current_block.Parent;
current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
- linq_clause_blocks.Push (current_block);
+ linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
}
expression EQUALS
{
current_block.SetEndLocation (lexer.Location);
current_block = current_block.Parent;
- var lt = (Tokenizer.LocatedToken) $2;
- current_block = new Linq.QueryBlock (compiler, current_block, new SimpleMemberName (lt.Value, lt.Location), lexer.Location);
+ current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
}
expression opt_join_into
{
var sn = new SimpleMemberName (lt.Value, lt.Location);
SimpleMemberName sn2 = null;
- ToplevelBlock outer_selector = (ToplevelBlock) linq_clause_blocks.Pop ();
- ToplevelBlock block = (ToplevelBlock) linq_clause_blocks.Pop ();
+ var outer_selector = linq_clause_blocks.Pop ();
+ var block = linq_clause_blocks.Pop ();
if ($12 == null) {
- $$ = new Linq.Join (block, sn, (Expression)$5, outer_selector, current_block.Toplevel, GetLocation ($1));
+ $$ = new Linq.Join (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1));
} else {
var lt2 = (Tokenizer.LocatedToken) $12;
sn2 = new SimpleMemberName (lt2.Value, lt2.Location);
- $$ = new Linq.GroupJoin (block, sn, (Expression)$5, outer_selector, current_block.Toplevel,
+ $$ = new Linq.GroupJoin (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block,
sn2, GetLocation ($1));
}
current_block.SetEndLocation (lexer.Location);
current_block = current_block.Parent;
- if (sn2 == null)
- ((Linq.QueryBlock)current_block).AddTransparentParameter (compiler, sn);
- else
- ((Linq.QueryBlock)current_block).AddTransparentParameter (compiler, sn2);
+ ((Linq.QueryBlock)current_block).AddRangeVariable (sn2 ?? sn);
}
| JOIN type IDENTIFIER IN
{
if (linq_clause_blocks == null)
- linq_clause_blocks = new Stack<Block> ();
+ linq_clause_blocks = new Stack<Linq.QueryBlock> ();
current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
- linq_clause_blocks.Push (current_block);
+ linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
}
expression ON
{
current_block = current_block.Parent;
current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
- linq_clause_blocks.Push (current_block);
+ linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
}
expression EQUALS
{
current_block.SetEndLocation (lexer.Location);
current_block = current_block.Parent;
- var lt = (Tokenizer.LocatedToken) $3;
- current_block = new Linq.QueryBlock (compiler, current_block, new SimpleMemberName (lt.Value, lt.Location), lexer.Location);
+ current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
}
expression opt_join_into
{
var lt = (Tokenizer.LocatedToken) $3;
var sn = new SimpleMemberName (lt.Value, lt.Location);
SimpleMemberName sn2 = null;
- ToplevelBlock outer_selector = (ToplevelBlock) linq_clause_blocks.Pop ();
- ToplevelBlock block = (ToplevelBlock) linq_clause_blocks.Pop ();
+ var outer_selector = linq_clause_blocks.Pop ();
+ var block = linq_clause_blocks.Pop ();
- Linq.Cast cast = new Linq.Cast ((FullNamedExpression)$2, (Expression)$6);
if ($13 == null) {
- $$ = new Linq.Join (block, sn, cast, outer_selector, current_block.Toplevel, GetLocation ($1));
+ $$ = new Linq.Join (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1)) {
+ IdentifierType = (FullNamedExpression)$2
+ };
} else {
var lt2 = (Tokenizer.LocatedToken) $13;
sn2 = new SimpleMemberName (lt2.Value, lt2.Location);
- $$ = new Linq.GroupJoin (block, sn, cast, outer_selector, current_block.Toplevel,
- sn2, GetLocation ($1));
+ $$ = new Linq.GroupJoin (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, sn2, GetLocation ($1)) {
+ IdentifierType = (FullNamedExpression)$2
+ };
}
current_block.AddStatement (new ContextualReturn ((Expression) $12));
current_block.SetEndLocation (lexer.Location);
current_block = current_block.Parent;
- if (sn2 == null)
- ((Linq.QueryBlock)current_block).AddTransparentParameter (compiler, sn);
- else
- ((Linq.QueryBlock)current_block).AddTransparentParameter (compiler, sn2);
+ ((Linq.QueryBlock)current_block).AddRangeVariable (sn2 ?? sn);
}
;
current_block.SetEndLocation (lexer.Location);
current_block = current_block.Parent;
- current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+ current_block = new Linq.QueryBlock (compiler, (Linq.QueryBlock) current_block, lexer.Location);
}
then_by
{
- ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$3;
+ ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$4;
$$ = $1;
}
;
order_by
: expression
{
- $$ = new Linq.OrderByAscending (current_block.Toplevel, (Expression)$1);
+ $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
}
| expression ASCENDING
{
- $$ = new Linq.OrderByAscending (current_block.Toplevel, (Expression)$1);
+ $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
}
| expression DESCENDING
{
- $$ = new Linq.OrderByDescending (current_block.Toplevel, (Expression)$1);
+ $$ = new Linq.OrderByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
}
;
then_by
: expression
{
- $$ = new Linq.ThenByAscending (current_block.Toplevel, (Expression)$1);
+ $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
}
| expression ASCENDING
{
- $$ = new Linq.ThenByAscending (current_block.Toplevel, (Expression)$1);
+ $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
}
| expression DESCENDING
{
- $$ = new Linq.ThenByDescending (current_block.Toplevel, (Expression)$1);
+ $$ = new Linq.ThenByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
}
;
current_block.SetEndLocation (GetLocation ($1));
current_block = current_block.Parent;
-
- var lt = (Tokenizer.LocatedToken) $2;
+
+ current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
- current_block = new Linq.QueryBlock (compiler, current_block, new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1));
+ if (linq_clause_blocks == null)
+ linq_clause_blocks = new Stack<Linq.QueryBlock> ();
+
+ linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
}
query_body
{
- $$ = new Linq.QueryExpression (current_block, (Linq.AQueryClause)$4);
+ var current_block = linq_clause_blocks.Pop ();
+ var lt = (Tokenizer.LocatedToken) $2;
+ $$ = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, null, new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1)) {
+ next = (Linq.AQueryClause)$4
+ };
}
;
// (ref object retval)
Parameter [] mpar = new Parameter [1];
- mpar [0] = new Parameter (TypeManager.system_object_expr, "$retval", Parameter.Modifier.REF, null, Location.Null);
+ mpar [0] = new Parameter (new TypeExpression (TypeManager.object_type, Location.Null), "$retval", Parameter.Modifier.REF, null, Location.Null);
ParametersCompiled pars = new ParametersCompiled (compiler, mpar);
current_local_parameters = pars;
Method method = new Method (
current_class,
null, // generic
- TypeManager.system_void_expr,
+ new TypeExpression (TypeManager.void_type, Location.Null),
Modifiers.PUBLIC | Modifiers.STATIC,
new MemberName ("Host"),
pars,
public string identifier;
Expression initializer;
public Location Location;
- public Attributes OptAttributes;
- public string DocComment;
- public VariableDeclaration (Tokenizer.LocatedToken lt, Expression initializer, Attributes opt_attrs)
+ public VariableDeclaration (Tokenizer.LocatedToken lt, Expression initializer)
{
this.identifier = lt.Value;
this.initializer = initializer;
this.Location = lt.Location;
- this.OptAttributes = opt_attrs;
- }
-
- public VariableDeclaration (Tokenizer.LocatedToken lt, Expression initializer)
- : this (lt, initializer, null)
- {
}
public Expression GetInitializer (FullNamedExpression type)
{
if (initializer is ArrayInitializer)
- return new ArrayCreation (type, "", (ArrayInitializer)initializer, Location);
+ return new ArrayCreation (type, (ArrayInitializer)initializer);
return initializer;
}
}
}
-class VariableMemberDeclaration
-{
- public readonly MemberName MemberName;
- Expression initializer;
-
- public VariableMemberDeclaration (MemberName mn, Expression initializer)
- {
- MemberName = mn;
- this.initializer = initializer;
- }
-
- public Expression GetInitializer (FullNamedExpression type)
- {
- if (initializer is ArrayInitializer)
- return new ArrayCreation (type, "", (ArrayInitializer)initializer, MemberName.Location);
-
- return initializer;
- }
-}
-
// <summary>
// A class used to hold info about an operator declarator
Report.Error (1031, loc, "Type expected");
}
+void Error_UnsafeCodeNotAllowed (Location loc)
+{
+ Report.Error (227, loc, "Unsafe code requires the `unsafe' command line option to be specified");
+}
+
void Error_NamedArgumentExpected (NamedArgument a)
{
Report.Error (1738, a.Location, "Named arguments must appear after the positional arguments");
}
}
+[System.Diagnostics.Conditional ("FULL_AST")]
+void StoreModifierLocation (object token, Location loc)
+{
+ if (lbag == null)
+ return;
+
+ if (mod_locations == null)
+ mod_locations = new List<Tuple<Modifiers, Location>> ();
+
+ mod_locations.Add (Tuple.Create ((Modifiers) token, loc));
+}
+
Block declare_local_variables (FullNamedExpression type, List<object> variable_declarators, Location loc)
{
Block implicit_block;
if (obj is MemberName)
return ((MemberName) obj).Location;
+ if (obj is Expression)
+ return ((Expression) obj).Location;
+
return lexer.Location;
}
get { return compiler.Report; }
}
+public LocationsBag LocationsBag {
+ get {
+ return lbag;
+ }
+ set {
+ lbag = value;
+ }
+}
+
void start_block (Location loc)
{
if (current_block == null || parsing_anonymous_method) {
- current_block = new ToplevelBlock (compiler, current_block, current_local_parameters, current_generic_method, loc);
+ current_block = new ToplevelBlock (compiler, current_block, current_local_parameters, loc);
parsing_anonymous_method = false;
} else {
current_block = new ExplicitBlock (current_block, loc, Location.Null);
error_code = 1525;
}
- if (expecting != null)
- Report.Error (error_code, lexer.Location, "{2} `{0}', expecting {1}",
- symbol, expecting, msg);
- else
+ if (string.IsNullOrEmpty (expecting))
Report.Error (error_code, lexer.Location, "{1} `{0}'", symbol, msg);
+ else
+ Report.Error (error_code, lexer.Location, "{2} `{0}', expecting {1}", symbol, expecting, msg);
}
string GetExpecting ()
case Token.CLOSE_BRACE:
return "}";
case Token.OPEN_BRACKET:
+ case Token.OPEN_BRACKET_EXPR:
return "[";
case Token.CLOSE_BRACKET:
return "]";