3 // cs-parser.jay: The Parser for the C# compiler
5 // Authors: Miguel de Icaza (miguel@gnu.org)
6 // Ravi Pratap (ravi@ximian.com)
8 // Licensed under the terms of the GNU GPL
10 // (C) 2001 Ximian, Inc (http://www.ximian.com)
11 // (C) 2004 Novell, Inc
14 // (1) Figure out why error productions dont work. `type-declaration' is a
15 // great spot to put an `error' because you can reproduce it with this input:
18 // Possible optimization:
19 // Run memory profiler with parsing only, and consider dropping
20 // arraylists where not needed. Some pieces can use linked lists.
28 using System.Collections;
33 public class CSharpParser {
34 NamespaceEntry current_namespace;
35 TypeContainer current_container;
36 TypeContainer current_class;
38 IIteratorContainer iterator_container;
41 /// Current block is used to add statements as we find
44 Block current_block, top_current_block;
46 Delegate current_delegate;
49 /// This is used by the unary_expression code to resolve
50 /// a name against a parameter.
52 Parameters current_local_parameters;
55 /// Using during property parsing to describe the implicit
56 /// value parameter that is passed to the "set" and "get"accesor
57 /// methods (properties and indexers).
59 Expression implicit_value_parameter_type;
60 Parameters indexer_parameters;
63 /// Used to determine if we are parsing the get/set pair
64 /// of an indexer or a property
69 /// An out-of-band stack.
78 static public int yacc_verbose_flag;
80 // Name of the file we are parsing
89 /// Temporary Xml documentation cache.
90 /// For enum types, we need one more temporary store.
93 string enumTypeComment;
95 /// Current attribute target
96 string current_attr_target;
98 /// assembly and module attribute definitions are enabled
99 bool global_attrs_enabled = true;
100 bool has_get, has_set;
105 %token NONE /* This token is never returned by our lexer */
106 %token ERROR // This is used not by the parser, but by the tokenizer.
110 *These are the C# keywords
197 /* C# keywords which are not really keywords */
203 /* C# single character operators/punctuation. */
204 %token OPEN_BRACE "{"
205 %token CLOSE_BRACE "}"
206 %token OPEN_BRACKET "["
207 %token CLOSE_BRACKET "]"
208 %token OPEN_PARENS "("
209 %token CLOSE_PARENS ")"
221 %token OP_GENERICS_LT "<"
223 %token OP_GENERICS_GT ">"
224 %token BITWISE_AND "&"
225 %token BITWISE_OR "|"
232 /* C# multi-character operators. */
233 %token DOUBLE_COLON "::"
236 %token OP_SHIFT_LEFT "<<"
237 %token OP_SHIFT_RIGHT ">>"
244 %token OP_MULT_ASSIGN "*="
245 %token OP_DIV_ASSIGN "/="
246 %token OP_MOD_ASSIGN "%="
247 %token OP_ADD_ASSIGN "+="
248 %token OP_SUB_ASSIGN "-="
249 %token OP_SHIFT_LEFT_ASSIGN "<<="
250 %token OP_SHIFT_RIGHT_ASSIGN ">>="
251 %token OP_AND_ASSIGN "&="
252 %token OP_XOR_ASSIGN "^="
253 %token OP_OR_ASSIGN "|="
257 %token LITERAL_INTEGER "int literal"
258 %token LITERAL_FLOAT "float literal"
259 %token LITERAL_DOUBLE "double literal"
260 %token LITERAL_DECIMAL "decimal literal"
261 %token LITERAL_CHARACTER "character literal"
262 %token LITERAL_STRING "string literal"
265 %token CLOSE_PARENS_CAST
266 %token CLOSE_PARENS_NO_CAST
267 %token CLOSE_PARENS_OPEN_PARENS
268 %token CLOSE_PARENS_MINUS
269 %token DEFAULT_OPEN_PARENS
270 %token GENERIC_DIMENSION
272 /* Add precedence rules to solve dangling else s/r conflict */
281 %left OP_SHIFT_LEFT OP_SHIFT_RIGHT
283 %left STAR DIV PERCENT
284 %right BANG CARRET UMINUS
285 %nonassoc OP_INC OP_DEC
287 %left OPEN_BRACKET OPEN_BRACE
291 %start compilation_unit
295 : outer_declarations opt_EOF
296 | outer_declarations global_attributes opt_EOF
297 | global_attributes opt_EOF
298 | opt_EOF /* allow empty files */
304 Lexer.check_incorrect_doc_comment ();
308 Lexer.check_incorrect_doc_comment ();
314 | outer_declarations outer_declaration
318 : extern_alias_directive
320 | namespace_member_declaration
323 extern_alias_directives
324 : extern_alias_directive
325 | extern_alias_directives extern_alias_directive;
327 extern_alias_directive
328 : EXTERN IDENTIFIER IDENTIFIER SEMICOLON
330 LocatedToken lt = (LocatedToken) $2;
333 Report.Error (1003, lt.Location, "'alias' expected");
334 } else if (RootContext.Version == LanguageVersion.ISO_1) {
335 Report.FeatureIsNotStandardized (lt.Location, "external alias");
337 lt = (LocatedToken) $3;
338 current_namespace.UsingExternalAlias (lt.Value, lt.Location);
345 | using_directives using_directive
349 : using_alias_directive
351 if (RootContext.Documentation != null)
352 Lexer.doc_state = XmlCommentState.Allowed;
354 | using_namespace_directive
356 if (RootContext.Documentation != null)
357 Lexer.doc_state = XmlCommentState.Allowed;
361 using_alias_directive
362 : USING IDENTIFIER ASSIGN
363 namespace_or_type_name SEMICOLON
365 LocatedToken lt = (LocatedToken) $2;
366 current_namespace.UsingAlias (lt.Value, (MemberName) $4, (Location) $1);
367 current_namespace.UsingFound = true;
370 CheckIdentifierToken (yyToken, GetLocation ($2));
374 using_namespace_directive
375 : USING namespace_name SEMICOLON
377 current_namespace.Using ((MemberName) $2, (Location) $1);
378 current_namespace.UsingFound = true;
383 // Strictly speaking, namespaces don't have attributes but
384 // we parse global attributes along with namespace declarations and then
387 namespace_declaration
388 : opt_attributes NAMESPACE namespace_or_type_name
390 MemberName name = (MemberName) $3;
393 Report.Error(1671, name.Location, "A namespace declaration cannot have modifiers or attributes");
396 if (name.TypeArguments != null)
397 syntax_error (lexer.Location, "namespace name expected");
399 current_namespace = new NamespaceEntry (
400 current_namespace, file, name.GetName (), name.Location);
402 namespace_body opt_semicolon
404 current_namespace = current_namespace.Parent;
419 : namespace_or_type_name {
420 MemberName name = (MemberName) $1;
422 if (name.TypeArguments != null)
423 syntax_error (lexer.Location, "namespace name expected");
432 if (RootContext.Documentation != null)
433 Lexer.doc_state = XmlCommentState.Allowed;
435 opt_extern_alias_directives
437 opt_namespace_member_declarations
446 opt_extern_alias_directives
448 | extern_alias_directives
451 opt_namespace_member_declarations
453 | namespace_member_declarations
456 namespace_member_declarations
457 : namespace_member_declaration
458 | namespace_member_declarations namespace_member_declaration
461 namespace_member_declaration
465 DeclSpace ds = (DeclSpace)$1;
467 if ((ds.ModFlags & (Modifiers.PRIVATE|Modifiers.PROTECTED)) != 0){
468 Report.Error (1527, ds.Location,
469 "Namespace elements cannot be explicitly declared as private, protected or protected internal");
472 current_namespace.DeclarationFound = true;
474 | namespace_declaration {
475 current_namespace.DeclarationFound = true;
478 | field_declaration {
479 Report.Error (116, ((MemberCore) $1).Location, "A namespace can only contain types and namespace declarations");
481 | method_declaration {
482 Report.Error (116, ((MemberCore) $1).Location, "A namespace can only contain types and namespace declarations");
489 | interface_declaration
491 | delegate_declaration
493 // Enable this when we have handled all errors, because this acts as a generic fallback
496 // Console.WriteLine ("Token=" + yyToken);
497 // Report.Error (1518, GetLocation ($1), "Expected class, struct, interface, enum or delegate");
509 CodeGen.Assembly.AddAttributes (((Attributes)$1).Attrs);
517 global_attrs_enabled = false;
522 global_attrs_enabled = false;
531 ArrayList sect = (ArrayList) $1;
533 if (global_attrs_enabled) {
534 if (current_attr_target == "module") {
535 CodeGen.Module.AddAttributes (sect);
537 } else if (current_attr_target != null && current_attr_target.Length > 0) {
538 CodeGen.Assembly.AddAttributes (sect);
541 $$ = new Attributes (sect);
544 if (RootContext.Documentation != null) {
545 Lexer.check_incorrect_doc_comment ();
547 XmlCommentState.Allowed;
551 $$ = new Attributes (sect);
553 current_attr_target = null;
555 | attribute_sections attribute_section
557 Attributes attrs = $1 as Attributes;
558 ArrayList sect = (ArrayList) $2;
560 if (global_attrs_enabled) {
561 if (current_attr_target == "module") {
562 CodeGen.Module.AddAttributes (sect);
564 } else if (current_attr_target == "assembly") {
565 CodeGen.Assembly.AddAttributes (sect);
569 attrs = new Attributes (sect);
571 attrs.AddAttributes (sect);
575 attrs = new Attributes (sect);
577 attrs.AddAttributes (sect);
580 current_attr_target = null;
585 : OPEN_BRACKET attribute_target_specifier attribute_list opt_comma CLOSE_BRACKET
589 | OPEN_BRACKET attribute_list opt_comma CLOSE_BRACKET
595 attribute_target_specifier
596 : attribute_target COLON
598 current_attr_target = (string)$1;
606 LocatedToken lt = (LocatedToken) $1;
607 CheckAttributeTarget (lt.Value, lt.Location);
608 $$ = lt.Value; // Location won't be required anymore.
610 | EVENT { $$ = "event"; }
611 | RETURN { $$ = "return"; }
617 ArrayList attrs = new ArrayList (4);
623 | attribute_list COMMA attribute
625 ArrayList attrs = (ArrayList) $1;
633 : attribute_name opt_attribute_arguments
635 MemberName mname = (MemberName) $1;
636 if (mname.IsGeneric) {
637 Report.Error (404, lexer.Location,
638 "'<' unexpected: attributes cannot be generic");
641 ArrayList arguments = (ArrayList) $2;
642 MemberName left = mname.Left;
643 string identifier = mname.Name;
645 Expression left_expr = left == null ? null : left.GetTypeExpression ();
647 if (current_attr_target == "assembly" || current_attr_target == "module")
648 // FIXME: supply "nameEscaped" parameter here.
649 $$ = new GlobalAttribute (current_class, current_attr_target,
650 left_expr, identifier, arguments, mname.Location, lexer.IsEscapedIdentifier (mname.Location));
652 $$ = new Attribute (current_attr_target, left_expr, identifier, arguments, mname.Location, lexer.IsEscapedIdentifier (mname.Location));
657 : namespace_or_type_name { /* reserved attribute name or identifier: 17.4 */ }
660 opt_attribute_arguments
661 : /* empty */ { $$ = null; }
662 | OPEN_PARENS attribute_arguments CLOSE_PARENS
670 : opt_positional_argument_list
675 ArrayList args = new ArrayList (4);
681 | positional_argument_list COMMA named_argument_list
683 ArrayList args = new ArrayList (4);
689 | named_argument_list
691 ArrayList args = new ArrayList (4);
700 opt_positional_argument_list
701 : /* empty */ { $$ = null; }
702 | positional_argument_list
705 positional_argument_list
708 ArrayList args = new ArrayList (4);
709 args.Add (new Argument ((Expression) $1, Argument.AType.Expression));
713 | positional_argument_list COMMA expression
715 ArrayList args = (ArrayList) $1;
716 args.Add (new Argument ((Expression) $3, Argument.AType.Expression));
725 ArrayList args = new ArrayList (4);
730 | named_argument_list COMMA named_argument
732 ArrayList args = (ArrayList) $1;
737 | named_argument_list COMMA expression
739 Report.Error (1016, ((Expression) $3).Location, "Named attribute argument expected");
745 : IDENTIFIER ASSIGN expression
747 // FIXME: keep location
748 $$ = new DictionaryEntry (
749 ((LocatedToken) $1).Value,
750 new Argument ((Expression) $3, Argument.AType.Expression));
756 : OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
759 opt_class_member_declarations
761 | class_member_declarations
764 class_member_declarations
765 : class_member_declaration
766 | class_member_declarations
767 class_member_declaration
770 class_member_declaration
771 : constant_declaration // done
772 | field_declaration // done
773 | method_declaration // done
774 | property_declaration // done
775 | event_declaration // done
776 | indexer_declaration // done
777 | operator_declaration // done
778 | constructor_declaration // done
779 | destructor_declaration // done
789 lexer.ConstraintsParsing = true;
793 MemberName name = MakeName ((MemberName) $6);
795 ClassPart part = PartialContainer.CreatePart (
796 current_namespace, current_class, name, (int) $2,
797 (Attributes) $1, Kind.Struct, (Location) $3);
799 current_container = part.PartialContainer;
800 current_class = part;
802 current_class = new Struct (
803 current_namespace, current_class, name, (int) $2,
806 current_container.AddClassOrStruct (current_class);
807 current_container = current_class;
808 RootContext.Tree.RecordDecl (current_namespace.NS, name, current_class);
812 opt_type_parameter_constraints_clauses
814 lexer.ConstraintsParsing = false;
817 current_class.Bases = (ArrayList) $8;
819 current_class.SetParameterInfo ((ArrayList) $9);
821 if (RootContext.Documentation != null)
822 current_class.DocComment = Lexer.consume_doc_comment ();
826 if (RootContext.Documentation != null)
827 Lexer.doc_state = XmlCommentState.Allowed;
831 $$ = pop_current_class ();
833 | opt_attributes opt_modifiers opt_partial STRUCT error {
834 CheckIdentifierToken (yyToken, GetLocation ($5));
841 if (RootContext.Documentation != null)
842 Lexer.doc_state = XmlCommentState.Allowed;
844 opt_struct_member_declarations CLOSE_BRACE
847 opt_struct_member_declarations
849 | struct_member_declarations
852 struct_member_declarations
853 : struct_member_declaration
854 | struct_member_declarations struct_member_declaration
857 struct_member_declaration
858 : constant_declaration
861 | property_declaration
863 | indexer_declaration
864 | operator_declaration
865 | constructor_declaration
869 * This is only included so we can flag error 575:
870 * destructors only allowed on class types
872 | destructor_declaration
883 int modflags = (int) $2;
884 foreach (VariableDeclaration constant in (ArrayList) $5){
885 Location l = constant.Location;
886 if ((modflags & Modifiers.STATIC) != 0) {
887 Report.Error (504, l, "The constant `{0}' cannot be marked static", current_container.GetSignatureForError () + '.' + (string) constant.identifier);
891 Const c = new Const (
892 current_class, (Expression) $4, (string) constant.identifier,
893 (Expression) constant.expression_or_array_initializer, modflags,
896 if (RootContext.Documentation != null) {
897 c.DocComment = Lexer.consume_doc_comment ();
898 Lexer.doc_state = XmlCommentState.Allowed;
900 current_container.AddConstant (c);
906 : constant_declarator
908 ArrayList constants = new ArrayList (4);
913 | constant_declarators COMMA constant_declarator
916 ArrayList constants = (ArrayList) $1;
923 : IDENTIFIER ASSIGN constant_expression
925 $$ = new VariableDeclaration ((LocatedToken) $1, $3);
929 // A const field requires a value to be provided
930 Report.Error (145, ((LocatedToken) $1).Location, "A const field requires a value to be provided");
942 Expression type = (Expression) $3;
945 foreach (VariableDeclaration var in (ArrayList) $4){
946 Field field = new Field (current_class, type, mod, var.identifier,
947 var.expression_or_array_initializer,
948 (Attributes) $1, var.Location);
950 if (RootContext.Documentation != null) {
951 field.DocComment = Lexer.consume_doc_comment ();
952 Lexer.doc_state = XmlCommentState.Allowed;
954 current_container.AddField (field);
955 $$ = field; // FIXME: might be better if it points to the top item
962 fixed_variable_declarators
965 Expression type = (Expression) $4;
968 foreach (VariableDeclaration var in (ArrayList) $5) {
969 FixedField field = new FixedField (current_class, type, mod, var.identifier,
970 (Expression)var.expression_or_array_initializer, (Attributes) $1, var.Location);
972 if (RootContext.Documentation != null) {
973 field.DocComment = Lexer.consume_doc_comment ();
974 Lexer.doc_state = XmlCommentState.Allowed;
976 current_container.AddField (field);
977 $$ = field; // FIXME: might be better if it points to the top item
985 Report.Error (670, (Location) $3, "Fields cannot have void type");
989 fixed_variable_declarators
990 : fixed_variable_declarator
992 ArrayList decl = new ArrayList (2);
996 | fixed_variable_declarators COMMA fixed_variable_declarator
998 ArrayList decls = (ArrayList) $1;
1004 fixed_variable_declarator
1005 : IDENTIFIER OPEN_BRACKET expression CLOSE_BRACKET
1007 $$ = new VariableDeclaration ((LocatedToken) $1, $3);
1009 | IDENTIFIER OPEN_BRACKET CLOSE_BRACKET
1011 Report.Error (443, lexer.Location, "Value or constant expected");
1012 $$ = new VariableDeclaration ((LocatedToken) $1, null);
1016 variable_declarators
1017 : variable_declarator
1019 ArrayList decl = new ArrayList (4);
1024 | variable_declarators COMMA variable_declarator
1026 ArrayList decls = (ArrayList) $1;
1033 : IDENTIFIER ASSIGN variable_initializer
1035 $$ = new VariableDeclaration ((LocatedToken) $1, $3);
1039 $$ = new VariableDeclaration ((LocatedToken) $1, null);
1041 | IDENTIFIER OPEN_BRACKET opt_expression CLOSE_BRACKET
1043 Report.Error (650, ((LocatedToken) $1).Location, "Syntax error, bad array declarator. To declare a managed array the rank specifier precedes the variable's identifier. " +
1044 "To declare a fixed size buffer field, use the fixed keyword before the field type");
1049 variable_initializer
1058 | STACKALLOC type OPEN_BRACKET expression CLOSE_BRACKET
1060 $$ = new StackAlloc ((Expression) $2, (Expression) $4, (Location) $1);
1064 Report.Error (1575, (Location) $1, "A stackalloc expression requires [] after type");
1071 iterator_container = (IIteratorContainer) $1;
1072 if (RootContext.Documentation != null)
1073 Lexer.doc_state = XmlCommentState.NotAllowed;
1077 Method method = (Method) $1;
1078 method.Block = (ToplevelBlock) $3;
1079 current_container.AddMethod (method);
1081 current_local_parameters = null;
1082 iterator_container = null;
1084 if (RootContext.Documentation != null)
1085 Lexer.doc_state = XmlCommentState.Allowed;
1098 Report.Error (1585, lexer.Location,
1099 "Member modifier `{0}' must precede the member type and name",
1100 Modifiers.Name (i));
1111 type namespace_or_type_name
1112 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1114 lexer.ConstraintsParsing = true;
1116 opt_type_parameter_constraints_clauses
1118 lexer.ConstraintsParsing = false;
1120 MemberName name = (MemberName) $4;
1122 if ($9 != null && name.TypeArguments == null)
1123 Report.Error (80, lexer.Location,
1124 "Constraints are not allowed on non-generic declarations");
1128 GenericMethod generic = null;
1129 if (name.TypeArguments != null) {
1130 generic = new GenericMethod (current_namespace, current_class, name,
1131 (Expression) $3, (Parameters) $6);
1133 generic.SetParameterInfo ((ArrayList) $9);
1136 method = new Method (current_class, generic, (Expression) $3, (int) $2, false,
1137 name, (Parameters) $6, (Attributes) $1);
1139 current_local_parameters = (Parameters) $6;
1141 if (RootContext.Documentation != null)
1142 method.DocComment = Lexer.consume_doc_comment ();
1148 VOID namespace_or_type_name
1149 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1151 lexer.ConstraintsParsing = true;
1153 opt_type_parameter_constraints_clauses
1155 lexer.ConstraintsParsing = false;
1157 MemberName name = (MemberName) $4;
1159 if ($9 != null && name.TypeArguments == null)
1160 Report.Error (80, lexer.Location,
1161 "Constraints are not allowed on non-generic declarations");
1164 GenericMethod generic = null;
1165 if (name.TypeArguments != null) {
1166 generic = new GenericMethod (current_namespace, current_class, name,
1167 TypeManager.system_void_expr, (Parameters) $6);
1169 generic.SetParameterInfo ((ArrayList) $9);
1172 method = new Method (current_class, generic, TypeManager.system_void_expr,
1173 (int) $2, false, name, (Parameters) $6, (Attributes) $1);
1175 current_local_parameters = (Parameters) $6;
1177 if (RootContext.Documentation != null)
1178 method.DocComment = Lexer.consume_doc_comment ();
1185 modifiers namespace_or_type_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1187 MemberName name = (MemberName) $5;
1188 Report.Error (1585, name.Location,
1189 "Member modifier `{0}' must precede the member type and name", Modifiers.Name ((int) $4));
1191 Method method = new Method (current_class, null, TypeManager.system_void_expr,
1192 0, false, name, (Parameters) $6, (Attributes) $1);
1194 current_local_parameters = (Parameters) $6;
1196 if (RootContext.Documentation != null)
1197 method.DocComment = Lexer.consume_doc_comment ();
1205 | SEMICOLON { $$ = null; }
1208 opt_formal_parameter_list
1209 : /* empty */ { $$ = Parameters.EmptyReadOnlyParameters; }
1210 | formal_parameter_list
1213 formal_parameter_list
1216 ArrayList pars_list = (ArrayList) $1;
1218 Parameter [] pars = new Parameter [pars_list.Count];
1219 pars_list.CopyTo (pars);
1221 $$ = new Parameters (pars, null);
1223 | fixed_parameters COMMA parameter_array
1225 ArrayList pars_list = (ArrayList) $1;
1227 Parameter [] pars = new Parameter [pars_list.Count];
1228 pars_list.CopyTo (pars);
1230 $$ = new Parameters (pars, (Parameter) $3);
1232 | fixed_parameters COMMA ARGLIST
1234 ArrayList pars_list = (ArrayList) $1;
1236 Parameter [] pars = new Parameter [pars_list.Count];
1237 pars_list.CopyTo (pars);
1239 $$ = new Parameters (pars, true);
1241 | parameter_array COMMA fixed_parameters
1244 Report.Error (231, ((Parameter) $1).Location, "A params parameter must be the last parameter in a formal parameter list");
1247 | ARGLIST COMMA fixed_parameters
1249 Report.Error (257, (Location) $1, "An __arglist parameter must be the last parameter in a formal parameter list");
1254 $$ = new Parameters (null, (Parameter) $1);
1258 $$ = new Parameters (null, true);
1265 ArrayList pars = new ArrayList (4);
1270 | fixed_parameters COMMA fixed_parameter
1272 ArrayList pars = (ArrayList) $1;
1281 opt_parameter_modifier
1285 LocatedToken lt = (LocatedToken) $4;
1286 $$ = new Parameter ((Expression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1289 opt_parameter_modifier
1291 IDENTIFIER OPEN_BRACKET CLOSE_BRACKET
1293 LocatedToken lt = (LocatedToken) $4;
1294 Report.Error (1552, lt.Location, "Array type specifier, [], must appear before parameter name");
1298 opt_parameter_modifier
1301 Report.Error (1001, GetLocation ($3), "Identifier expected");
1305 opt_parameter_modifier
1308 CheckIdentifierToken (yyToken, GetLocation ($4));
1312 opt_parameter_modifier
1318 LocatedToken lt = (LocatedToken) $4;
1319 Report.Error (241, lt.Location, "Default parameter specifiers are not permitted");
1324 opt_parameter_modifier
1325 : /* empty */ { $$ = Parameter.Modifier.NONE; }
1326 | parameter_modifier
1330 : REF { $$ = Parameter.Modifier.REF | Parameter.Modifier.ISBYREF; }
1331 | OUT { $$ = Parameter.Modifier.OUT | Parameter.Modifier.ISBYREF; }
1335 : opt_attributes PARAMS type IDENTIFIER
1337 LocatedToken lt = (LocatedToken) $4;
1338 $$ = new Parameter ((Expression) $3, lt.Value, Parameter.Modifier.PARAMS, (Attributes) $1, lt.Location);
1339 note ("type must be a single-dimension array type");
1341 | opt_attributes PARAMS parameter_modifier type IDENTIFIER
1343 Report.Error (1611, (Location) $2, "The params parameter cannot be declared as ref or out");
1346 | opt_attributes PARAMS type error {
1347 CheckIdentifierToken (yyToken, GetLocation ($4));
1352 property_declaration
1356 namespace_or_type_name
1358 if (RootContext.Documentation != null)
1359 tmpComment = Lexer.consume_doc_comment ();
1363 implicit_value_parameter_type = (Expression) $3;
1365 lexer.PropertyParsing = true;
1367 accessor_declarations
1369 lexer.PropertyParsing = false;
1370 has_get = has_set = false;
1378 Pair pair = (Pair) $8;
1379 Accessor get_block = (Accessor) pair.First;
1380 Accessor set_block = (Accessor) pair.Second;
1382 MemberName name = (MemberName) $4;
1384 if (name.TypeArguments != null)
1385 syntax_error (lexer.Location, "a property can't have type arguments");
1387 prop = new Property (current_class, (Expression) $3, (int) $2, false,
1388 name, (Attributes) $1, get_block, set_block);
1390 current_container.AddProperty (prop);
1391 implicit_value_parameter_type = null;
1393 if (RootContext.Documentation != null)
1394 prop.DocComment = ConsumeStoredComment ();
1399 accessor_declarations
1400 : get_accessor_declaration
1402 $$ = new Pair ($1, null);
1404 | get_accessor_declaration accessor_declarations
1406 Pair pair = (Pair) $2;
1410 | set_accessor_declaration
1412 $$ = new Pair (null, $1);
1414 | set_accessor_declaration accessor_declarations
1416 Pair pair = (Pair) $2;
1422 Report.Error (1014, GetLocation ($1), "A get or set accessor expected");
1427 get_accessor_declaration
1428 : opt_attributes opt_modifiers GET
1430 // If this is not the case, then current_local_parameters has already
1431 // been set in indexer_declaration
1432 if (parsing_indexer == false)
1433 current_local_parameters = null;
1435 current_local_parameters = indexer_parameters;
1436 lexer.PropertyParsing = false;
1438 iterator_container = SimpleIteratorContainer.GetSimple ();
1443 Report.Error (1007, (Location) $3, "Property accessor already defined");
1446 Accessor accessor = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, (Location) $3);
1448 current_local_parameters = null;
1449 lexer.PropertyParsing = true;
1451 if (SimpleIteratorContainer.Simple.Yields)
1452 accessor.SetYields ();
1454 iterator_container = null;
1456 if (RootContext.Documentation != null)
1457 if (Lexer.doc_state == XmlCommentState.Error)
1458 Lexer.doc_state = XmlCommentState.NotAllowed;
1464 set_accessor_declaration
1465 : opt_attributes opt_modifiers SET
1468 Parameter implicit_value_parameter = new Parameter (
1469 implicit_value_parameter_type, "value",
1470 Parameter.Modifier.NONE, null, (Location) $3);
1472 if (parsing_indexer == false) {
1473 args = new Parameter [1];
1474 args [0] = implicit_value_parameter;
1475 current_local_parameters = new Parameters (args, null);
1477 Parameter [] fpars = indexer_parameters.FixedParameters;
1480 int count = fpars.Length;
1482 args = new Parameter [count + 1];
1483 fpars.CopyTo (args, 0);
1484 args [count] = implicit_value_parameter;
1487 current_local_parameters = new Parameters (
1488 args, indexer_parameters.ArrayParameter);
1491 lexer.PropertyParsing = false;
1493 iterator_container = SimpleIteratorContainer.GetSimple ();
1498 Report.Error (1007, ((LocatedToken) $3).Location, "Property accessor already defined");
1501 Accessor accessor = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, (Location) $3);
1503 current_local_parameters = null;
1504 lexer.PropertyParsing = true;
1506 if (SimpleIteratorContainer.Simple.Yields)
1507 accessor.SetYields ();
1509 iterator_container = null;
1511 if (RootContext.Documentation != null
1512 && Lexer.doc_state == XmlCommentState.Error)
1513 Lexer.doc_state = XmlCommentState.NotAllowed;
1521 | SEMICOLON { $$ = null; }
1524 interface_declaration
1530 lexer.ConstraintsParsing = true;
1534 MemberName name = MakeName ((MemberName) $6);
1537 ClassPart part = PartialContainer.CreatePart (
1538 current_namespace, current_class, name, (int) $2,
1539 (Attributes) $1, Kind.Interface, (Location) $3);
1541 current_container = part.PartialContainer;
1542 current_class = part;
1544 current_class = new Interface (
1545 current_namespace, current_class, name, (int) $2,
1548 current_container.AddInterface (current_class);
1549 current_container = current_class;
1550 RootContext.Tree.RecordDecl (current_namespace.NS, name, current_class);
1554 opt_type_parameter_constraints_clauses
1556 lexer.ConstraintsParsing = false;
1559 current_class.Bases = (ArrayList) $8;
1561 current_class.SetParameterInfo ((ArrayList) $9);
1563 if (RootContext.Documentation != null) {
1564 current_class.DocComment = Lexer.consume_doc_comment ();
1565 Lexer.doc_state = XmlCommentState.Allowed;
1570 if (RootContext.Documentation != null)
1571 Lexer.doc_state = XmlCommentState.Allowed;
1575 $$ = pop_current_class ();
1577 | opt_attributes opt_modifiers opt_partial INTERFACE error {
1578 CheckIdentifierToken (yyToken, GetLocation ($5));
1584 opt_interface_member_declarations
1588 opt_interface_member_declarations
1590 | interface_member_declarations
1593 interface_member_declarations
1594 : interface_member_declaration
1595 | interface_member_declarations interface_member_declaration
1598 interface_member_declaration
1599 : interface_method_declaration
1604 Method m = (Method) $1;
1606 if (m.IsExplicitImpl)
1607 Report.Error (541, m.Location, "`{0}': explicit interface declaration can only be declared in a class or struct",
1608 m.GetSignatureForError ());
1610 current_container.AddMethod (m);
1612 if (RootContext.Documentation != null)
1613 Lexer.doc_state = XmlCommentState.Allowed;
1615 | interface_property_declaration
1620 Property p = (Property) $1;
1622 if (p.IsExplicitImpl)
1623 Report.Error (541, p.Location, "`{0}': explicit interface declaration can only be declared in a class or struct",
1624 p.GetSignatureForError ());
1626 current_container.AddProperty (p);
1628 if (RootContext.Documentation != null)
1629 Lexer.doc_state = XmlCommentState.Allowed;
1631 | interface_event_declaration
1634 Event e = (Event) $1;
1636 if (e.IsExplicitImpl)
1637 Report.Error (541, e.Location, "`{0}': explicit interface declaration can only be declared in a class or struct",
1638 e.GetSignatureForError ());
1640 current_container.AddEvent (e);
1643 if (RootContext.Documentation != null)
1644 Lexer.doc_state = XmlCommentState.Allowed;
1646 | interface_indexer_declaration
1651 Indexer i = (Indexer) $1;
1653 if (i.IsExplicitImpl)
1654 Report.Error (541, i.Location, "`{0}': explicit interface declaration can only be declared in a class or struct",
1655 i.GetSignatureForError ());
1657 current_container.AddIndexer (i);
1659 if (RootContext.Documentation != null)
1660 Lexer.doc_state = XmlCommentState.Allowed;
1662 | delegate_declaration
1665 Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
1666 ((MemberCore)$1).GetSignatureForError ());
1672 Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
1673 ((MemberCore)$1).GetSignatureForError ());
1676 | struct_declaration
1679 Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
1680 ((MemberCore)$1).GetSignatureForError ());
1686 Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
1687 ((MemberCore)$1).GetSignatureForError ());
1690 | interface_declaration
1693 Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
1694 ((MemberCore)$1).GetSignatureForError ());
1697 | constant_declaration
1699 Report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
1707 val = Modifiers.Check (Modifiers.NEW | Modifiers.UNSAFE, val, 0, GetLocation ($1));
1712 interface_method_declaration_body
1715 lexer.ConstraintsParsing = false;
1717 opt_statement_list CLOSE_BRACE
1719 Report.Error (531, lexer.Location,
1720 "'{0}': interface members cannot have a definition", ((MemberName) $-1).ToString ());
1726 interface_method_declaration
1727 : opt_attributes opt_new type namespace_or_type_name
1728 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1730 lexer.ConstraintsParsing = true;
1732 opt_type_parameter_constraints_clauses
1734 // Refer to the name as $-1 in interface_method_declaration_body
1737 interface_method_declaration_body
1739 lexer.ConstraintsParsing = false;
1741 MemberName name = (MemberName) $4;
1743 if ($9 != null && name.TypeArguments == null)
1744 Report.Error (80, lexer.Location,
1745 "Constraints are not allowed on non-generic declarations");
1747 GenericMethod generic = null;
1748 if (name.TypeArguments != null) {
1749 generic = new GenericMethod (current_namespace, current_class, name,
1750 (Expression) $3, (Parameters) $6);
1752 generic.SetParameterInfo ((ArrayList) $9);
1755 $$ = new Method (current_class, generic, (Expression) $3, (int) $2, true, name,
1756 (Parameters) $6, (Attributes) $1);
1757 if (RootContext.Documentation != null)
1758 ((Method) $$).DocComment = Lexer.consume_doc_comment ();
1760 | opt_attributes opt_new VOID namespace_or_type_name
1761 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1763 lexer.ConstraintsParsing = true;
1765 opt_type_parameter_constraints_clauses
1769 interface_method_declaration_body
1771 lexer.ConstraintsParsing = false;
1773 MemberName name = (MemberName) $4;
1775 if ($9 != null && name.TypeArguments == null)
1776 Report.Error (80, lexer.Location,
1777 "Constraints are not allowed on non-generic declarations");
1779 GenericMethod generic = null;
1780 if (name.TypeArguments != null) {
1781 generic = new GenericMethod (current_namespace, current_class, name,
1782 TypeManager.system_void_expr, (Parameters) $6);
1784 generic.SetParameterInfo ((ArrayList) $9);
1787 $$ = new Method (current_class, generic, TypeManager.system_void_expr, (int) $2,
1788 true, name, (Parameters) $6, (Attributes) $1);
1789 if (RootContext.Documentation != null)
1790 ((Method) $$).DocComment = Lexer.consume_doc_comment ();
1794 interface_property_declaration
1799 { lexer.PropertyParsing = true; }
1800 accessor_declarations
1802 has_get = has_set = false;
1803 lexer.PropertyParsing = false;
1807 LocatedToken lt = (LocatedToken) $4;
1808 MemberName name = new MemberName (lt.Value, lt.Location);
1810 if ($3 == TypeManager.system_void_expr) {
1811 Report.Error (547, lt.Location, "`{0}': property or indexer cannot have void type", lt.Value);
1817 p = new Property (current_class, (Expression) $3, (int) $2, true,
1818 name, (Attributes) $1,
1821 Report.Error (548, p.Location, "`{0}': property or indexer must have at least one accessor", p.GetSignatureForError ());
1825 Pair pair = (Pair) $7;
1826 p = new Property (current_class, (Expression) $3, (int) $2, true,
1827 name, (Attributes) $1,
1828 (Accessor)pair.First, (Accessor)pair.Second);
1830 if (pair.First != null && ((Accessor)(pair.First)).Block != null) {
1831 Report.Error (531, p.Location, "`{0}.get': interface members cannot have a definition", p.GetSignatureForError ());
1836 if (pair.Second != null && ((Accessor)(pair.Second)).Block != null) {
1837 Report.Error (531, p.Location, "`{0}.set': interface members cannot have a definition", p.GetSignatureForError ());
1842 if (RootContext.Documentation != null)
1843 p.DocComment = Lexer.consume_doc_comment ();
1850 CheckIdentifierToken (yyToken, GetLocation ($4));
1856 interface_event_declaration
1857 : opt_attributes opt_new EVENT type IDENTIFIER SEMICOLON
1859 LocatedToken lt = (LocatedToken) $5;
1860 $$ = new EventField (current_class, (Expression) $4, (int) $2, true,
1861 new MemberName (lt.Value, lt.Location), null,
1863 if (RootContext.Documentation != null)
1864 ((EventField) $$).DocComment = Lexer.consume_doc_comment ();
1866 | opt_attributes opt_new EVENT type error {
1867 CheckIdentifierToken (yyToken, GetLocation ($5));
1870 | opt_attributes opt_new EVENT type IDENTIFIER ASSIGN {
1871 LocatedToken lt = (LocatedToken) $5;
1872 Report.Error (68, lt.Location, "`{0}.{1}': event in interface cannot have initializer", current_container.Name, lt.Value);
1875 | opt_attributes opt_new EVENT type IDENTIFIER OPEN_BRACE
1877 lexer.EventParsing = true;
1879 event_accessor_declarations
1881 lexer.EventParsing = false;
1884 Report.Error (69, (Location) $3, "Event in interface cannot have add or remove accessors");
1889 interface_indexer_declaration
1890 : opt_attributes opt_new type THIS
1891 OPEN_BRACKET formal_parameter_list CLOSE_BRACKET
1893 { lexer.PropertyParsing = true; }
1894 accessor_declarations
1896 has_get = has_set = false;
1897 lexer.PropertyParsing = false;
1903 i = new Indexer (current_class, (Expression) $3,
1904 new MemberName (TypeContainer.DefaultIndexerName, (Location) $4),
1905 (int) $2, true, (Parameters) $6, (Attributes) $1,
1908 Report.Error (548, i.Location, "`{0}': property or indexer must have at least one accessor", i.GetSignatureForError ());
1912 Pair pair = (Pair) $10;
1913 i = new Indexer (current_class, (Expression) $3,
1914 new MemberName (TypeContainer.DefaultIndexerName, (Location) $4),
1915 (int) $2, true, (Parameters) $6, (Attributes) $1,
1916 (Accessor)pair.First, (Accessor)pair.Second);
1918 if (pair.First != null && ((Accessor)(pair.First)).Block != null) {
1919 Report.Error (531, i.Location, "`{0}.get': interface members cannot have a definition", i.GetSignatureForError ());
1924 if (pair.Second != null && ((Accessor)(pair.Second)).Block != null) {
1925 Report.Error (531, i.Location, "`{0}.set': interface members cannot have a definition", i.GetSignatureForError ());
1930 if (RootContext.Documentation != null)
1931 i.DocComment = ConsumeStoredComment ();
1937 operator_declaration
1938 : opt_attributes opt_modifiers operator_declarator
1940 iterator_container = SimpleIteratorContainer.GetSimple ();
1947 OperatorDeclaration decl = (OperatorDeclaration) $3;
1949 Parameter [] param_list = new Parameter [decl.arg2type != null ? 2 : 1];
1951 param_list[0] = new Parameter (decl.arg1type, decl.arg1name, Parameter.Modifier.NONE, null, decl.location);
1952 if (decl.arg2type != null)
1953 param_list[1] = new Parameter (decl.arg2type, decl.arg2name, Parameter.Modifier.NONE, null, decl.location);
1955 Operator op = new Operator (
1956 current_class, decl.optype, decl.ret_type, (int) $2,
1957 new Parameters (param_list, null),
1958 (ToplevelBlock) $5, (Attributes) $1, decl.location);
1960 if (RootContext.Documentation != null) {
1961 op.DocComment = tmpComment;
1962 Lexer.doc_state = XmlCommentState.Allowed;
1965 if (SimpleIteratorContainer.Simple.Yields)
1968 // Note again, checking is done in semantic analysis
1969 current_container.AddOperator (op);
1971 current_local_parameters = null;
1972 iterator_container = null;
1978 | SEMICOLON { $$ = null; }
1981 : type OPERATOR overloadable_operator
1982 OPEN_PARENS type IDENTIFIER CLOSE_PARENS
1984 LocatedToken lt = (LocatedToken) $6;
1985 Operator.OpType op = (Operator.OpType) $3;
1986 CheckUnaryOperator (op, lt.Location);
1988 if (op == Operator.OpType.Addition)
1989 op = Operator.OpType.UnaryPlus;
1991 if (op == Operator.OpType.Subtraction)
1992 op = Operator.OpType.UnaryNegation;
1994 Parameter [] pars = new Parameter [1];
1995 Expression type = (Expression) $5;
1997 pars [0] = new Parameter (type, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
1999 current_local_parameters = new Parameters (pars, null);
2001 if (RootContext.Documentation != null) {
2002 tmpComment = Lexer.consume_doc_comment ();
2003 Lexer.doc_state = XmlCommentState.NotAllowed;
2006 $$ = new OperatorDeclaration (op, (Expression) $1, type, lt.Value,
2007 null, null, (Location) $2);
2009 | type OPERATOR overloadable_operator
2011 type IDENTIFIER COMMA
2015 LocatedToken ltParam1 = (LocatedToken) $6;
2016 LocatedToken ltParam2 = (LocatedToken) $9;
2017 CheckBinaryOperator ((Operator.OpType) $3, (Location) $2);
2019 Parameter [] pars = new Parameter [2];
2021 Expression typeL = (Expression) $5;
2022 Expression typeR = (Expression) $8;
2024 pars [0] = new Parameter (typeL, ltParam1.Value, Parameter.Modifier.NONE, null, ltParam1.Location);
2025 pars [1] = new Parameter (typeR, ltParam2.Value, Parameter.Modifier.NONE, null, ltParam2.Location);
2027 current_local_parameters = new Parameters (pars, null);
2029 if (RootContext.Documentation != null) {
2030 tmpComment = Lexer.consume_doc_comment ();
2031 Lexer.doc_state = XmlCommentState.NotAllowed;
2034 $$ = new OperatorDeclaration ((Operator.OpType) $3, (Expression) $1,
2035 typeL, ltParam1.Value,
2036 typeR, ltParam2.Value, (Location) $2);
2038 | conversion_operator_declarator
2039 | type OPERATOR overloadable_operator
2041 type IDENTIFIER COMMA
2042 type IDENTIFIER COMMA
2046 Report.Error (1534, (Location) $2, "Overloaded binary operator `{0}' takes two parameters",
2047 Operator.GetName ((Operator.OpType) $3));
2050 | type OPERATOR overloadable_operator
2051 OPEN_PARENS CLOSE_PARENS
2053 Report.Error (1535, (Location) $2, "Overloaded unary operator `{0}' takes one parameter",
2054 Operator.GetName ((Operator.OpType) $3));
2059 overloadable_operator
2061 : BANG { $$ = Operator.OpType.LogicalNot; }
2062 | TILDE { $$ = Operator.OpType.OnesComplement; }
2063 | OP_INC { $$ = Operator.OpType.Increment; }
2064 | OP_DEC { $$ = Operator.OpType.Decrement; }
2065 | TRUE { $$ = Operator.OpType.True; }
2066 | FALSE { $$ = Operator.OpType.False; }
2067 // Unary and binary:
2068 | PLUS { $$ = Operator.OpType.Addition; }
2069 | MINUS { $$ = Operator.OpType.Subtraction; }
2071 | STAR { $$ = Operator.OpType.Multiply; }
2072 | DIV { $$ = Operator.OpType.Division; }
2073 | PERCENT { $$ = Operator.OpType.Modulus; }
2074 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
2075 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
2076 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
2077 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
2078 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
2079 | OP_EQ { $$ = Operator.OpType.Equality; }
2080 | OP_NE { $$ = Operator.OpType.Inequality; }
2081 | OP_GT { $$ = Operator.OpType.GreaterThan; }
2082 | OP_LT { $$ = Operator.OpType.LessThan; }
2083 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
2084 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
2087 conversion_operator_declarator
2088 : IMPLICIT OPERATOR type OPEN_PARENS type IDENTIFIER CLOSE_PARENS
2090 LocatedToken lt = (LocatedToken) $6;
2091 Parameter [] pars = new Parameter [1];
2093 pars [0] = new Parameter ((Expression) $5, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
2095 current_local_parameters = new Parameters (pars, null);
2097 if (RootContext.Documentation != null) {
2098 tmpComment = Lexer.consume_doc_comment ();
2099 Lexer.doc_state = XmlCommentState.NotAllowed;
2102 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (Expression) $3, (Expression) $5, lt.Value,
2103 null, null, (Location) $2);
2105 | EXPLICIT OPERATOR type OPEN_PARENS type IDENTIFIER CLOSE_PARENS
2107 LocatedToken lt = (LocatedToken) $6;
2108 Parameter [] pars = new Parameter [1];
2110 pars [0] = new Parameter ((Expression) $5, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
2112 current_local_parameters = new Parameters (pars, null);
2114 if (RootContext.Documentation != null) {
2115 tmpComment = Lexer.consume_doc_comment ();
2116 Lexer.doc_state = XmlCommentState.NotAllowed;
2119 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (Expression) $3, (Expression) $5, lt.Value,
2120 null, null, (Location) $2);
2124 syntax_error ((Location) $1, "'operator' expected");
2128 syntax_error ((Location) $1, "'operator' expected");
2132 constructor_declaration
2135 constructor_declarator
2138 Constructor c = (Constructor) $3;
2139 c.Block = (ToplevelBlock) $4;
2140 c.OptAttributes = (Attributes) $1;
2141 c.ModFlags = (int) $2;
2143 if (RootContext.Documentation != null)
2144 c.DocComment = ConsumeStoredComment ();
2146 if (c.Name == current_container.Basename){
2147 if ((c.ModFlags & Modifiers.STATIC) != 0){
2148 if ((c.ModFlags & Modifiers.Accessibility) != 0){
2149 Report.Error (515, c.Location,
2150 "`{0}': access modifiers are not allowed on static constructors",
2151 c.GetSignatureForError ());
2154 c.ModFlags = Modifiers.Check (Constructor.AllowedModifiers, (int) $2, Modifiers.PRIVATE, c.Location);
2156 if (c.Initializer != null){
2157 Report.Error (514, c.Location,
2158 "`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
2159 c.GetSignatureForError ());
2162 if (!c.Parameters.Empty){
2163 Report.Error (132, c.Location,
2164 "`{0}': The static constructor must be parameterless", c.GetSignatureForError ());
2167 c.ModFlags = Modifiers.Check (Constructor.AllowedModifiers, (int) $2, Modifiers.PRIVATE, c.Location);
2170 // We let another layer check the validity of the constructor.
2171 //Console.WriteLine ("{0} and {1}", c.Name, current_container.Basename);
2174 current_container.AddConstructor (c);
2176 current_local_parameters = null;
2177 if (RootContext.Documentation != null)
2178 Lexer.doc_state = XmlCommentState.Allowed;
2182 constructor_declarator
2185 if (RootContext.Documentation != null) {
2186 tmpComment = Lexer.consume_doc_comment ();
2187 Lexer.doc_state = XmlCommentState.Allowed;
2190 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2192 current_local_parameters = (Parameters) $4;
2194 opt_constructor_initializer
2196 LocatedToken lt = (LocatedToken) $1;
2197 $$ = new Constructor (current_class, lt.Value, 0, (Parameters) $4,
2198 (ConstructorInitializer) $7, lt.Location);
2204 | SEMICOLON { $$ = null; }
2207 opt_constructor_initializer
2208 : /* empty */ { $$ = null; }
2209 | constructor_initializer
2212 constructor_initializer
2213 : COLON BASE OPEN_PARENS opt_argument_list CLOSE_PARENS
2215 $$ = new ConstructorBaseInitializer ((ArrayList) $4, (Location) $2);
2217 | COLON THIS OPEN_PARENS opt_argument_list CLOSE_PARENS
2219 $$ = new ConstructorThisInitializer ((ArrayList) $4, (Location) $2);
2222 Report.Error (1018, (Location) $1, "Keyword this or base expected");
2228 : /* EMPTY */ { $$ = 0; }
2229 | UNSAFE { $$ = Modifiers.UNSAFE; }
2230 | EXTERN { $$ = Modifiers.EXTERN; }
2233 destructor_declaration
2234 : opt_attributes opt_finalizer TILDE
2236 if (RootContext.Documentation != null) {
2237 tmpComment = Lexer.consume_doc_comment ();
2238 Lexer.doc_state = XmlCommentState.NotAllowed;
2241 IDENTIFIER OPEN_PARENS CLOSE_PARENS block
2243 LocatedToken lt = (LocatedToken) $5;
2244 if (lt.Value != current_container.MemberName.Name){
2245 Report.Error (574, lt.Location, "Name of destructor must match name of class");
2246 } else if (current_container.Kind != Kind.Class){
2247 Report.Error (575, lt.Location, "Only class types can contain destructor");
2249 Location l = lt.Location;
2252 if (!RootContext.StdLib && current_container.Name == "System.Object")
2253 m |= Modifiers.PROTECTED | Modifiers.VIRTUAL;
2255 m |= Modifiers.PROTECTED | Modifiers.OVERRIDE;
2257 Method d = new Destructor (
2258 current_class, TypeManager.system_void_expr, m, "Finalize",
2259 new Parameters (null, null), (Attributes) $1, l);
2260 if (RootContext.Documentation != null)
2261 d.DocComment = ConsumeStoredComment ();
2263 d.Block = (ToplevelBlock) $8;
2264 current_container.AddMethod (d);
2272 EVENT type variable_declarators SEMICOLON
2274 foreach (VariableDeclaration var in (ArrayList) $5) {
2276 MemberName name = new MemberName (var.identifier,
2279 Event e = new EventField (
2280 current_class, (Expression) $4, (int) $2, false, name,
2281 var.expression_or_array_initializer, (Attributes) $1);
2283 current_container.AddEvent (e);
2285 if (RootContext.Documentation != null) {
2286 e.DocComment = Lexer.consume_doc_comment ();
2287 Lexer.doc_state = XmlCommentState.Allowed;
2293 EVENT type namespace_or_type_name
2296 implicit_value_parameter_type = (Expression) $4;
2297 lexer.EventParsing = true;
2299 event_accessor_declarations
2301 lexer.EventParsing = false;
2305 MemberName name = (MemberName) $5;
2308 Report.Error (65, (Location) $3, "`{0}.{1}': event property must have both add and remove accessors",
2309 current_container.Name, name.ToString ());
2312 Pair pair = (Pair) $8;
2314 if (name.TypeArguments != null)
2315 syntax_error (lexer.Location, "an event can't have type arguments");
2317 if (pair.First == null || pair.Second == null)
2318 // CS0073 is already reported, so no CS0065 here.
2321 Event e = new EventProperty (
2322 current_class, (Expression) $4, (int) $2, false, name, null,
2323 (Attributes) $1, (Accessor) pair.First, (Accessor) pair.Second);
2324 if (RootContext.Documentation != null) {
2325 e.DocComment = Lexer.consume_doc_comment ();
2326 Lexer.doc_state = XmlCommentState.Allowed;
2329 current_container.AddEvent (e);
2330 implicit_value_parameter_type = null;
2334 | opt_attributes opt_modifiers EVENT type namespace_or_type_name error {
2335 MemberName mn = (MemberName) $5;
2337 if (mn.Left != null)
2338 Report.Error (71, mn.Location, "An explicit interface implementation of an event must use property syntax");
2340 Report.Error (71, mn.Location, "Event declaration should use property syntax");
2342 if (RootContext.Documentation != null)
2343 Lexer.doc_state = XmlCommentState.Allowed;
2347 event_accessor_declarations
2348 : add_accessor_declaration remove_accessor_declaration
2350 $$ = new Pair ($1, $2);
2352 | remove_accessor_declaration add_accessor_declaration
2354 $$ = new Pair ($2, $1);
2356 | add_accessor_declaration { $$ = null; }
2357 | remove_accessor_declaration { $$ = null; }
2360 Report.Error (1055, GetLocation ($1), "An add or remove accessor expected");
2366 add_accessor_declaration
2367 : opt_attributes ADD
2369 Parameter [] args = new Parameter [1];
2370 Parameter implicit_value_parameter = new Parameter (
2371 implicit_value_parameter_type, "value",
2372 Parameter.Modifier.NONE, null, (Location) $2);
2374 args [0] = implicit_value_parameter;
2376 current_local_parameters = new Parameters (args, null);
2377 lexer.EventParsing = false;
2381 $$ = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, (Location) $2);
2382 lexer.EventParsing = true;
2384 | opt_attributes ADD error {
2385 Report.Error (73, (Location) $2, "An add or remove accessor must have a body");
2388 | opt_attributes modifiers ADD {
2389 Report.Error (1609, (Location) $3, "Modifiers cannot be placed on event accessor declarations");
2394 remove_accessor_declaration
2395 : opt_attributes REMOVE
2397 Parameter [] args = new Parameter [1];
2398 Parameter implicit_value_parameter = new Parameter (
2399 implicit_value_parameter_type, "value",
2400 Parameter.Modifier.NONE, null, (Location) $2);
2402 args [0] = implicit_value_parameter;
2404 current_local_parameters = new Parameters (args, null);
2405 lexer.EventParsing = false;
2409 $$ = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, (Location) $2);
2410 lexer.EventParsing = true;
2412 | opt_attributes REMOVE error {
2413 Report.Error (73, (Location) $2, "An add or remove accessor must have a body");
2416 | opt_attributes modifiers REMOVE {
2417 Report.Error (1609, (Location) $3, "Modifiers cannot be placed on event accessor declarations");
2423 : opt_attributes opt_modifiers indexer_declarator
2426 IndexerDeclaration decl = (IndexerDeclaration) $3;
2428 implicit_value_parameter_type = decl.type;
2430 lexer.PropertyParsing = true;
2431 parsing_indexer = true;
2433 indexer_parameters = decl.param_list;
2434 iterator_container = SimpleIteratorContainer.GetSimple ();
2436 accessor_declarations
2438 lexer.PropertyParsing = false;
2439 has_get = has_set = false;
2440 parsing_indexer = false;
2447 // The signature is computed from the signature of the indexer. Look
2448 // at section 3.6 on the spec
2450 IndexerDeclaration decl = (IndexerDeclaration) $3;
2451 Pair pair = (Pair) $6;
2452 Accessor get_block = (Accessor) pair.First;
2453 Accessor set_block = (Accessor) pair.Second;
2456 if (decl.interface_type != null)
2457 name = new MemberName (
2458 decl.interface_type, TypeContainer.DefaultIndexerName, decl.location);
2460 name = new MemberName (TypeContainer.DefaultIndexerName, decl.location);
2462 indexer = new Indexer (current_class, decl.type, name,
2463 (int) $2, false, decl.param_list, (Attributes) $1,
2464 get_block, set_block);
2466 if (RootContext.Documentation != null)
2467 indexer.DocComment = ConsumeStoredComment ();
2469 current_container.AddIndexer (indexer);
2471 current_local_parameters = null;
2472 implicit_value_parameter_type = null;
2473 indexer_parameters = null;
2478 : type THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
2480 Parameters pars = (Parameters) $4;
2481 if (pars.HasArglist) {
2482 // "__arglist is not valid in this context"
2483 Report.Error (1669, (Location) $2, "__arglist is not valid in this context");
2484 } else if (pars.FixedParameters == null && pars.ArrayParameter == null){
2485 Report.Error (1551, (Location) $2, "Indexers must have at least one parameter");
2487 if (RootContext.Documentation != null) {
2488 tmpComment = Lexer.consume_doc_comment ();
2489 Lexer.doc_state = XmlCommentState.Allowed;
2492 $$ = new IndexerDeclaration ((Expression) $1, null, pars, (Location) $2);
2494 | type namespace_or_type_name DOT THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
2496 Parameters pars = (Parameters) $6;
2498 if (pars.HasArglist) {
2499 // "__arglist is not valid in this context"
2500 Report.Error (1669, (Location) $4, "__arglist is not valid in this context");
2501 } else if (pars.FixedParameters == null && pars.ArrayParameter == null){
2502 Report.Error (1551, (Location) $4, "Indexers must have at least one parameter");
2505 MemberName name = (MemberName) $2;
2506 $$ = new IndexerDeclaration ((Expression) $1, name, pars, (Location) $4);
2508 if (RootContext.Documentation != null) {
2509 tmpComment = Lexer.consume_doc_comment ();
2510 Lexer.doc_state = XmlCommentState.Allowed;
2521 if (RootContext.Documentation != null)
2522 enumTypeComment = Lexer.consume_doc_comment ();
2527 LocatedToken lt = (LocatedToken) $5;
2528 Location enum_location = lt.Location;
2531 Report.Error (267, lt.Location, "The partial modifier can only appear immediately before `class', `struct' or `interface'");
2532 break; // assumes that the parser put us in a switch
2535 MemberName name = MakeName (new MemberName (lt.Value, enum_location));
2536 Enum e = new Enum (current_namespace, current_class, (Expression) $6, (int) $2,
2537 name, (Attributes) $1);
2539 if (RootContext.Documentation != null)
2540 e.DocComment = enumTypeComment;
2543 EnumMember em = null;
2544 foreach (VariableDeclaration ev in (ArrayList) $8) {
2545 em = new EnumMember (e, em, (Expression) ev.expression_or_array_initializer,
2546 new MemberName (ev.identifier, ev.Location), ev.OptAttributes);
2548 // if (RootContext.Documentation != null)
2549 em.DocComment = ev.DocComment;
2551 e.AddEnumMember (em);
2554 current_container.AddEnum (e);
2555 RootContext.Tree.RecordDecl (current_namespace.NS, name, e);
2562 : /* empty */ { $$ = TypeManager.system_int32_expr; }
2563 | COLON type { $$ = $2; }
2569 if (RootContext.Documentation != null)
2570 Lexer.doc_state = XmlCommentState.Allowed;
2572 opt_enum_member_declarations
2574 // here will be evaluated after CLOSE_BLACE is consumed.
2575 if (RootContext.Documentation != null)
2576 Lexer.doc_state = XmlCommentState.Allowed;
2584 opt_enum_member_declarations
2585 : /* empty */ { $$ = new ArrayList (4); }
2586 | enum_member_declarations opt_comma { $$ = $1; }
2589 enum_member_declarations
2590 : enum_member_declaration
2592 ArrayList l = new ArrayList (4);
2597 | enum_member_declarations COMMA enum_member_declaration
2599 ArrayList l = (ArrayList) $1;
2607 enum_member_declaration
2608 : opt_attributes IDENTIFIER
2610 VariableDeclaration vd = new VariableDeclaration (
2611 (LocatedToken) $2, null, (Attributes) $1);
2613 if (RootContext.Documentation != null) {
2614 vd.DocComment = Lexer.consume_doc_comment ();
2615 Lexer.doc_state = XmlCommentState.Allowed;
2620 | opt_attributes IDENTIFIER
2622 if (RootContext.Documentation != null) {
2623 tmpComment = Lexer.consume_doc_comment ();
2624 Lexer.doc_state = XmlCommentState.NotAllowed;
2629 VariableDeclaration vd = new VariableDeclaration (
2630 (LocatedToken) $2, $5, (Attributes) $1);
2632 if (RootContext.Documentation != null)
2633 vd.DocComment = ConsumeStoredComment ();
2639 delegate_declaration
2644 lexer.ConstraintsParsing = true;
2647 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2649 MemberName name = MakeName ((MemberName) $6);
2650 Delegate del = new Delegate (current_namespace, current_class, (Expression) $5,
2651 (int) $2, name, (Parameters) $8, (Attributes) $1);
2653 if (RootContext.Documentation != null) {
2654 del.DocComment = Lexer.consume_doc_comment ();
2655 Lexer.doc_state = XmlCommentState.Allowed;
2658 current_container.AddDelegate (del);
2659 RootContext.Tree.RecordDecl (current_namespace.NS, name, del);
2661 current_delegate = del;
2663 opt_type_parameter_constraints_clauses
2665 lexer.ConstraintsParsing = false;
2669 current_delegate.SetParameterInfo ((ArrayList) $11);
2670 $$ = current_delegate;
2672 current_delegate = null;
2679 lexer.CheckNullable (false);
2684 lexer.CheckNullable (true);
2689 namespace_or_type_name
2691 | IDENTIFIER DOUBLE_COLON IDENTIFIER {
2692 LocatedToken lt1 = (LocatedToken) $1;
2693 LocatedToken lt2 = (LocatedToken) $3;
2694 $$ = new MemberName (lt1.Value, lt2.Value, lt2.Location);
2696 | namespace_or_type_name DOT IDENTIFIER opt_type_argument_list {
2697 LocatedToken lt = (LocatedToken) $3;
2698 $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $4, lt.Location);
2703 : IDENTIFIER opt_type_argument_list {
2704 LocatedToken lt = (LocatedToken) $1;
2705 $$ = new MemberName (lt.Value, (TypeArguments) $2, lt.Location);
2709 opt_type_argument_list
2710 : /* empty */ { $$ = null; }
2711 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
2714 if (RootContext.Version == LanguageVersion.ISO_1)
2715 Report.FeatureIsNotStandardized (lexer.Location, "generics");
2719 $$ = new TypeArguments ((int) $1, lexer.Location);
2720 if (RootContext.Version == LanguageVersion.ISO_1)
2721 Report.FeatureIsNotStandardized (lexer.Location, "generics");
2727 TypeArguments type_args = new TypeArguments (lexer.Location);
2728 type_args.Add ((Expression) $1);
2731 | type_arguments COMMA type {
2732 TypeArguments type_args = (TypeArguments) $1;
2733 type_args.Add ((Expression) $3);
2739 * Before you think of adding a return_type, notice that we have been
2740 * using two rules in the places where it matters (one rule using type
2741 * and another identical one that uses VOID as the return type). This
2742 * gets rid of a shift/reduce couple
2745 : namespace_or_type_name opt_nullable
2747 MemberName name = (MemberName) $1;
2748 $$ = name.GetTypeExpression ();
2751 $$ = new ComposedCast ((Expression) $$, "?", lexer.Location);
2753 | builtin_types opt_nullable
2756 $$ = new ComposedCast ((Expression) $1, "?", lexer.Location);
2766 // Note that here only unmanaged types are allowed but we
2767 // can't perform checks during this phase - we do it during
2768 // semantic analysis.
2770 $$ = new ComposedCast ((Expression) $1, "*", Lexer.Location);
2774 $$ = new ComposedCast (TypeManager.system_void_expr, "*", (Location) $1);
2779 : builtin_types opt_nullable
2782 $$ = new ComposedCast ((Expression) $1, "?", lexer.Location);
2784 | non_expression_type rank_specifier
2786 Location loc = GetLocation ($1);
2788 loc = lexer.Location;
2789 $$ = new ComposedCast ((Expression) $1, (string) $2, loc);
2791 | non_expression_type STAR
2793 Location loc = GetLocation ($1);
2795 loc = lexer.Location;
2796 $$ = new ComposedCast ((Expression) $1, "*", loc);
2798 | expression rank_specifiers
2800 $$ = new ComposedCast ((Expression) $1, (string) $2);
2804 $$ = new ComposedCast ((Expression) $1, "*");
2808 // We need this because the parser will happily go and reduce IDENTIFIER STAR
2809 // through this different path
2811 | multiplicative_expression STAR
2813 $$ = new ComposedCast ((Expression) $1, "*");
2820 ArrayList types = new ArrayList (4);
2825 | type_list COMMA type
2827 ArrayList types = (ArrayList) $1;
2835 * replaces all the productions for isolating the various
2836 * simple types, but we need this to reuse it easily in local_variable_type
2839 : OBJECT { $$ = TypeManager.system_object_expr; }
2840 | STRING { $$ = TypeManager.system_string_expr; }
2841 | BOOL { $$ = TypeManager.system_boolean_expr; }
2842 | DECIMAL { $$ = TypeManager.system_decimal_expr; }
2843 | FLOAT { $$ = TypeManager.system_single_expr; }
2844 | DOUBLE { $$ = TypeManager.system_double_expr; }
2849 : SBYTE { $$ = TypeManager.system_sbyte_expr; }
2850 | BYTE { $$ = TypeManager.system_byte_expr; }
2851 | SHORT { $$ = TypeManager.system_int16_expr; }
2852 | USHORT { $$ = TypeManager.system_uint16_expr; }
2853 | INT { $$ = TypeManager.system_int32_expr; }
2854 | UINT { $$ = TypeManager.system_uint32_expr; }
2855 | LONG { $$ = TypeManager.system_int64_expr; }
2856 | ULONG { $$ = TypeManager.system_uint64_expr; }
2857 | CHAR { $$ = TypeManager.system_char_expr; }
2858 | VOID { $$ = TypeManager.system_void_expr; }
2862 : type rank_specifiers opt_nullable
2864 string rank_specifiers = (string) $2;
2866 rank_specifiers += "?";
2868 $$ = new ComposedCast ((Expression) $1, rank_specifiers);
2873 // Expressions, section 7.5
2882 MemberName mn = (MemberName) $1;
2883 $$ = mn.GetTypeExpression ();
2885 | IDENTIFIER DOUBLE_COLON IDENTIFIER
2887 LocatedToken lt1 = (LocatedToken) $1;
2888 LocatedToken lt2 = (LocatedToken) $3;
2889 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, lt2.Location);
2891 | parenthesized_expression
2892 | default_value_expression
2894 | invocation_expression
2898 | post_increment_expression
2899 | post_decrement_expression
2903 | checked_expression
2904 | unchecked_expression
2905 | pointer_member_access
2906 | anonymous_method_expression
2913 | LITERAL_CHARACTER { $$ = new CharLiteral ((char) lexer.Value, lexer.Location); }
2914 | LITERAL_STRING { $$ = new StringLiteral ((string) lexer.Value, lexer.Location); }
2915 | NULL { $$ = new NullLiteral (lexer.Location); }
2919 : LITERAL_FLOAT { $$ = new FloatLiteral ((float) lexer.Value, lexer.Location); }
2920 | LITERAL_DOUBLE { $$ = new DoubleLiteral ((double) lexer.Value, lexer.Location); }
2921 | LITERAL_DECIMAL { $$ = new DecimalLiteral ((decimal) lexer.Value, lexer.Location); }
2926 object v = lexer.Value;
2929 $$ = new IntLiteral ((int) v, lexer.Location);
2930 } else if (v is uint)
2931 $$ = new UIntLiteral ((UInt32) v, lexer.Location);
2933 $$ = new LongLiteral ((Int64) v, lexer.Location);
2934 else if (v is ulong)
2935 $$ = new ULongLiteral ((UInt64) v, lexer.Location);
2937 Console.WriteLine ("OOPS. Unexpected result from scanner");
2942 : TRUE { $$ = new BoolLiteral (true, lexer.Location); }
2943 | FALSE { $$ = new BoolLiteral (false, lexer.Location); }
2946 parenthesized_expression_0
2947 : OPEN_PARENS expression CLOSE_PARENS
2950 lexer.Deambiguate_CloseParens ();
2951 // After this, the next token returned is one of
2952 // CLOSE_PARENS_CAST, CLOSE_PARENS_NO_CAST, CLOSE_PARENS_OPEN_PARENS
2953 // or CLOSE_PARENS_MINUS.
2957 parenthesized_expression
2958 : parenthesized_expression_0 CLOSE_PARENS_NO_CAST
2962 | parenthesized_expression_0 CLOSE_PARENS_MINUS
2964 // If a parenthesized expression is followed by a minus, we need to wrap
2965 // the expression inside a ParenthesizedExpression for the CS0075 check
2966 // in Binary.DoResolve().
2967 $$ = new ParenthesizedExpression ((Expression) $1);
2972 : primary_expression DOT IDENTIFIER opt_type_argument_list
2974 LocatedToken lt = (LocatedToken) $3;
2975 $$ = new MemberAccess ((Expression) $1, lt.Value,
2976 (TypeArguments) $4, lt.Location);
2978 | predefined_type DOT IDENTIFIER opt_type_argument_list
2980 LocatedToken lt = (LocatedToken) $3;
2981 $$ = new MemberAccess ((Expression) $1, lt.Value,
2982 (TypeArguments) $4, lt.Location);
2990 invocation_expression
2991 : primary_expression {
2992 $$ = lexer.Location;
2993 } OPEN_PARENS opt_argument_list CLOSE_PARENS
2996 Location l = (Location) $3;
2997 Report.Error (1, l, "Parse error");
2999 $$ = new Invocation ((Expression) $1, (ArrayList) $4);
3001 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS CLOSE_PARENS
3003 $$ = new Invocation ((Expression) $1, new ArrayList ());
3005 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS primary_expression
3007 $$ = new InvocationOrCast ((Expression) $1, (Expression) $3);
3009 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS non_simple_argument CLOSE_PARENS
3011 ArrayList args = new ArrayList (1);
3013 $$ = new Invocation ((Expression) $1, args);
3015 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS argument_list COMMA argument CLOSE_PARENS
3017 ArrayList args = ((ArrayList) $4);
3019 $$ = new Invocation ((Expression) $1, args);
3024 : /* empty */ { $$ = null; }
3031 ArrayList list = new ArrayList (4);
3035 | argument_list COMMA argument
3037 ArrayList list = (ArrayList) $1;
3041 | argument_list error {
3042 CheckToken (1026, yyToken, "Expected `,' or `)'", GetLocation ($2));
3050 $$ = new Argument ((Expression) $1, Argument.AType.Expression);
3052 | non_simple_argument
3059 : REF variable_reference
3061 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3063 | OUT variable_reference
3065 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3067 | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
3069 ArrayList list = (ArrayList) $3;
3070 Argument[] args = new Argument [list.Count];
3071 list.CopyTo (args, 0);
3073 Expression expr = new Arglist (args, (Location) $1);
3074 $$ = new Argument (expr, Argument.AType.Expression);
3078 $$ = new Argument (new ArglistAccess ((Location) $1), Argument.AType.ArgList);
3083 : expression { note ("section 5.4"); $$ = $1; }
3087 : primary_expression OPEN_BRACKET expression_list CLOSE_BRACKET
3089 $$ = new ElementAccess ((Expression) $1, (ArrayList) $3);
3091 | primary_expression rank_specifiers
3093 // So the super-trick is that primary_expression
3094 // can only be either a SimpleName or a MemberAccess.
3095 // The MemberAccess case arises when you have a fully qualified type-name like :
3097 // SimpleName is when you have
3100 Expression expr = (Expression) $1;
3101 if (expr is ComposedCast){
3102 $$ = new ComposedCast (expr, (string) $2);
3103 } else if (!(expr is SimpleName || expr is MemberAccess || expr is ConstructedType || expr is QualifiedAliasMember)){
3104 Error_ExpectingTypeName (expr);
3105 $$ = TypeManager.system_object_expr;
3108 // So we extract the string corresponding to the SimpleName
3111 $$ = new ComposedCast (expr, (string) $2);
3119 ArrayList list = new ArrayList (4);
3123 | expression_list COMMA expression
3125 ArrayList list = (ArrayList) $1;
3134 $$ = new This (current_block, (Location) $1);
3139 : BASE DOT IDENTIFIER
3141 LocatedToken lt = (LocatedToken) $3;
3142 $$ = new BaseAccess (lt.Value, lt.Location);
3144 | BASE OPEN_BRACKET expression_list CLOSE_BRACKET
3146 $$ = new BaseIndexerAccess ((ArrayList) $3, (Location) $1);
3149 Report.Error (175, (Location) $1, "Use of keyword `base' is not valid in this context");
3154 post_increment_expression
3155 : primary_expression OP_INC
3157 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement,
3158 (Expression) $1, (Location) $2);
3162 post_decrement_expression
3163 : primary_expression OP_DEC
3165 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement,
3166 (Expression) $1, (Location) $2);
3171 : object_or_delegate_creation_expression
3172 | array_creation_expression
3175 object_or_delegate_creation_expression
3176 : NEW type OPEN_PARENS opt_argument_list CLOSE_PARENS
3178 $$ = new New ((Expression) $2, (ArrayList) $4, (Location) $1);
3182 array_creation_expression
3183 : NEW type OPEN_BRACKET expression_list CLOSE_BRACKET
3185 opt_array_initializer
3187 $$ = new ArrayCreation ((Expression) $2, (ArrayList) $4, (string) $6, (ArrayList) $7, (Location) $1);
3189 | NEW type rank_specifiers array_initializer
3191 $$ = new ArrayCreation ((Expression) $2, (string) $3, (ArrayList) $4, (Location) $1);
3195 Report.Error (1031, (Location) $1, "Type expected");
3200 Report.Error (1526, (Location) $1, "A new expression requires () or [] after type");
3216 opt_rank_specifier_or_nullable
3225 | opt_nullable rank_specifiers
3232 | opt_nullable rank_specifiers INTERR
3235 $$ = "?" + $2 + "?";
3242 : rank_specifier opt_rank_specifier
3244 $$ = (string) $2 + (string) $1;
3249 : OPEN_BRACKET opt_dim_separators CLOSE_BRACKET
3251 $$ = "[" + (string) $2 + "]";
3271 | dim_separators COMMA
3273 $$ = (string) $1 + ",";
3277 opt_array_initializer
3289 : OPEN_BRACE CLOSE_BRACE
3291 ArrayList list = new ArrayList (4);
3294 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
3296 $$ = (ArrayList) $2;
3300 variable_initializer_list
3301 : variable_initializer
3303 ArrayList list = new ArrayList (4);
3307 | variable_initializer_list COMMA variable_initializer
3309 ArrayList list = (ArrayList) $1;
3315 void_pointer_expression
3316 : void_pointer_expression STAR
3318 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
3322 $$ = new ComposedCast (TypeManager.system_void_expr, "*", lexer.Location);;
3327 : TYPEOF OPEN_PARENS VOID CLOSE_PARENS
3329 $$ = new TypeOfVoid ((Location) $1);
3331 | TYPEOF OPEN_PARENS void_pointer_expression CLOSE_PARENS
3333 $$ = new TypeOf ((Expression) $3, (Location) $1);
3335 | TYPEOF OPEN_PARENS
3337 lexer.TypeOfParsing = true;
3341 lexer.TypeOfParsing = false;
3342 $$ = new TypeOf ((Expression) $4, lexer.Location);
3347 : SIZEOF OPEN_PARENS type CLOSE_PARENS {
3348 $$ = new SizeOf ((Expression) $3, (Location) $1);
3353 : CHECKED OPEN_PARENS expression CLOSE_PARENS
3355 $$ = new CheckedExpr ((Expression) $3, (Location) $1);
3359 unchecked_expression
3360 : UNCHECKED OPEN_PARENS expression CLOSE_PARENS
3362 $$ = new UnCheckedExpr ((Expression) $3, (Location) $1);
3366 pointer_member_access
3367 : primary_expression OP_PTR IDENTIFIER
3370 LocatedToken lt = (LocatedToken) $3;
3372 deref = new Unary (Unary.Operator.Indirection, (Expression) $1, lt.Location);
3373 $$ = new MemberAccess (deref, lt.Value, lt.Location);
3377 anonymous_method_expression
3378 : DELEGATE opt_anonymous_method_signature
3380 oob_stack.Push (current_local_parameters);
3381 current_local_parameters = (Parameters)$2;
3383 // Force the next block to be created as a ToplevelBlock
3384 oob_stack.Push (current_block);
3385 oob_stack.Push (top_current_block);
3386 current_block = null;
3390 Location loc = (Location) $1;
3391 top_current_block = (Block) oob_stack.Pop ();
3392 current_block = (Block) oob_stack.Pop ();
3393 if (RootContext.Version == LanguageVersion.ISO_1){
3394 Report.FeatureIsNotStandardized (loc, "anonymous methods");
3397 ToplevelBlock anon_block = (ToplevelBlock) $4;
3399 anon_block.Parent = current_block;
3400 $$ = new AnonymousMethod ((Parameters) $2, (ToplevelBlock) top_current_block,
3403 current_local_parameters = (Parameters) oob_stack.Pop ();
3407 opt_anonymous_method_signature
3408 : /* empty */ { $$ = null; }
3409 | anonymous_method_signature
3412 anonymous_method_signature
3413 : OPEN_PARENS opt_anonymous_method_parameter_list CLOSE_PARENS
3416 $$ = Parameters.EmptyReadOnlyParameters;
3418 ArrayList par_list = (ArrayList) $2;
3419 Parameter [] pars = new Parameter [par_list.Count];
3420 par_list.CopyTo (pars);
3421 $$ = new Parameters (pars, null);
3426 opt_anonymous_method_parameter_list
3427 : /* empty */ { $$ = null; }
3428 | anonymous_method_parameter_list { $$ = $1; }
3431 anonymous_method_parameter_list
3432 : anonymous_method_parameter
3434 ArrayList a = new ArrayList (4);
3438 | anonymous_method_parameter_list COMMA anonymous_method_parameter
3440 ArrayList a = (ArrayList) $1;
3446 anonymous_method_parameter
3447 : opt_parameter_modifier type IDENTIFIER {
3448 LocatedToken lt = (LocatedToken) $3;
3449 $$ = new Parameter ((Expression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
3451 | PARAMS type IDENTIFIER {
3452 Report.Error (1670, ((LocatedToken) $3).Location, "The `params' modifier is not allowed in anonymous method declaration");
3457 default_value_expression
3458 : DEFAULT_OPEN_PARENS type CLOSE_PARENS
3460 $$ = new DefaultValueExpression ((Expression) $2, lexer.Location);
3465 : primary_expression
3466 | BANG prefixed_unary_expression
3468 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, (Location) $1);
3470 | TILDE prefixed_unary_expression
3472 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, (Location) $1);
3478 : parenthesized_expression_0 CLOSE_PARENS_CAST unary_expression
3480 $$ = new Cast ((Expression) $1, (Expression) $3);
3482 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS cast_expression
3484 $$ = new Cast ((Expression) $1, (Expression) $3);
3490 | OPEN_PARENS non_expression_type CLOSE_PARENS prefixed_unary_expression
3492 // TODO: wrong location
3493 $$ = new Cast ((Expression) $2, (Expression) $4, lexer.Location);
3498 // The idea to split this out is from Rhys' grammar
3499 // to solve the problem with casts.
3501 prefixed_unary_expression
3503 | PLUS prefixed_unary_expression
3505 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, (Location) $1);
3507 | MINUS prefixed_unary_expression
3509 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, (Location) $1);
3511 | OP_INC prefixed_unary_expression
3513 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
3514 (Expression) $2, (Location) $1);
3516 | OP_DEC prefixed_unary_expression
3518 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
3519 (Expression) $2, (Location) $1);
3521 | STAR prefixed_unary_expression
3523 $$ = new Unary (Unary.Operator.Indirection, (Expression) $2, (Location) $1);
3525 | BITWISE_AND prefixed_unary_expression
3527 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, (Location) $1);
3531 pre_increment_expression
3532 : OP_INC prefixed_unary_expression
3534 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
3535 (Expression) $2, (Location) $1);
3539 pre_decrement_expression
3540 : OP_DEC prefixed_unary_expression
3542 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
3543 (Expression) $2, (Location) $1);
3547 multiplicative_expression
3548 : prefixed_unary_expression
3549 | multiplicative_expression STAR prefixed_unary_expression
3551 $$ = new Binary (Binary.Operator.Multiply,
3552 (Expression) $1, (Expression) $3);
3554 | multiplicative_expression DIV prefixed_unary_expression
3556 $$ = new Binary (Binary.Operator.Division,
3557 (Expression) $1, (Expression) $3);
3559 | multiplicative_expression PERCENT prefixed_unary_expression
3561 $$ = new Binary (Binary.Operator.Modulus,
3562 (Expression) $1, (Expression) $3);
3567 : multiplicative_expression
3568 | additive_expression PLUS multiplicative_expression
3570 $$ = new Binary (Binary.Operator.Addition,
3571 (Expression) $1, (Expression) $3);
3573 | additive_expression MINUS multiplicative_expression
3575 $$ = new Binary (Binary.Operator.Subtraction,
3576 (Expression) $1, (Expression) $3);
3581 : additive_expression
3582 | shift_expression OP_SHIFT_LEFT additive_expression
3584 $$ = new Binary (Binary.Operator.LeftShift,
3585 (Expression) $1, (Expression) $3);
3587 | shift_expression OP_SHIFT_RIGHT additive_expression
3589 $$ = new Binary (Binary.Operator.RightShift,
3590 (Expression) $1, (Expression) $3);
3601 lexer.PutbackNullable ();
3606 nullable_type_or_conditional
3609 if (((bool) $2) && ($1 is ComposedCast))
3610 $$ = ((ComposedCast) $1).RemoveNullable ();
3616 relational_expression
3618 | relational_expression OP_LT shift_expression
3620 $$ = new Binary (Binary.Operator.LessThan,
3621 (Expression) $1, (Expression) $3);
3623 | relational_expression OP_GT shift_expression
3625 $$ = new Binary (Binary.Operator.GreaterThan,
3626 (Expression) $1, (Expression) $3);
3628 | relational_expression OP_LE shift_expression
3630 $$ = new Binary (Binary.Operator.LessThanOrEqual,
3631 (Expression) $1, (Expression) $3);
3633 | relational_expression OP_GE shift_expression
3635 $$ = new Binary (Binary.Operator.GreaterThanOrEqual,
3636 (Expression) $1, (Expression) $3);
3638 | relational_expression IS
3641 } nullable_type_or_conditional
3643 $$ = new Is ((Expression) $1, (Expression) $4, (Location) $2);
3645 | relational_expression AS
3648 } nullable_type_or_conditional
3650 $$ = new As ((Expression) $1, (Expression) $4, (Location) $2);
3655 : relational_expression
3656 | equality_expression OP_EQ relational_expression
3658 $$ = new Binary (Binary.Operator.Equality,
3659 (Expression) $1, (Expression) $3);
3661 | equality_expression OP_NE relational_expression
3663 $$ = new Binary (Binary.Operator.Inequality,
3664 (Expression) $1, (Expression) $3);
3669 : equality_expression
3670 | and_expression BITWISE_AND equality_expression
3672 $$ = new Binary (Binary.Operator.BitwiseAnd,
3673 (Expression) $1, (Expression) $3);
3677 exclusive_or_expression
3679 | exclusive_or_expression CARRET and_expression
3681 $$ = new Binary (Binary.Operator.ExclusiveOr,
3682 (Expression) $1, (Expression) $3);
3686 inclusive_or_expression
3687 : exclusive_or_expression
3688 | inclusive_or_expression BITWISE_OR exclusive_or_expression
3690 $$ = new Binary (Binary.Operator.BitwiseOr,
3691 (Expression) $1, (Expression) $3);
3695 conditional_and_expression
3696 : inclusive_or_expression
3697 | conditional_and_expression OP_AND inclusive_or_expression
3699 $$ = new Binary (Binary.Operator.LogicalAnd,
3700 (Expression) $1, (Expression) $3);
3704 conditional_or_expression
3705 : conditional_and_expression
3706 | conditional_or_expression OP_OR conditional_and_expression
3708 $$ = new Binary (Binary.Operator.LogicalOr,
3709 (Expression) $1, (Expression) $3);
3713 conditional_expression
3714 : conditional_or_expression
3715 | conditional_or_expression INTERR expression COLON expression
3717 $$ = new Conditional ((Expression) $1, (Expression) $3, (Expression) $5);
3719 | conditional_or_expression INTERR INTERR expression
3721 $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $4, lexer.Location);
3723 // We'll be resolved into a `parenthesized_expression_0' later on.
3724 | conditional_or_expression INTERR CLOSE_PARENS
3726 $$ = new ComposedCast ((Expression) $1, "?", lexer.Location);
3727 lexer.PutbackCloseParens ();
3731 assignment_expression
3732 : prefixed_unary_expression ASSIGN expression
3734 $$ = new Assign ((Expression) $1, (Expression) $3);
3736 | prefixed_unary_expression OP_MULT_ASSIGN expression
3738 $$ = new CompoundAssign (
3739 Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
3741 | prefixed_unary_expression OP_DIV_ASSIGN expression
3743 $$ = new CompoundAssign (
3744 Binary.Operator.Division, (Expression) $1, (Expression) $3);
3746 | prefixed_unary_expression OP_MOD_ASSIGN expression
3748 $$ = new CompoundAssign (
3749 Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
3751 | prefixed_unary_expression OP_ADD_ASSIGN expression
3753 $$ = new CompoundAssign (
3754 Binary.Operator.Addition, (Expression) $1, (Expression) $3);
3756 | prefixed_unary_expression OP_SUB_ASSIGN expression
3758 $$ = new CompoundAssign (
3759 Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
3761 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
3763 $$ = new CompoundAssign (
3764 Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
3766 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
3768 $$ = new CompoundAssign (
3769 Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
3771 | prefixed_unary_expression OP_AND_ASSIGN expression
3773 $$ = new CompoundAssign (
3774 Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
3776 | prefixed_unary_expression OP_OR_ASSIGN expression
3778 $$ = new CompoundAssign (
3779 Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
3781 | prefixed_unary_expression OP_XOR_ASSIGN expression
3783 $$ = new CompoundAssign (
3784 Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
3789 : conditional_expression
3790 | assignment_expression
3810 lexer.ConstraintsParsing = true;
3814 MemberName name = MakeName ((MemberName) $6);
3815 int mod_flags = (int) $2;
3818 ClassPart part = PartialContainer.CreatePart (
3819 current_namespace, current_class, name, mod_flags,
3820 (Attributes) $1, Kind.Class, (Location) $3);
3822 current_container = part.PartialContainer;
3823 current_class = part;
3825 if ((mod_flags & Modifiers.STATIC) != 0) {
3826 current_class = new StaticClass (
3827 current_namespace, current_class, name,
3828 mod_flags, (Attributes) $1);
3830 current_class = new Class (
3831 current_namespace, current_class, name,
3832 mod_flags, (Attributes) $1);
3835 current_container.AddClassOrStruct (current_class);
3836 current_container = current_class;
3837 RootContext.Tree.RecordDecl (current_namespace.NS, name, current_class);
3841 opt_type_parameter_constraints_clauses
3843 lexer.ConstraintsParsing = false;
3846 if (current_class.Name == "System.Object") {
3847 Report.Error (537, current_class.Location,
3848 "The class System.Object cannot have a base " +
3849 "class or implement an interface.");
3851 current_class.Bases = (ArrayList) $8;
3854 current_class.SetParameterInfo ((ArrayList) $9);
3856 if (RootContext.Documentation != null) {
3857 current_class.DocComment = Lexer.consume_doc_comment ();
3858 Lexer.doc_state = XmlCommentState.Allowed;
3863 if (RootContext.Documentation != null)
3864 Lexer.doc_state = XmlCommentState.Allowed;
3868 $$ = pop_current_class ();
3876 { $$ = $1; } // location
3880 : /* empty */ { $$ = (int) 0; }
3886 | modifiers modifier
3891 if ((m1 & m2) != 0) {
3892 Location l = lexer.Location;
3893 Report.Error (1004, l, "Duplicate `{0}' modifier", Modifiers.Name (m2));
3895 $$ = (int) (m1 | m2);
3900 : NEW { $$ = Modifiers.NEW; }
3901 | PUBLIC { $$ = Modifiers.PUBLIC; }
3902 | PROTECTED { $$ = Modifiers.PROTECTED; }
3903 | INTERNAL { $$ = Modifiers.INTERNAL; }
3904 | PRIVATE { $$ = Modifiers.PRIVATE; }
3905 | ABSTRACT { $$ = Modifiers.ABSTRACT; }
3906 | SEALED { $$ = Modifiers.SEALED; }
3907 | STATIC { $$ = Modifiers.STATIC; }
3908 | READONLY { $$ = Modifiers.READONLY; }
3909 | VIRTUAL { $$ = Modifiers.VIRTUAL; }
3910 | OVERRIDE { $$ = Modifiers.OVERRIDE; }
3911 | EXTERN { $$ = Modifiers.EXTERN; }
3912 | VOLATILE { $$ = Modifiers.VOLATILE; }
3913 | UNSAFE { $$ = Modifiers.UNSAFE; }
3917 : /* empty */ { $$ = null; }
3918 | class_base { $$ = $1; }
3922 : COLON type_list { $$ = $2; }
3925 opt_type_parameter_constraints_clauses
3926 : /* empty */ { $$ = null; }
3927 | type_parameter_constraints_clauses
3931 type_parameter_constraints_clauses
3932 : type_parameter_constraints_clause {
3933 ArrayList constraints = new ArrayList (1);
3934 constraints.Add ($1);
3937 | type_parameter_constraints_clauses type_parameter_constraints_clause {
3938 ArrayList constraints = (ArrayList) $1;
3940 constraints.Add ($2);
3945 type_parameter_constraints_clause
3946 : WHERE IDENTIFIER COLON type_parameter_constraints {
3947 LocatedToken lt = (LocatedToken) $2;
3948 $$ = new Constraints (lt.Value, (ArrayList) $4, lt.Location);
3952 type_parameter_constraints
3953 : type_parameter_constraint {
3954 ArrayList constraints = new ArrayList (1);
3955 constraints.Add ($1);
3958 | type_parameter_constraints COMMA type_parameter_constraint {
3959 ArrayList constraints = (ArrayList) $1;
3961 constraints.Add ($3);
3966 type_parameter_constraint
3968 | NEW OPEN_PARENS CLOSE_PARENS {
3969 $$ = SpecialConstraint.Constructor;
3972 $$ = SpecialConstraint.ReferenceType;
3975 $$ = SpecialConstraint.ValueType;
3984 // A block is "contained" on the following places:
3986 // property_declaration as part of the accessor body (get/set)
3987 // operator_declaration
3988 // constructor_declaration
3989 // destructor_declaration
3990 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
3995 if (current_block == null){
3996 current_block = new ToplevelBlock ((ToplevelBlock) top_current_block, current_local_parameters, (Location) $1);
3997 top_current_block = current_block;
3999 current_block = new Block (current_block, (Location) $1, Location.Null);
4002 opt_statement_list CLOSE_BRACE
4004 while (current_block.Implicit)
4005 current_block = current_block.Parent;
4007 current_block.SetEndLocation ((Location) $4);
4008 current_block = current_block.Parent;
4009 if (current_block == null)
4010 top_current_block = null;
4021 | statement_list statement
4025 : declaration_statement
4027 if ($1 != null && (Block) $1 != current_block){
4028 current_block.AddStatement ((Statement) $1);
4029 current_block = (Block) $1;
4032 | valid_declaration_statement
4034 current_block.AddStatement ((Statement) $1);
4039 valid_declaration_statement
4042 | expression_statement
4043 | selection_statement
4044 | iteration_statement
4048 | unchecked_statement
4056 : valid_declaration_statement
4057 | declaration_statement
4059 Report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4064 Report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4072 $$ = EmptyStatement.Value;
4079 LocatedToken lt = (LocatedToken) $1;
4080 LabeledStatement labeled = new LabeledStatement (lt.Value, lt.Location);
4082 if (current_block.AddLabel (lt.Value, labeled, lt.Location))
4083 current_block.AddStatement (labeled);
4088 declaration_statement
4089 : local_variable_declaration SEMICOLON
4092 DictionaryEntry de = (DictionaryEntry) $1;
4093 Expression e = (Expression) de.Key;
4095 $$ = declare_local_variables (e, (ArrayList) de.Value, e.Location);
4099 | local_constant_declaration SEMICOLON
4102 DictionaryEntry de = (DictionaryEntry) $1;
4104 $$ = declare_local_constants ((Expression) de.Key, (ArrayList) de.Value);
4110 * The following is from Rhys' grammar:
4111 * > Types in local variable declarations must be recognized as
4112 * > expressions to prevent reduce/reduce errors in the grammar.
4113 * > The expressions are converted into types during semantic analysis.
4116 : primary_expression opt_rank_specifier_or_nullable
4118 // FIXME: Do something smart here regarding the composition of the type.
4120 // Ok, the above "primary_expression" is there to get rid of
4121 // both reduce/reduce and shift/reduces in the grammar, it should
4122 // really just be "type_name". If you use type_name, a reduce/reduce
4123 // creeps up. If you use namespace_or_type_name (which is all we need
4124 // really) two shift/reduces appear.
4127 // So the super-trick is that primary_expression
4128 // can only be either a SimpleName or a MemberAccess.
4129 // The MemberAccess case arises when you have a fully qualified type-name like :
4131 // SimpleName is when you have
4134 Expression expr = (Expression) $1;
4135 if (!(expr is SimpleName || expr is MemberAccess || expr is ComposedCast || expr is ConstructedType || expr is QualifiedAliasMember)) {
4136 Error_ExpectingTypeName (expr);
4140 // So we extract the string corresponding to the SimpleName
4144 if ((string) $2 == "")
4147 $$ = new ComposedCast ((Expression) $1, (string) $2);
4150 | builtin_types opt_rank_specifier_or_nullable
4152 if ((string) $2 == "")
4155 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
4159 local_variable_pointer_type
4160 : primary_expression STAR
4162 Expression expr = (Expression) $1;
4164 if (!(expr is SimpleName || expr is MemberAccess || expr is ComposedCast || expr is ConstructedType || expr is QualifiedAliasMember)) {
4165 Error_ExpectingTypeName (expr);
4169 $$ = new ComposedCast ((Expression) $1, "*");
4171 | builtin_types STAR
4173 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
4177 $$ = new ComposedCast (TypeManager.system_void_expr, "*", (Location) $1);
4179 | local_variable_pointer_type STAR
4181 $$ = new ComposedCast ((Expression) $1, "*");
4185 local_variable_declaration
4186 : local_variable_type variable_declarators
4189 $$ = new DictionaryEntry ($1, $2);
4193 | local_variable_pointer_type opt_rank_specifier_or_nullable variable_declarators
4198 if ((string) $2 == "")
4199 t = (Expression) $1;
4201 t = new ComposedCast ((Expression) $1, (string) $2);
4202 $$ = new DictionaryEntry (t, $3);
4208 local_constant_declaration
4209 : CONST local_variable_type constant_declarators
4212 $$ = new DictionaryEntry ($2, $3);
4218 expression_statement
4219 : statement_expression SEMICOLON
4226 // We have to do the wrapping here and not in the case above,
4227 // because statement_expression is used for example in for_statement
4229 statement_expression
4230 : invocation_expression { $$ = new StatementExpression ((ExpressionStatement) $1); }
4231 | object_creation_expression { $$ = new StatementExpression ((ExpressionStatement) $1); }
4232 | assignment_expression { $$ = new StatementExpression ((ExpressionStatement) $1); }
4233 | post_increment_expression { $$ = new StatementExpression ((ExpressionStatement) $1); }
4234 | post_decrement_expression { $$ = new StatementExpression ((ExpressionStatement) $1); }
4235 | pre_increment_expression { $$ = new StatementExpression ((ExpressionStatement) $1); }
4236 | pre_decrement_expression { $$ = new StatementExpression ((ExpressionStatement) $1); }
4238 Report.Error (1002, GetLocation ($1), "Expecting `;'");
4243 object_creation_expression
4244 : object_or_delegate_creation_expression
4245 { note ("complain if this is a delegate maybe?"); }
4254 : IF OPEN_PARENS boolean_expression CLOSE_PARENS
4257 Location l = (Location) $1;
4259 $$ = new If ((Expression) $3, (Statement) $5, l);
4261 // FIXME: location for warning should be loc property of $5.
4262 if ($5 == EmptyStatement.Value)
4263 Report.Warning (642, 3, l, "Possible mistaken empty statement");
4266 | IF OPEN_PARENS boolean_expression CLOSE_PARENS
4267 embedded_statement ELSE embedded_statement
4269 Location l = (Location) $1;
4271 $$ = new If ((Expression) $3, (Statement) $5, (Statement) $7, l);
4273 // FIXME: location for warning should be loc property of $5 and $7.
4274 if ($5 == EmptyStatement.Value)
4275 Report.Warning (642, 3, l, "Possible mistaken empty statement");
4276 if ($7 == EmptyStatement.Value)
4277 Report.Warning (642, 3, l, "Possible mistaken empty statement");
4282 : SWITCH OPEN_PARENS
4284 switch_stack.Push (current_block);
4286 expression CLOSE_PARENS
4289 $$ = new Switch ((Expression) $4, (ArrayList) $6, (Location) $1);
4290 current_block = (Block) switch_stack.Pop ();
4306 Report.Error (1522, lexer.Location, "Empty switch block");
4314 ArrayList sections = new ArrayList (4);
4319 | switch_sections switch_section
4321 ArrayList sections = (ArrayList) $1;
4331 current_block = current_block.CreateSwitchBlock (lexer.Location);
4335 Block topmost = current_block;
4337 while (topmost.Implicit)
4338 topmost = topmost.Parent;
4339 $$ = new SwitchSection ((ArrayList) $1, topmost);
4346 ArrayList labels = new ArrayList (4);
4351 | switch_labels switch_label
4353 ArrayList labels = (ArrayList) ($1);
4361 : CASE constant_expression COLON { $$ = new SwitchLabel ((Expression) $2, (Location) $1); }
4362 | DEFAULT COLON { $$ = new SwitchLabel (null, (Location) $2); }
4365 1523, GetLocation ($1),
4366 "The keyword case or default must precede code in switch block");
4378 : WHILE OPEN_PARENS boolean_expression CLOSE_PARENS embedded_statement
4380 Location l = (Location) $1;
4381 $$ = new While ((Expression) $3, (Statement) $5, l);
4386 : DO embedded_statement
4387 WHILE OPEN_PARENS boolean_expression CLOSE_PARENS SEMICOLON
4389 Location l = (Location) $1;
4391 $$ = new Do ((Statement) $2, (Expression) $5, l);
4397 opt_for_initializer SEMICOLON
4399 Block assign_block = new Block (current_block);
4400 current_block = assign_block;
4402 if ($3 is DictionaryEntry){
4403 DictionaryEntry de = (DictionaryEntry) $3;
4405 Expression type = (Expression) de.Key;
4406 ArrayList var_declarators = (ArrayList) de.Value;
4408 foreach (VariableDeclaration decl in var_declarators){
4412 vi = current_block.AddVariable (type, decl.identifier, decl.Location);
4416 Location l = lexer.Location;
4418 if (decl.expression_or_array_initializer is Expression){
4419 expr = (Expression) decl.expression_or_array_initializer;
4420 } else if (decl.expression_or_array_initializer == null) {
4423 ArrayList init = (ArrayList) decl.expression_or_array_initializer;
4424 expr = new ArrayCreation (type, "", init, decl.Location);
4427 LocalVariableReference var;
4428 var = new LocalVariableReference (assign_block, decl.identifier, l);
4431 Assign a = new Assign (var, expr, decl.Location);
4433 assign_block.AddStatement (new StatementExpression (a));
4437 // Note: the $$ below refers to the value of this code block, not of the LHS non-terminal.
4438 // This can be referred to as $5 below.
4444 opt_for_condition SEMICOLON
4445 opt_for_iterator CLOSE_PARENS
4448 Location l = (Location) $1;
4450 For f = new For ((Statement) $5, (Expression) $6, (Statement) $8, (Statement) $10, l);
4452 current_block.AddStatement (f);
4453 while (current_block.Implicit)
4454 current_block = current_block.Parent;
4456 current_block = current_block.Parent;
4461 : /* empty */ { $$ = EmptyStatement.Value; }
4466 : local_variable_declaration
4467 | statement_expression_list
4471 : /* empty */ { $$ = null; }
4472 | boolean_expression
4476 : /* empty */ { $$ = EmptyStatement.Value; }
4481 : statement_expression_list
4484 statement_expression_list
4485 : statement_expression
4487 // CHANGE: was `null'
4488 Statement s = (Statement) $1;
4489 Block b = new Block (current_block, Block.Flags.Implicit, s.loc, lexer.Location);
4494 | statement_expression_list COMMA statement_expression
4496 Block b = (Block) $1;
4498 b.AddStatement ((Statement) $3);
4504 : FOREACH OPEN_PARENS type IN expression CLOSE_PARENS
4506 Report.Error (230, (Location) $1, "Type and identifier are both required in a foreach statement");
4509 | FOREACH OPEN_PARENS type IDENTIFIER IN
4510 expression CLOSE_PARENS
4512 Block foreach_block = new Block (current_block);
4513 current_block = foreach_block;
4515 LocatedToken lt = (LocatedToken) $4;
4516 Location l = lt.Location;
4519 vi = foreach_block.AddVariable ((Expression) $3, lt.Value, l);
4521 vi.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Foreach);
4523 // Get a writable reference to this read-only variable.
4525 // Note that the $$ here refers to the value of _this_ code block,
4526 // not the value of the LHS non-terminal. This can be referred to as $8 below.
4527 $$ = new LocalVariableReference (foreach_block, lt.Value, l, vi, false);
4534 LocalVariableReference v = (LocalVariableReference) $8;
4535 Location l = (Location) $1;
4538 Foreach f = new Foreach ((Expression) $3, v, (Expression) $6, (Statement) $9, l);
4539 current_block.AddStatement (f);
4542 while (current_block.Implicit)
4543 current_block = current_block.Parent;
4545 current_block = current_block.Parent;
4551 | continue_statement
4561 $$ = new Break ((Location) $1);
4566 : CONTINUE SEMICOLON
4568 $$ = new Continue ((Location) $1);
4573 : GOTO IDENTIFIER SEMICOLON
4575 LocatedToken lt = (LocatedToken) $2;
4576 $$ = new Goto (lt.Value, lt.Location);
4578 | GOTO CASE constant_expression SEMICOLON
4580 $$ = new GotoCase ((Expression) $3, (Location) $1);
4582 | GOTO DEFAULT SEMICOLON
4584 $$ = new GotoDefault ((Location) $1);
4589 : RETURN opt_expression SEMICOLON
4591 $$ = new Return ((Expression) $2, (Location) $1);
4596 : THROW opt_expression SEMICOLON
4598 $$ = new Throw ((Expression) $2, (Location) $1);
4603 : IDENTIFIER RETURN expression SEMICOLON
4605 LocatedToken lt = (LocatedToken) $1;
4606 string s = lt.Value;
4608 Report.Error (1003, lt.Location, "; expected");
4611 if (RootContext.Version == LanguageVersion.ISO_1){
4612 Report.FeatureIsNotStandardized (lt.Location, "yield statement");
4615 if (iterator_container == null){
4616 Report.Error (204, lt.Location, "yield statement can only be used within a method, operator or property");
4619 iterator_container.SetYields ();
4620 $$ = new Yield ((Expression) $3, lt.Location);
4623 | IDENTIFIER RETURN SEMICOLON
4625 Report.Error (1627, (Location) $2, "Expression expected after yield return");
4628 | IDENTIFIER BREAK SEMICOLON
4630 LocatedToken lt = (LocatedToken) $1;
4631 string s = lt.Value;
4633 Report.Error (1003, lt.Location, "; expected");
4636 if (RootContext.Version == LanguageVersion.ISO_1){
4637 Report.FeatureIsNotStandardized (lt.Location, "yield statement");
4640 if (iterator_container == null){
4641 Report.Error (204, lt.Location, "yield statement can only be used within a method, operator or property");
4644 iterator_container.SetYields ();
4645 $$ = new YieldBreak (lt.Location);
4656 : TRY block catch_clauses
4660 ArrayList c = (ArrayList)$3;
4661 for (int i = 0; i < c.Count; ++i) {
4662 Catch cc = (Catch) c [i];
4664 if (i != c.Count - 1)
4665 Report.Error (1017, cc.loc, "Try statement already has an empty catch block");
4672 // Now s contains the list of specific catch clauses
4673 // and g contains the general one.
4675 $$ = new Try ((Block) $2, c, g, null, ((Block) $2).loc);
4677 | TRY block opt_catch_clauses FINALLY block
4680 ArrayList s = new ArrayList (4);
4681 ArrayList catch_list = (ArrayList) $3;
4683 if (catch_list != null){
4684 foreach (Catch cc in catch_list) {
4692 $$ = new Try ((Block) $2, s, g, (Block) $5, ((Block) $2).loc);
4696 Report.Error (1524, (Location) $1, "Expected catch or finally");
4702 : /* empty */ { $$ = null; }
4709 ArrayList l = new ArrayList (4);
4714 | catch_clauses catch_clause
4716 ArrayList l = (ArrayList) $1;
4724 : /* empty */ { $$ = null; }
4729 : CATCH opt_catch_args
4731 Expression type = null;
4734 DictionaryEntry cc = (DictionaryEntry) $2;
4735 type = (Expression) cc.Key;
4736 LocatedToken lt = (LocatedToken) cc.Value;
4739 ArrayList one = new ArrayList (4);
4741 one.Add (new VariableDeclaration (lt, null));
4743 current_block = new Block (current_block);
4744 Block b = declare_local_variables (type, one, lt.Location);
4749 Expression type = null;
4753 DictionaryEntry cc = (DictionaryEntry) $2;
4754 type = (Expression) cc.Key;
4755 LocatedToken lt = (LocatedToken) cc.Value;
4759 while (current_block.Implicit)
4760 current_block = current_block.Parent;
4761 current_block = current_block.Parent;
4765 $$ = new Catch (type, id, (Block) $4, ((Block) $4).loc);
4770 : /* empty */ { $$ = null; }
4775 : OPEN_PARENS type opt_identifier CLOSE_PARENS
4777 $$ = new DictionaryEntry ($2, $3);
4785 $$ = new Checked ((Block) $2);
4792 $$ = new Unchecked ((Block) $2);
4799 RootContext.CheckUnsafeOption ((Location) $1);
4801 $$ = new Unsafe ((Block) $3);
4807 type fixed_pointer_declarators
4810 ArrayList list = (ArrayList) $4;
4811 Expression type = (Expression) $3;
4812 Location l = (Location) $1;
4813 int top = list.Count;
4815 Block assign_block = new Block (current_block);
4816 current_block = assign_block;
4818 for (int i = 0; i < top; i++){
4819 Pair p = (Pair) list [i];
4822 v = current_block.AddVariable (type, (string) p.First, l);
4826 v.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Fixed);
4834 Location l = (Location) $1;
4836 Fixed f = new Fixed ((Expression) $3, (ArrayList) $4, (Statement) $7, l);
4838 current_block.AddStatement (f);
4839 while (current_block.Implicit)
4840 current_block = current_block.Parent;
4842 current_block = current_block.Parent;
4846 fixed_pointer_declarators
4847 : fixed_pointer_declarator {
4848 ArrayList declarators = new ArrayList (4);
4850 declarators.Add ($1);
4853 | fixed_pointer_declarators COMMA fixed_pointer_declarator
4855 ArrayList declarators = (ArrayList) $1;
4857 declarators.Add ($3);
4862 fixed_pointer_declarator
4863 : IDENTIFIER ASSIGN expression
4865 LocatedToken lt = (LocatedToken) $1;
4866 // FIXME: keep location
4867 $$ = new Pair (lt.Value, $3);
4871 Report.Error (210, ((LocatedToken) $1).Location, "You must provide an initializer in a fixed or using statement declaration");
4877 : LOCK OPEN_PARENS expression CLOSE_PARENS
4883 $$ = new Lock ((Expression) $3, (Statement) $6, (Location) $1);
4888 : USING OPEN_PARENS resource_acquisition CLOSE_PARENS
4890 Block assign_block = new Block (current_block);
4891 current_block = assign_block;
4893 if ($3 is DictionaryEntry){
4894 DictionaryEntry de = (DictionaryEntry) $3;
4895 Location l = (Location) $1;
4897 Expression type = (Expression) de.Key;
4898 ArrayList var_declarators = (ArrayList) de.Value;
4900 ArrayList vars = new ArrayList (4);
4902 foreach (VariableDeclaration decl in var_declarators){
4904 LocalInfo vi = current_block.AddVariable (type, decl.identifier, decl.Location);
4907 vi.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Using);
4910 if (decl.expression_or_array_initializer is Expression){
4911 expr = (Expression) decl.expression_or_array_initializer;
4913 ArrayList init = (ArrayList) decl.expression_or_array_initializer;
4915 Report.Error (210, l, "You must provide an initializer in a fixed or using statement declaration");
4918 expr = new ArrayCreation (type, "", init, decl.Location);
4921 LocalVariableReference var;
4923 // Get a writable reference to this read-only variable.
4924 var = new LocalVariableReference (assign_block, decl.identifier, l, vi, false);
4926 // This is so that it is not a warning on using variables
4929 vars.Add (new DictionaryEntry (var, expr));
4931 // Assign a = new Assign (var, expr, decl.Location);
4932 // assign_block.AddStatement (new StatementExpression (a));
4935 // Note: the $$ here refers to the value of this code block and not of the LHS non-terminal.
4936 // It can be referred to as $5 below.
4937 $$ = new DictionaryEntry (type, vars);
4944 Using u = new Using ($5, (Statement) $6, (Location) $1);
4945 current_block.AddStatement (u);
4946 while (current_block.Implicit)
4947 current_block = current_block.Parent;
4949 current_block = current_block.Parent;
4953 resource_acquisition
4954 : local_variable_declaration
4961 // A class used to pass around variable declarations and constants
4963 public class VariableDeclaration {
4964 public string identifier;
4965 public object expression_or_array_initializer;
4966 public Location Location;
4967 public Attributes OptAttributes;
4968 public string DocComment;
4970 public VariableDeclaration (LocatedToken lt, object eoai, Attributes opt_attrs)
4972 this.identifier = lt.Value;
4973 this.expression_or_array_initializer = eoai;
4974 this.Location = lt.Location;
4975 this.OptAttributes = opt_attrs;
4978 public VariableDeclaration (LocatedToken lt, object eoai) : this (lt, eoai, null)
4984 // A class used to hold info about an indexer declarator
4986 public class IndexerDeclaration {
4987 public Expression type;
4988 public MemberName interface_type;
4989 public Parameters param_list;
4990 public Location location;
4992 public IndexerDeclaration (Expression type, MemberName interface_type,
4993 Parameters param_list, Location loc)
4996 this.interface_type = interface_type;
4997 this.param_list = param_list;
4998 this.location = loc;
5003 // We use this when we do not have an object in advance that is an IIteratorContainer
5005 public class SimpleIteratorContainer : IIteratorContainer {
5008 public static SimpleIteratorContainer Simple = new SimpleIteratorContainer ();
5013 public static SimpleIteratorContainer GetSimple () {
5014 Simple.Yields = false;
5018 public void SetYields () { Yields = true; }
5022 // A class used to hold info about an operator declarator
5024 public class OperatorDeclaration {
5025 public Operator.OpType optype;
5026 public Expression ret_type, arg1type, arg2type;
5027 public string arg1name, arg2name;
5028 public Location location;
5030 public OperatorDeclaration (Operator.OpType op, Expression ret_type,
5031 Expression arg1type, string arg1name,
5032 Expression arg2type, string arg2name, Location location)
5035 this.ret_type = ret_type;
5036 this.arg1type = arg1type;
5037 this.arg1name = arg1name;
5038 this.arg2type = arg2type;
5039 this.arg2name = arg2name;
5040 this.location = location;
5045 void Error_ExpectingTypeName (Expression expr)
5047 if (expr is Invocation){
5048 Report.Error (1002, expr.Location, "Expecting `;'");
5050 Report.Error (201, expr.Location, "Only assignment, call, increment, decrement, and new object expressions can be used as a statement");
5054 TypeContainer pop_current_class ()
5056 TypeContainer retval = current_class;
5058 current_class = current_class.Parent;
5059 current_container = current_container.Parent;
5061 if (current_class != current_container) {
5062 if (!(current_class is ClassPart) ||
5063 ((ClassPart) current_class).PartialContainer != current_container)
5064 throw new InternalErrorException ();
5065 } else if (current_container is ClassPart)
5066 current_container = ((ClassPart) current_class).PartialContainer;
5072 // Given the @class_name name, it creates a fully qualified name
5073 // based on the containing declaration space
5076 MakeName (MemberName class_name)
5078 Namespace ns = current_namespace.NS;
5080 if (current_container.Name == ""){
5082 return new MemberName (ns.MemberName, class_name);
5086 return new MemberName (current_container.MemberName, class_name);
5090 Block declare_local_variables (Expression type, ArrayList variable_declarators, Location loc)
5092 Block implicit_block;
5093 ArrayList inits = null;
5096 // We use the `Used' property to check whether statements
5097 // have been added to the current block. If so, we need
5098 // to create another block to contain the new declaration
5099 // otherwise, as an optimization, we use the same block to
5100 // add the declaration.
5102 // FIXME: A further optimization is to check if the statements
5103 // that were added were added as part of the initialization
5104 // below. In which case, no other statements have been executed
5105 // and we might be able to reduce the number of blocks for
5106 // situations like this:
5108 // int j = 1; int k = j + 1;
5110 if (current_block.Used)
5111 implicit_block = new Block (current_block, Block.Flags.Implicit, loc, Location.Null);
5113 implicit_block = current_block;
5115 foreach (VariableDeclaration decl in variable_declarators){
5117 if (implicit_block.AddVariable (type, decl.identifier, decl.Location) != null) {
5118 if (decl.expression_or_array_initializer != null){
5120 inits = new ArrayList (4);
5127 return implicit_block;
5129 foreach (VariableDeclaration decl in inits){
5133 if (decl.expression_or_array_initializer is Expression){
5134 expr = (Expression) decl.expression_or_array_initializer;
5137 ArrayList init = (ArrayList) decl.expression_or_array_initializer;
5139 expr = new ArrayCreation (type, "", init, decl.Location);
5142 LocalVariableReference var;
5143 var = new LocalVariableReference (implicit_block, decl.identifier, loc);
5145 assign = new Assign (var, expr, decl.Location);
5147 implicit_block.AddStatement (new StatementExpression (assign));
5150 return implicit_block;
5153 Block declare_local_constants (Expression type, ArrayList declarators)
5155 Block implicit_block;
5157 if (current_block.Used)
5158 implicit_block = new Block (current_block, Block.Flags.Implicit);
5160 implicit_block = current_block;
5162 foreach (VariableDeclaration decl in declarators){
5163 implicit_block.AddConstant (type, decl.identifier, (Expression) decl.expression_or_array_initializer, decl.Location);
5166 return implicit_block;
5169 void CheckAttributeTarget (string a, Location l)
5173 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
5177 Report.Error (658, l, "`" + a + "' is an invalid attribute target");
5183 void CheckUnaryOperator (Operator.OpType op, Location l)
5187 case Operator.OpType.LogicalNot:
5188 case Operator.OpType.OnesComplement:
5189 case Operator.OpType.Increment:
5190 case Operator.OpType.Decrement:
5191 case Operator.OpType.True:
5192 case Operator.OpType.False:
5193 case Operator.OpType.Addition:
5194 case Operator.OpType.Subtraction:
5199 Report.Error (1019, l, "Overloadable unary operator expected");
5205 void CheckBinaryOperator (Operator.OpType op, Location l)
5209 case Operator.OpType.Addition:
5210 case Operator.OpType.Subtraction:
5211 case Operator.OpType.Multiply:
5212 case Operator.OpType.Division:
5213 case Operator.OpType.Modulus:
5214 case Operator.OpType.BitwiseAnd:
5215 case Operator.OpType.BitwiseOr:
5216 case Operator.OpType.ExclusiveOr:
5217 case Operator.OpType.LeftShift:
5218 case Operator.OpType.RightShift:
5219 case Operator.OpType.Equality:
5220 case Operator.OpType.Inequality:
5221 case Operator.OpType.GreaterThan:
5222 case Operator.OpType.LessThan:
5223 case Operator.OpType.GreaterThanOrEqual:
5224 case Operator.OpType.LessThanOrEqual:
5228 Report.Error (1020, l, "Overloadable binary operator expected");
5234 void syntax_error (Location l, string msg)
5236 Report.Error (1003, l, "Syntax error, " + msg);
5239 void note (string s)
5241 // Used to put annotations
5246 public Tokenizer Lexer {
5252 public CSharpParser (SeekableStreamReader reader, SourceFile file, ArrayList defines)
5254 current_namespace = new NamespaceEntry (null, file, null, Location.Null);
5255 this.name = file.Name;
5257 current_container = RootContext.Tree.Types;
5258 // TODO: Make RootContext.Tree.Types a PartialContainer.
5259 current_class = current_container;
5260 current_container.NamespaceEntry = current_namespace;
5261 oob_stack = new Stack ();
5262 switch_stack = new Stack ();
5264 lexer = new Tokenizer (reader, file, defines);
5267 public void parse ()
5270 if (yacc_verbose_flag > 1)
5271 yyparse (lexer, new yydebug.yyDebugSimple ());
5274 Tokenizer tokenizer = lexer as Tokenizer;
5275 tokenizer.cleanup ();
5276 } catch (Exception e){
5278 // Removed for production use, use parser verbose to get the output.
5280 // Console.WriteLine (e);
5281 Report.Error (-25, lexer.Location, "Parsing error");
5282 if (yacc_verbose_flag > 0)
5283 Console.WriteLine (e);
5286 RootContext.Tree.Types.NamespaceEntry = null;
5289 void CheckToken (int error, int yyToken, string msg, Location loc)
5291 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD){
5292 Report.Error (error, loc, String.Format ("{0}: `{1}' is a keyword", msg, yyNames [yyToken].ToLower ()));
5295 Report.Error (error, loc, msg);
5298 void CheckIdentifierToken (int yyToken, Location loc)
5300 CheckToken (1041, yyToken, "Identifier expected", loc);
5303 string ConsumeStoredComment ()
5305 string s = tmpComment;
5307 Lexer.doc_state = XmlCommentState.Allowed;
5311 Location GetLocation (object obj)
5313 if (obj is MemberCore)
5314 return ((MemberCore) obj).Location;
5315 if (obj is MemberName)
5316 return ((MemberName) obj).Location;
5317 if (obj is LocatedToken)
5318 return ((LocatedToken) obj).Location;
5319 if (obj is Location)
5320 return (Location) obj;
5321 return lexer.Location;