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 /// Hack to help create non-typed array initializer
65 public static Expression current_array_type;
68 /// Used to determine if we are parsing the get/set pair
69 /// of an indexer or a property
74 /// An out-of-band stack.
83 static public int yacc_verbose_flag;
85 // Name of the file we are parsing
94 /// Temporary Xml documentation cache.
95 /// For enum types, we need one more temporary store.
98 string enumTypeComment;
100 /// Current attribute target
101 string current_attr_target;
103 /// assembly and module attribute definitions are enabled
104 bool global_attrs_enabled = true;
105 bool has_get, has_set;
110 %token NONE /* This token is never returned by our lexer */
111 %token ERROR // This is used not by the parser, but by the tokenizer.
115 *These are the C# keywords
202 /* C# keywords which are not really keywords */
208 /* C# single character operators/punctuation. */
209 %token OPEN_BRACE "{"
210 %token CLOSE_BRACE "}"
211 %token OPEN_BRACKET "["
212 %token CLOSE_BRACKET "]"
213 %token OPEN_PARENS "("
214 %token CLOSE_PARENS ")"
226 %token OP_GENERICS_LT "<"
228 %token OP_GENERICS_GT ">"
229 %token BITWISE_AND "&"
230 %token BITWISE_OR "|"
237 /* C# multi-character operators. */
238 %token DOUBLE_COLON "::"
241 %token OP_SHIFT_LEFT "<<"
242 %token OP_SHIFT_RIGHT ">>"
249 %token OP_MULT_ASSIGN "*="
250 %token OP_DIV_ASSIGN "/="
251 %token OP_MOD_ASSIGN "%="
252 %token OP_ADD_ASSIGN "+="
253 %token OP_SUB_ASSIGN "-="
254 %token OP_SHIFT_LEFT_ASSIGN "<<="
255 %token OP_SHIFT_RIGHT_ASSIGN ">>="
256 %token OP_AND_ASSIGN "&="
257 %token OP_XOR_ASSIGN "^="
258 %token OP_OR_ASSIGN "|="
262 %token LITERAL_INTEGER "int literal"
263 %token LITERAL_FLOAT "float literal"
264 %token LITERAL_DOUBLE "double literal"
265 %token LITERAL_DECIMAL "decimal literal"
266 %token LITERAL_CHARACTER "character literal"
267 %token LITERAL_STRING "string literal"
270 %token CLOSE_PARENS_CAST
271 %token CLOSE_PARENS_NO_CAST
272 %token CLOSE_PARENS_OPEN_PARENS
273 %token CLOSE_PARENS_MINUS
274 %token DEFAULT_OPEN_PARENS
275 %token GENERIC_DIMENSION
277 /* Add precedence rules to solve dangling else s/r conflict */
286 %left OP_SHIFT_LEFT OP_SHIFT_RIGHT
288 %left STAR DIV PERCENT
289 %right BANG CARRET UMINUS
290 %nonassoc OP_INC OP_DEC
292 %left OPEN_BRACKET OPEN_BRACE
296 %start compilation_unit
300 : outer_declarations opt_EOF
301 | outer_declarations global_attributes opt_EOF
302 | global_attributes opt_EOF
303 | opt_EOF /* allow empty files */
309 Lexer.check_incorrect_doc_comment ();
313 Lexer.check_incorrect_doc_comment ();
319 | outer_declarations outer_declaration
323 : extern_alias_directive
325 | namespace_member_declaration
328 extern_alias_directives
329 : extern_alias_directive
330 | extern_alias_directives extern_alias_directive;
332 extern_alias_directive
333 : EXTERN IDENTIFIER IDENTIFIER SEMICOLON
335 LocatedToken lt = (LocatedToken) $2;
338 Report.Error (1003, lt.Location, "'alias' expected");
339 } else if (RootContext.Version == LanguageVersion.ISO_1) {
340 Report.FeatureIsNotStandardized (lt.Location, "external alias");
342 lt = (LocatedToken) $3;
343 current_namespace.UsingExternalAlias (lt.Value, lt.Location);
350 | using_directives using_directive
354 : using_alias_directive
356 if (RootContext.Documentation != null)
357 Lexer.doc_state = XmlCommentState.Allowed;
359 | using_namespace_directive
361 if (RootContext.Documentation != null)
362 Lexer.doc_state = XmlCommentState.Allowed;
366 using_alias_directive
367 : USING IDENTIFIER ASSIGN
368 namespace_or_type_name SEMICOLON
370 LocatedToken lt = (LocatedToken) $2;
371 current_namespace.UsingAlias (lt.Value, (MemberName) $4, (Location) $1);
374 CheckIdentifierToken (yyToken, GetLocation ($2));
378 using_namespace_directive
379 : USING namespace_name SEMICOLON
381 current_namespace.Using ((MemberName) $2, (Location) $1);
386 // Strictly speaking, namespaces don't have attributes but
387 // we parse global attributes along with namespace declarations and then
390 namespace_declaration
391 : opt_attributes NAMESPACE namespace_or_type_name
393 MemberName name = (MemberName) $3;
396 Report.Error(1671, name.Location, "A namespace declaration cannot have modifiers or attributes");
399 if (name.TypeArguments != null)
400 syntax_error (lexer.Location, "namespace name expected");
402 current_namespace = new NamespaceEntry (
403 current_namespace, file, name.GetName (), name.Location);
405 namespace_body opt_semicolon
407 current_namespace = current_namespace.Parent;
422 : namespace_or_type_name {
423 MemberName name = (MemberName) $1;
425 if (name.TypeArguments != null)
426 syntax_error (lexer.Location, "namespace name expected");
435 if (RootContext.Documentation != null)
436 Lexer.doc_state = XmlCommentState.Allowed;
438 opt_extern_alias_directives
440 opt_namespace_member_declarations
449 opt_extern_alias_directives
451 | extern_alias_directives
454 opt_namespace_member_declarations
456 | namespace_member_declarations
459 namespace_member_declarations
460 : namespace_member_declaration
461 | namespace_member_declarations namespace_member_declaration
464 namespace_member_declaration
468 DeclSpace ds = (DeclSpace)$1;
470 if ((ds.ModFlags & (Modifiers.PRIVATE|Modifiers.PROTECTED)) != 0){
471 Report.Error (1527, ds.Location,
472 "Namespace elements cannot be explicitly declared as private, protected or protected internal");
475 current_namespace.DeclarationFound = true;
477 | namespace_declaration {
478 current_namespace.DeclarationFound = true;
481 | field_declaration {
482 Report.Error (116, ((MemberCore) $1).Location, "A namespace can only contain types and namespace declarations");
484 | method_declaration {
485 Report.Error (116, ((MemberCore) $1).Location, "A namespace can only contain types and namespace declarations");
492 | interface_declaration
494 | delegate_declaration
496 // Enable this when we have handled all errors, because this acts as a generic fallback
499 // Console.WriteLine ("Token=" + yyToken);
500 // Report.Error (1518, GetLocation ($1), "Expected class, struct, interface, enum or delegate");
512 CodeGen.Assembly.AddAttributes (((Attributes)$1).Attrs);
520 global_attrs_enabled = false;
525 global_attrs_enabled = false;
534 ArrayList sect = (ArrayList) $1;
536 if (global_attrs_enabled) {
537 if (current_attr_target == "module") {
538 CodeGen.Module.AddAttributes (sect);
540 } else if (current_attr_target != null && current_attr_target.Length > 0) {
541 CodeGen.Assembly.AddAttributes (sect);
544 $$ = new Attributes (sect);
547 if (RootContext.Documentation != null) {
548 Lexer.check_incorrect_doc_comment ();
550 XmlCommentState.Allowed;
554 $$ = new Attributes (sect);
556 current_attr_target = null;
558 | attribute_sections attribute_section
560 Attributes attrs = $1 as Attributes;
561 ArrayList sect = (ArrayList) $2;
563 if (global_attrs_enabled) {
564 if (current_attr_target == "module") {
565 CodeGen.Module.AddAttributes (sect);
567 } else if (current_attr_target == "assembly") {
568 CodeGen.Assembly.AddAttributes (sect);
572 attrs = new Attributes (sect);
574 attrs.AddAttributes (sect);
578 attrs = new Attributes (sect);
580 attrs.AddAttributes (sect);
583 current_attr_target = null;
588 : OPEN_BRACKET attribute_target_specifier attribute_list opt_comma CLOSE_BRACKET
592 | OPEN_BRACKET attribute_list opt_comma CLOSE_BRACKET
598 attribute_target_specifier
599 : attribute_target COLON
601 current_attr_target = (string)$1;
609 LocatedToken lt = (LocatedToken) $1;
610 CheckAttributeTarget (lt.Value, lt.Location);
611 $$ = lt.Value; // Location won't be required anymore.
613 | EVENT { $$ = "event"; }
614 | RETURN { $$ = "return"; }
620 ArrayList attrs = new ArrayList (4);
626 | attribute_list COMMA attribute
628 ArrayList attrs = (ArrayList) $1;
636 : attribute_name opt_attribute_arguments
638 MemberName mname = (MemberName) $1;
639 if (mname.IsGeneric) {
640 Report.Error (404, lexer.Location,
641 "'<' unexpected: attributes cannot be generic");
644 ArrayList arguments = (ArrayList) $2;
645 MemberName left = mname.Left;
646 string identifier = mname.Name;
648 Expression left_expr = left == null ? null : left.GetTypeExpression ();
650 if (current_attr_target == "assembly" || current_attr_target == "module")
651 // FIXME: supply "nameEscaped" parameter here.
652 $$ = new GlobalAttribute (current_namespace, current_attr_target,
653 left_expr, identifier, arguments, mname.Location, lexer.IsEscapedIdentifier (mname.Location));
655 $$ = new Attribute (current_attr_target, left_expr, identifier, arguments, mname.Location, lexer.IsEscapedIdentifier (mname.Location));
660 : namespace_or_type_name { /* reserved attribute name or identifier: 17.4 */ }
663 opt_attribute_arguments
664 : /* empty */ { $$ = null; }
665 | OPEN_PARENS attribute_arguments CLOSE_PARENS
673 : opt_positional_argument_list
678 ArrayList args = new ArrayList (4);
684 | positional_argument_list COMMA named_argument_list
686 ArrayList args = new ArrayList (4);
692 | named_argument_list
694 ArrayList args = new ArrayList (4);
703 opt_positional_argument_list
704 : /* empty */ { $$ = null; }
705 | positional_argument_list
708 positional_argument_list
711 ArrayList args = new ArrayList (4);
712 args.Add (new Argument ((Expression) $1, Argument.AType.Expression));
716 | positional_argument_list COMMA expression
718 ArrayList args = (ArrayList) $1;
719 args.Add (new Argument ((Expression) $3, Argument.AType.Expression));
728 ArrayList args = new ArrayList (4);
733 | named_argument_list COMMA named_argument
735 ArrayList args = (ArrayList) $1;
740 | named_argument_list COMMA expression
742 Report.Error (1016, ((Expression) $3).Location, "Named attribute argument expected");
748 : IDENTIFIER ASSIGN expression
750 // FIXME: keep location
751 $$ = new DictionaryEntry (
752 ((LocatedToken) $1).Value,
753 new Argument ((Expression) $3, Argument.AType.Expression));
759 : OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
762 opt_class_member_declarations
764 | class_member_declarations
767 class_member_declarations
768 : class_member_declaration
769 | class_member_declarations
770 class_member_declaration
773 class_member_declaration
774 : constant_declaration // done
775 | field_declaration // done
776 | method_declaration // done
777 | property_declaration // done
778 | event_declaration // done
779 | indexer_declaration // done
780 | operator_declaration // done
781 | constructor_declaration // done
782 | destructor_declaration // done
792 lexer.ConstraintsParsing = true;
796 MemberName name = MakeName ((MemberName) $6);
798 ClassPart part = PartialContainer.CreatePart (
799 current_namespace, current_class, name, (int) $2,
800 (Attributes) $1, Kind.Struct, (Location) $3);
802 current_container = part.PartialContainer;
803 current_class = part;
805 current_class = new Struct (
806 current_namespace, current_class, name, (int) $2,
809 current_container.AddClassOrStruct (current_class);
810 current_container = current_class;
811 RootContext.Tree.RecordDecl (current_namespace.NS, name, current_class);
815 opt_type_parameter_constraints_clauses
817 lexer.ConstraintsParsing = false;
820 current_class.Bases = (ArrayList) $8;
822 current_class.SetParameterInfo ((ArrayList) $9);
824 if (RootContext.Documentation != null)
825 current_class.DocComment = Lexer.consume_doc_comment ();
829 if (RootContext.Documentation != null)
830 Lexer.doc_state = XmlCommentState.Allowed;
834 $$ = pop_current_class ();
836 | opt_attributes opt_modifiers opt_partial STRUCT error {
837 CheckIdentifierToken (yyToken, GetLocation ($5));
844 if (RootContext.Documentation != null)
845 Lexer.doc_state = XmlCommentState.Allowed;
847 opt_struct_member_declarations CLOSE_BRACE
850 opt_struct_member_declarations
852 | struct_member_declarations
855 struct_member_declarations
856 : struct_member_declaration
857 | struct_member_declarations struct_member_declaration
860 struct_member_declaration
861 : constant_declaration
864 | property_declaration
866 | indexer_declaration
867 | operator_declaration
868 | constructor_declaration
872 * This is only included so we can flag error 575:
873 * destructors only allowed on class types
875 | destructor_declaration
886 int modflags = (int) $2;
887 foreach (VariableDeclaration constant in (ArrayList) $5){
888 Location l = constant.Location;
889 if ((modflags & Modifiers.STATIC) != 0) {
890 Report.Error (504, l, "The constant `{0}' cannot be marked static", current_container.GetSignatureForError () + '.' + (string) constant.identifier);
894 Const c = new Const (
895 current_class, (Expression) $4, (string) constant.identifier,
896 (Expression) constant.expression_or_array_initializer, modflags,
899 if (RootContext.Documentation != null) {
900 c.DocComment = Lexer.consume_doc_comment ();
901 Lexer.doc_state = XmlCommentState.Allowed;
903 current_container.AddConstant (c);
909 : constant_declarator
911 ArrayList constants = new ArrayList (4);
916 | constant_declarators COMMA constant_declarator
919 ArrayList constants = (ArrayList) $1;
926 : IDENTIFIER ASSIGN constant_expression
928 $$ = new VariableDeclaration ((LocatedToken) $1, $3);
932 // A const field requires a value to be provided
933 Report.Error (145, ((LocatedToken) $1).Location, "A const field requires a value to be provided");
945 Expression type = (Expression) $3;
948 foreach (VariableDeclaration var in (ArrayList) $4){
949 Field field = new Field (current_class, type, mod, var.identifier,
950 (Attributes) $1, var.Location);
952 field.Initializer = var.expression_or_array_initializer;
954 if (RootContext.Documentation != null) {
955 field.DocComment = Lexer.consume_doc_comment ();
956 Lexer.doc_state = XmlCommentState.Allowed;
958 current_container.AddField (field);
959 $$ = field; // FIXME: might be better if it points to the top item
966 fixed_variable_declarators
969 Expression type = (Expression) $4;
972 foreach (VariableDeclaration var in (ArrayList) $5) {
973 FixedField field = new FixedField (current_class, type, mod, var.identifier,
974 (Expression)var.expression_or_array_initializer, (Attributes) $1, var.Location);
976 if (RootContext.Documentation != null) {
977 field.DocComment = Lexer.consume_doc_comment ();
978 Lexer.doc_state = XmlCommentState.Allowed;
980 current_container.AddField (field);
981 $$ = field; // FIXME: might be better if it points to the top item
989 Report.Error (670, (Location) $3, "Fields cannot have void type");
993 fixed_variable_declarators
994 : fixed_variable_declarator
996 ArrayList decl = new ArrayList (2);
1000 | fixed_variable_declarators COMMA fixed_variable_declarator
1002 ArrayList decls = (ArrayList) $1;
1008 fixed_variable_declarator
1009 : IDENTIFIER OPEN_BRACKET expression CLOSE_BRACKET
1011 $$ = new VariableDeclaration ((LocatedToken) $1, $3);
1013 | IDENTIFIER OPEN_BRACKET CLOSE_BRACKET
1015 Report.Error (443, lexer.Location, "Value or constant expected");
1016 $$ = new VariableDeclaration ((LocatedToken) $1, null);
1020 variable_declarators
1021 : variable_declarator
1023 ArrayList decl = new ArrayList (4);
1028 | variable_declarators COMMA variable_declarator
1030 ArrayList decls = (ArrayList) $1;
1037 : IDENTIFIER ASSIGN variable_initializer
1039 $$ = new VariableDeclaration ((LocatedToken) $1, $3);
1043 $$ = new VariableDeclaration ((LocatedToken) $1, null);
1045 | IDENTIFIER OPEN_BRACKET opt_expression CLOSE_BRACKET
1047 Report.Error (650, ((LocatedToken) $1).Location, "Syntax error, bad array declarator. To declare a managed array the rank specifier precedes the variable's identifier. " +
1048 "To declare a fixed size buffer field, use the fixed keyword before the field type");
1053 variable_initializer
1062 | STACKALLOC type OPEN_BRACKET expression CLOSE_BRACKET
1064 $$ = new StackAlloc ((Expression) $2, (Expression) $4, (Location) $1);
1068 Report.Error (1575, (Location) $1, "A stackalloc expression requires [] after type");
1075 iterator_container = (IIteratorContainer) $1;
1076 if (RootContext.Documentation != null)
1077 Lexer.doc_state = XmlCommentState.NotAllowed;
1081 Method method = (Method) $1;
1082 method.Block = (ToplevelBlock) $3;
1083 current_container.AddMethod (method);
1085 current_local_parameters = null;
1086 iterator_container = null;
1088 if (RootContext.Documentation != null)
1089 Lexer.doc_state = XmlCommentState.Allowed;
1102 Report.Error (1585, lexer.Location,
1103 "Member modifier `{0}' must precede the member type and name",
1104 Modifiers.Name (i));
1115 type namespace_or_type_name
1116 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1118 lexer.ConstraintsParsing = true;
1120 opt_type_parameter_constraints_clauses
1122 lexer.ConstraintsParsing = false;
1124 MemberName name = (MemberName) $4;
1126 if ($9 != null && name.TypeArguments == null)
1127 Report.Error (80, lexer.Location,
1128 "Constraints are not allowed on non-generic declarations");
1132 GenericMethod generic = null;
1133 if (name.TypeArguments != null) {
1134 generic = new GenericMethod (current_namespace, current_class, name,
1135 (Expression) $3, (Parameters) $6);
1137 generic.SetParameterInfo ((ArrayList) $9);
1140 method = new Method (current_class, generic, (Expression) $3, (int) $2, false,
1141 name, (Parameters) $6, (Attributes) $1);
1143 current_local_parameters = (Parameters) $6;
1145 if (RootContext.Documentation != null)
1146 method.DocComment = Lexer.consume_doc_comment ();
1152 VOID namespace_or_type_name
1153 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1155 lexer.ConstraintsParsing = true;
1157 opt_type_parameter_constraints_clauses
1159 lexer.ConstraintsParsing = false;
1161 MemberName name = (MemberName) $4;
1163 if ($9 != null && name.TypeArguments == null)
1164 Report.Error (80, lexer.Location,
1165 "Constraints are not allowed on non-generic declarations");
1168 GenericMethod generic = null;
1169 if (name.TypeArguments != null) {
1170 generic = new GenericMethod (current_namespace, current_class, name,
1171 TypeManager.system_void_expr, (Parameters) $6);
1173 generic.SetParameterInfo ((ArrayList) $9);
1176 method = new Method (current_class, generic, TypeManager.system_void_expr,
1177 (int) $2, false, name, (Parameters) $6, (Attributes) $1);
1179 current_local_parameters = (Parameters) $6;
1181 if (RootContext.Documentation != null)
1182 method.DocComment = Lexer.consume_doc_comment ();
1189 modifiers namespace_or_type_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1191 MemberName name = (MemberName) $5;
1192 Report.Error (1585, name.Location,
1193 "Member modifier `{0}' must precede the member type and name", Modifiers.Name ((int) $4));
1195 Method method = new Method (current_class, null, TypeManager.system_void_expr,
1196 0, false, name, (Parameters) $6, (Attributes) $1);
1198 current_local_parameters = (Parameters) $6;
1200 if (RootContext.Documentation != null)
1201 method.DocComment = Lexer.consume_doc_comment ();
1209 | SEMICOLON { $$ = null; }
1212 opt_formal_parameter_list
1213 : /* empty */ { $$ = Parameters.EmptyReadOnlyParameters; }
1214 | formal_parameter_list
1217 formal_parameter_list
1220 ArrayList pars_list = (ArrayList) $1;
1222 Parameter [] pars = new Parameter [pars_list.Count];
1223 pars_list.CopyTo (pars);
1225 $$ = new Parameters (pars);
1227 | fixed_parameters COMMA parameter_array
1229 ArrayList pars_list = (ArrayList) $1;
1232 Parameter [] pars = new Parameter [pars_list.Count];
1233 pars_list.CopyTo (pars);
1235 $$ = new Parameters (pars);
1237 | fixed_parameters COMMA ARGLIST
1239 ArrayList pars_list = (ArrayList) $1;
1240 //pars_list.Add (new ArglistParameter (GetLocation ($3)));
1242 Parameter [] pars = new Parameter [pars_list.Count];
1243 pars_list.CopyTo (pars);
1245 $$ = new Parameters (pars, true);
1247 | parameter_array COMMA fixed_parameters
1250 Report.Error (231, ((Parameter) $1).Location, "A params parameter must be the last parameter in a formal parameter list");
1253 | ARGLIST COMMA fixed_parameters
1255 Report.Error (257, (Location) $1, "An __arglist parameter must be the last parameter in a formal parameter list");
1260 $$ = new Parameters (new Parameter[] { (Parameter) $1 } );
1264 $$ = new Parameters (new Parameter[0], true);
1271 ArrayList pars = new ArrayList (4);
1276 | fixed_parameters COMMA fixed_parameter
1278 ArrayList pars = (ArrayList) $1;
1287 opt_parameter_modifier
1291 LocatedToken lt = (LocatedToken) $4;
1292 $$ = new Parameter ((Expression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1295 opt_parameter_modifier
1297 IDENTIFIER OPEN_BRACKET CLOSE_BRACKET
1299 LocatedToken lt = (LocatedToken) $4;
1300 Report.Error (1552, lt.Location, "Array type specifier, [], must appear before parameter name");
1304 opt_parameter_modifier
1307 Report.Error (1001, GetLocation ($3), "Identifier expected");
1311 opt_parameter_modifier
1314 CheckIdentifierToken (yyToken, GetLocation ($4));
1318 opt_parameter_modifier
1324 LocatedToken lt = (LocatedToken) $4;
1325 Report.Error (241, lt.Location, "Default parameter specifiers are not permitted");
1330 opt_parameter_modifier
1331 : /* empty */ { $$ = Parameter.Modifier.NONE; }
1332 | parameter_modifier
1336 : REF { $$ = Parameter.Modifier.REF; }
1337 | OUT { $$ = Parameter.Modifier.OUT; }
1341 : opt_attributes PARAMS type IDENTIFIER
1343 LocatedToken lt = (LocatedToken) $4;
1344 $$ = new ParamsParameter ((Expression) $3, lt.Value, (Attributes) $1, lt.Location);
1345 note ("type must be a single-dimension array type");
1347 | opt_attributes PARAMS parameter_modifier type IDENTIFIER
1349 Report.Error (1611, (Location) $2, "The params parameter cannot be declared as ref or out");
1352 | opt_attributes PARAMS type error {
1353 CheckIdentifierToken (yyToken, GetLocation ($4));
1358 property_declaration
1362 namespace_or_type_name
1364 if (RootContext.Documentation != null)
1365 tmpComment = Lexer.consume_doc_comment ();
1369 implicit_value_parameter_type = (Expression) $3;
1371 lexer.PropertyParsing = true;
1373 accessor_declarations
1375 lexer.PropertyParsing = false;
1376 has_get = has_set = false;
1384 Pair pair = (Pair) $8;
1385 Accessor get_block = (Accessor) pair.First;
1386 Accessor set_block = (Accessor) pair.Second;
1388 MemberName name = (MemberName) $4;
1390 if (name.TypeArguments != null)
1391 syntax_error (lexer.Location, "a property can't have type arguments");
1393 prop = new Property (current_class, (Expression) $3, (int) $2, false,
1394 name, (Attributes) $1, get_block, set_block);
1396 current_container.AddProperty (prop);
1397 implicit_value_parameter_type = null;
1399 if (RootContext.Documentation != null)
1400 prop.DocComment = ConsumeStoredComment ();
1405 accessor_declarations
1406 : get_accessor_declaration
1408 $$ = new Pair ($1, null);
1410 | get_accessor_declaration accessor_declarations
1412 Pair pair = (Pair) $2;
1416 | set_accessor_declaration
1418 $$ = new Pair (null, $1);
1420 | set_accessor_declaration accessor_declarations
1422 Pair pair = (Pair) $2;
1428 Report.Error (1014, GetLocation ($1), "A get or set accessor expected");
1433 get_accessor_declaration
1434 : opt_attributes opt_modifiers GET
1436 // If this is not the case, then current_local_parameters has already
1437 // been set in indexer_declaration
1438 if (parsing_indexer == false)
1439 current_local_parameters = null;
1441 current_local_parameters = indexer_parameters;
1442 lexer.PropertyParsing = false;
1444 iterator_container = SimpleIteratorContainer.GetSimple ();
1449 Report.Error (1007, (Location) $3, "Property accessor already defined");
1452 Accessor accessor = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, (Location) $3);
1454 current_local_parameters = null;
1455 lexer.PropertyParsing = true;
1457 if (SimpleIteratorContainer.Simple.Yields)
1458 accessor.SetYields ();
1460 iterator_container = null;
1462 if (RootContext.Documentation != null)
1463 if (Lexer.doc_state == XmlCommentState.Error)
1464 Lexer.doc_state = XmlCommentState.NotAllowed;
1470 set_accessor_declaration
1471 : opt_attributes opt_modifiers SET
1474 Parameter implicit_value_parameter = new Parameter (
1475 implicit_value_parameter_type, "value",
1476 Parameter.Modifier.NONE, null, (Location) $3);
1478 if (parsing_indexer == false) {
1479 args = new Parameter [1];
1480 args [0] = implicit_value_parameter;
1481 current_local_parameters = new Parameters (args);
1483 Parameter [] fpars = indexer_parameters.FixedParameters;
1486 int count = fpars.Length;
1488 args = new Parameter [count + 1];
1489 fpars.CopyTo (args, 0);
1490 args [count] = implicit_value_parameter;
1493 current_local_parameters = new Parameters (
1497 lexer.PropertyParsing = false;
1499 iterator_container = SimpleIteratorContainer.GetSimple ();
1504 Report.Error (1007, ((LocatedToken) $3).Location, "Property accessor already defined");
1507 Accessor accessor = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, (Location) $3);
1509 current_local_parameters = null;
1510 lexer.PropertyParsing = true;
1512 if (SimpleIteratorContainer.Simple.Yields)
1513 accessor.SetYields ();
1515 iterator_container = null;
1517 if (RootContext.Documentation != null
1518 && Lexer.doc_state == XmlCommentState.Error)
1519 Lexer.doc_state = XmlCommentState.NotAllowed;
1527 | SEMICOLON { $$ = null; }
1530 interface_declaration
1536 lexer.ConstraintsParsing = true;
1540 MemberName name = MakeName ((MemberName) $6);
1543 ClassPart part = PartialContainer.CreatePart (
1544 current_namespace, current_class, name, (int) $2,
1545 (Attributes) $1, Kind.Interface, (Location) $3);
1547 current_container = part.PartialContainer;
1548 current_class = part;
1550 current_class = new Interface (
1551 current_namespace, current_class, name, (int) $2,
1554 current_container.AddInterface (current_class);
1555 current_container = current_class;
1556 RootContext.Tree.RecordDecl (current_namespace.NS, name, current_class);
1560 opt_type_parameter_constraints_clauses
1562 lexer.ConstraintsParsing = false;
1565 current_class.Bases = (ArrayList) $8;
1567 current_class.SetParameterInfo ((ArrayList) $9);
1569 if (RootContext.Documentation != null) {
1570 current_class.DocComment = Lexer.consume_doc_comment ();
1571 Lexer.doc_state = XmlCommentState.Allowed;
1576 if (RootContext.Documentation != null)
1577 Lexer.doc_state = XmlCommentState.Allowed;
1581 $$ = pop_current_class ();
1583 | opt_attributes opt_modifiers opt_partial INTERFACE error {
1584 CheckIdentifierToken (yyToken, GetLocation ($5));
1590 opt_interface_member_declarations
1594 opt_interface_member_declarations
1596 | interface_member_declarations
1599 interface_member_declarations
1600 : interface_member_declaration
1601 | interface_member_declarations interface_member_declaration
1604 interface_member_declaration
1605 : interface_method_declaration
1610 Method m = (Method) $1;
1612 if (m.IsExplicitImpl)
1613 Report.Error (541, m.Location, "`{0}': explicit interface declaration can only be declared in a class or struct",
1614 m.GetSignatureForError ());
1616 current_container.AddMethod (m);
1618 if (RootContext.Documentation != null)
1619 Lexer.doc_state = XmlCommentState.Allowed;
1621 | interface_property_declaration
1626 Property p = (Property) $1;
1628 if (p.IsExplicitImpl)
1629 Report.Error (541, p.Location, "`{0}': explicit interface declaration can only be declared in a class or struct",
1630 p.GetSignatureForError ());
1632 current_container.AddProperty (p);
1634 if (RootContext.Documentation != null)
1635 Lexer.doc_state = XmlCommentState.Allowed;
1637 | interface_event_declaration
1640 Event e = (Event) $1;
1642 if (e.IsExplicitImpl)
1643 Report.Error (541, e.Location, "`{0}': explicit interface declaration can only be declared in a class or struct",
1644 e.GetSignatureForError ());
1646 current_container.AddEvent (e);
1649 if (RootContext.Documentation != null)
1650 Lexer.doc_state = XmlCommentState.Allowed;
1652 | interface_indexer_declaration
1657 Indexer i = (Indexer) $1;
1659 if (i.IsExplicitImpl)
1660 Report.Error (541, i.Location, "`{0}': explicit interface declaration can only be declared in a class or struct",
1661 i.GetSignatureForError ());
1663 current_container.AddIndexer (i);
1665 if (RootContext.Documentation != null)
1666 Lexer.doc_state = XmlCommentState.Allowed;
1668 | delegate_declaration
1671 Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
1672 ((MemberCore)$1).GetSignatureForError ());
1678 Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
1679 ((MemberCore)$1).GetSignatureForError ());
1682 | struct_declaration
1685 Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
1686 ((MemberCore)$1).GetSignatureForError ());
1692 Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
1693 ((MemberCore)$1).GetSignatureForError ());
1696 | interface_declaration
1699 Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
1700 ((MemberCore)$1).GetSignatureForError ());
1703 | constant_declaration
1705 Report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
1713 val = Modifiers.Check (Modifiers.NEW | Modifiers.UNSAFE, val, 0, GetLocation ($1));
1718 interface_method_declaration_body
1721 lexer.ConstraintsParsing = false;
1723 opt_statement_list CLOSE_BRACE
1725 Report.Error (531, lexer.Location,
1726 "'{0}': interface members cannot have a definition", ((MemberName) $-1).ToString ());
1732 interface_method_declaration
1733 : opt_attributes opt_new type namespace_or_type_name
1734 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1736 lexer.ConstraintsParsing = true;
1738 opt_type_parameter_constraints_clauses
1740 // Refer to the name as $-1 in interface_method_declaration_body
1743 interface_method_declaration_body
1745 lexer.ConstraintsParsing = false;
1747 MemberName name = (MemberName) $4;
1749 if ($9 != null && name.TypeArguments == null)
1750 Report.Error (80, lexer.Location,
1751 "Constraints are not allowed on non-generic declarations");
1753 GenericMethod generic = null;
1754 if (name.TypeArguments != null) {
1755 generic = new GenericMethod (current_namespace, current_class, name,
1756 (Expression) $3, (Parameters) $6);
1758 generic.SetParameterInfo ((ArrayList) $9);
1761 $$ = new Method (current_class, generic, (Expression) $3, (int) $2, true, name,
1762 (Parameters) $6, (Attributes) $1);
1763 if (RootContext.Documentation != null)
1764 ((Method) $$).DocComment = Lexer.consume_doc_comment ();
1766 | opt_attributes opt_new VOID namespace_or_type_name
1767 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1769 lexer.ConstraintsParsing = true;
1771 opt_type_parameter_constraints_clauses
1775 interface_method_declaration_body
1777 lexer.ConstraintsParsing = false;
1779 MemberName name = (MemberName) $4;
1781 if ($9 != null && name.TypeArguments == null)
1782 Report.Error (80, lexer.Location,
1783 "Constraints are not allowed on non-generic declarations");
1785 GenericMethod generic = null;
1786 if (name.TypeArguments != null) {
1787 generic = new GenericMethod (current_namespace, current_class, name,
1788 TypeManager.system_void_expr, (Parameters) $6);
1790 generic.SetParameterInfo ((ArrayList) $9);
1793 $$ = new Method (current_class, generic, TypeManager.system_void_expr, (int) $2,
1794 true, name, (Parameters) $6, (Attributes) $1);
1795 if (RootContext.Documentation != null)
1796 ((Method) $$).DocComment = Lexer.consume_doc_comment ();
1800 interface_property_declaration
1805 { lexer.PropertyParsing = true; }
1806 accessor_declarations
1808 has_get = has_set = false;
1809 lexer.PropertyParsing = false;
1813 LocatedToken lt = (LocatedToken) $4;
1814 MemberName name = new MemberName (lt.Value, lt.Location);
1816 if ($3 == TypeManager.system_void_expr) {
1817 Report.Error (547, lt.Location, "`{0}': property or indexer cannot have void type", lt.Value);
1823 p = new Property (current_class, (Expression) $3, (int) $2, true,
1824 name, (Attributes) $1,
1827 Report.Error (548, p.Location, "`{0}': property or indexer must have at least one accessor", p.GetSignatureForError ());
1831 Pair pair = (Pair) $7;
1832 p = new Property (current_class, (Expression) $3, (int) $2, true,
1833 name, (Attributes) $1,
1834 (Accessor)pair.First, (Accessor)pair.Second);
1836 if (pair.First != null && ((Accessor)(pair.First)).Block != null) {
1837 Report.Error (531, p.Location, "`{0}.get': interface members cannot have a definition", p.GetSignatureForError ());
1842 if (pair.Second != null && ((Accessor)(pair.Second)).Block != null) {
1843 Report.Error (531, p.Location, "`{0}.set': interface members cannot have a definition", p.GetSignatureForError ());
1848 if (RootContext.Documentation != null)
1849 p.DocComment = Lexer.consume_doc_comment ();
1856 CheckIdentifierToken (yyToken, GetLocation ($4));
1862 interface_event_declaration
1863 : opt_attributes opt_new EVENT type IDENTIFIER SEMICOLON
1865 LocatedToken lt = (LocatedToken) $5;
1866 $$ = new EventField (current_class, (Expression) $4, (int) $2, true,
1867 new MemberName (lt.Value, lt.Location),
1869 if (RootContext.Documentation != null)
1870 ((EventField) $$).DocComment = Lexer.consume_doc_comment ();
1872 | opt_attributes opt_new EVENT type error {
1873 CheckIdentifierToken (yyToken, GetLocation ($5));
1876 | opt_attributes opt_new EVENT type IDENTIFIER ASSIGN {
1877 LocatedToken lt = (LocatedToken) $5;
1878 Report.Error (68, lt.Location, "`{0}.{1}': event in interface cannot have initializer", current_container.Name, lt.Value);
1881 | opt_attributes opt_new EVENT type IDENTIFIER OPEN_BRACE
1883 lexer.EventParsing = true;
1885 event_accessor_declarations
1887 lexer.EventParsing = false;
1890 Report.Error (69, (Location) $3, "Event in interface cannot have add or remove accessors");
1895 interface_indexer_declaration
1896 : opt_attributes opt_new type THIS
1897 OPEN_BRACKET formal_parameter_list CLOSE_BRACKET
1899 { lexer.PropertyParsing = true; }
1900 accessor_declarations
1902 has_get = has_set = false;
1903 lexer.PropertyParsing = false;
1909 i = new Indexer (current_class, (Expression) $3,
1910 new MemberName (TypeContainer.DefaultIndexerName, (Location) $4),
1911 (int) $2, true, (Parameters) $6, (Attributes) $1,
1914 Report.Error (548, i.Location, "`{0}': property or indexer must have at least one accessor", i.GetSignatureForError ());
1918 Pair pair = (Pair) $10;
1919 i = new Indexer (current_class, (Expression) $3,
1920 new MemberName (TypeContainer.DefaultIndexerName, (Location) $4),
1921 (int) $2, true, (Parameters) $6, (Attributes) $1,
1922 (Accessor)pair.First, (Accessor)pair.Second);
1924 if (pair.First != null && ((Accessor)(pair.First)).Block != null) {
1925 Report.Error (531, i.Location, "`{0}.get': interface members cannot have a definition", i.GetSignatureForError ());
1930 if (pair.Second != null && ((Accessor)(pair.Second)).Block != null) {
1931 Report.Error (531, i.Location, "`{0}.set': interface members cannot have a definition", i.GetSignatureForError ());
1936 if (RootContext.Documentation != null)
1937 i.DocComment = ConsumeStoredComment ();
1943 operator_declaration
1944 : opt_attributes opt_modifiers operator_declarator
1946 iterator_container = SimpleIteratorContainer.GetSimple ();
1953 OperatorDeclaration decl = (OperatorDeclaration) $3;
1955 Parameter [] param_list = new Parameter [decl.arg2type != null ? 2 : 1];
1957 param_list[0] = new Parameter (decl.arg1type, decl.arg1name, Parameter.Modifier.NONE, null, decl.location);
1958 if (decl.arg2type != null)
1959 param_list[1] = new Parameter (decl.arg2type, decl.arg2name, Parameter.Modifier.NONE, null, decl.location);
1961 Operator op = new Operator (
1962 current_class, decl.optype, decl.ret_type, (int) $2,
1963 new Parameters (param_list),
1964 (ToplevelBlock) $5, (Attributes) $1, decl.location);
1966 if (RootContext.Documentation != null) {
1967 op.DocComment = tmpComment;
1968 Lexer.doc_state = XmlCommentState.Allowed;
1971 if (SimpleIteratorContainer.Simple.Yields)
1974 // Note again, checking is done in semantic analysis
1975 current_container.AddOperator (op);
1977 current_local_parameters = null;
1978 iterator_container = null;
1984 | SEMICOLON { $$ = null; }
1987 : type OPERATOR overloadable_operator
1988 OPEN_PARENS type IDENTIFIER CLOSE_PARENS
1990 LocatedToken lt = (LocatedToken) $6;
1991 Operator.OpType op = (Operator.OpType) $3;
1992 CheckUnaryOperator (op, lt.Location);
1994 if (op == Operator.OpType.Addition)
1995 op = Operator.OpType.UnaryPlus;
1997 if (op == Operator.OpType.Subtraction)
1998 op = Operator.OpType.UnaryNegation;
2000 Parameter [] pars = new Parameter [1];
2001 Expression type = (Expression) $5;
2003 pars [0] = new Parameter (type, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
2005 current_local_parameters = new Parameters (pars);
2007 if (RootContext.Documentation != null) {
2008 tmpComment = Lexer.consume_doc_comment ();
2009 Lexer.doc_state = XmlCommentState.NotAllowed;
2012 $$ = new OperatorDeclaration (op, (Expression) $1, type, lt.Value,
2013 null, null, (Location) $2);
2015 | type OPERATOR overloadable_operator
2017 type IDENTIFIER COMMA
2021 LocatedToken ltParam1 = (LocatedToken) $6;
2022 LocatedToken ltParam2 = (LocatedToken) $9;
2023 CheckBinaryOperator ((Operator.OpType) $3, (Location) $2);
2025 Parameter [] pars = new Parameter [2];
2027 Expression typeL = (Expression) $5;
2028 Expression typeR = (Expression) $8;
2030 pars [0] = new Parameter (typeL, ltParam1.Value, Parameter.Modifier.NONE, null, ltParam1.Location);
2031 pars [1] = new Parameter (typeR, ltParam2.Value, Parameter.Modifier.NONE, null, ltParam2.Location);
2033 current_local_parameters = new Parameters (pars);
2035 if (RootContext.Documentation != null) {
2036 tmpComment = Lexer.consume_doc_comment ();
2037 Lexer.doc_state = XmlCommentState.NotAllowed;
2040 $$ = new OperatorDeclaration ((Operator.OpType) $3, (Expression) $1,
2041 typeL, ltParam1.Value,
2042 typeR, ltParam2.Value, (Location) $2);
2044 | conversion_operator_declarator
2045 | type OPERATOR overloadable_operator
2047 type IDENTIFIER COMMA
2048 type IDENTIFIER COMMA
2052 Report.Error (1534, (Location) $2, "Overloaded binary operator `{0}' takes two parameters",
2053 Operator.GetName ((Operator.OpType) $3));
2056 | type OPERATOR overloadable_operator
2057 OPEN_PARENS CLOSE_PARENS
2059 Report.Error (1535, (Location) $2, "Overloaded unary operator `{0}' takes one parameter",
2060 Operator.GetName ((Operator.OpType) $3));
2065 overloadable_operator
2067 : BANG { $$ = Operator.OpType.LogicalNot; }
2068 | TILDE { $$ = Operator.OpType.OnesComplement; }
2069 | OP_INC { $$ = Operator.OpType.Increment; }
2070 | OP_DEC { $$ = Operator.OpType.Decrement; }
2071 | TRUE { $$ = Operator.OpType.True; }
2072 | FALSE { $$ = Operator.OpType.False; }
2073 // Unary and binary:
2074 | PLUS { $$ = Operator.OpType.Addition; }
2075 | MINUS { $$ = Operator.OpType.Subtraction; }
2077 | STAR { $$ = Operator.OpType.Multiply; }
2078 | DIV { $$ = Operator.OpType.Division; }
2079 | PERCENT { $$ = Operator.OpType.Modulus; }
2080 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
2081 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
2082 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
2083 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
2084 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
2085 | OP_EQ { $$ = Operator.OpType.Equality; }
2086 | OP_NE { $$ = Operator.OpType.Inequality; }
2087 | OP_GT { $$ = Operator.OpType.GreaterThan; }
2088 | OP_LT { $$ = Operator.OpType.LessThan; }
2089 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
2090 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
2093 conversion_operator_declarator
2094 : IMPLICIT OPERATOR type OPEN_PARENS type IDENTIFIER CLOSE_PARENS
2096 LocatedToken lt = (LocatedToken) $6;
2097 Parameter [] pars = new Parameter [1];
2099 pars [0] = new Parameter ((Expression) $5, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
2101 current_local_parameters = new Parameters (pars);
2103 if (RootContext.Documentation != null) {
2104 tmpComment = Lexer.consume_doc_comment ();
2105 Lexer.doc_state = XmlCommentState.NotAllowed;
2108 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (Expression) $3, (Expression) $5, lt.Value,
2109 null, null, (Location) $2);
2111 | EXPLICIT OPERATOR type OPEN_PARENS type IDENTIFIER CLOSE_PARENS
2113 LocatedToken lt = (LocatedToken) $6;
2114 Parameter [] pars = new Parameter [1];
2116 pars [0] = new Parameter ((Expression) $5, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
2118 current_local_parameters = new Parameters (pars);
2120 if (RootContext.Documentation != null) {
2121 tmpComment = Lexer.consume_doc_comment ();
2122 Lexer.doc_state = XmlCommentState.NotAllowed;
2125 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (Expression) $3, (Expression) $5, lt.Value,
2126 null, null, (Location) $2);
2130 syntax_error ((Location) $1, "'operator' expected");
2134 syntax_error ((Location) $1, "'operator' expected");
2138 constructor_declaration
2141 constructor_declarator
2144 Constructor c = (Constructor) $3;
2145 c.Block = (ToplevelBlock) $4;
2146 c.OptAttributes = (Attributes) $1;
2147 c.ModFlags = (int) $2;
2149 if (RootContext.Documentation != null)
2150 c.DocComment = ConsumeStoredComment ();
2152 if (c.Name == current_container.Basename){
2153 if ((c.ModFlags & Modifiers.STATIC) != 0){
2154 if ((c.ModFlags & Modifiers.Accessibility) != 0){
2155 Report.Error (515, c.Location,
2156 "`{0}': access modifiers are not allowed on static constructors",
2157 c.GetSignatureForError ());
2160 c.ModFlags = Modifiers.Check (Constructor.AllowedModifiers, (int) $2, Modifiers.PRIVATE, c.Location);
2162 if (c.Initializer != null){
2163 Report.Error (514, c.Location,
2164 "`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
2165 c.GetSignatureForError ());
2168 if (!c.Parameters.Empty){
2169 Report.Error (132, c.Location,
2170 "`{0}': The static constructor must be parameterless", c.GetSignatureForError ());
2173 c.ModFlags = Modifiers.Check (Constructor.AllowedModifiers, (int) $2, Modifiers.PRIVATE, c.Location);
2176 // We let another layer check the validity of the constructor.
2177 //Console.WriteLine ("{0} and {1}", c.Name, current_container.Basename);
2180 current_container.AddConstructor (c);
2182 current_local_parameters = null;
2183 if (RootContext.Documentation != null)
2184 Lexer.doc_state = XmlCommentState.Allowed;
2188 constructor_declarator
2191 if (RootContext.Documentation != null) {
2192 tmpComment = Lexer.consume_doc_comment ();
2193 Lexer.doc_state = XmlCommentState.Allowed;
2196 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2198 current_local_parameters = (Parameters) $4;
2200 opt_constructor_initializer
2202 LocatedToken lt = (LocatedToken) $1;
2203 $$ = new Constructor (current_class, lt.Value, 0, (Parameters) $4,
2204 (ConstructorInitializer) $7, lt.Location);
2210 | SEMICOLON { $$ = null; }
2213 opt_constructor_initializer
2214 : /* empty */ { $$ = null; }
2215 | constructor_initializer
2218 constructor_initializer
2219 : COLON BASE OPEN_PARENS opt_argument_list CLOSE_PARENS
2221 $$ = new ConstructorBaseInitializer ((ArrayList) $4, (Location) $2);
2223 | COLON THIS OPEN_PARENS opt_argument_list CLOSE_PARENS
2225 $$ = new ConstructorThisInitializer ((ArrayList) $4, (Location) $2);
2228 Report.Error (1018, (Location) $1, "Keyword this or base expected");
2234 : /* EMPTY */ { $$ = 0; }
2235 | UNSAFE { $$ = Modifiers.UNSAFE; }
2236 | EXTERN { $$ = Modifiers.EXTERN; }
2239 destructor_declaration
2240 : opt_attributes opt_finalizer TILDE
2242 if (RootContext.Documentation != null) {
2243 tmpComment = Lexer.consume_doc_comment ();
2244 Lexer.doc_state = XmlCommentState.NotAllowed;
2247 IDENTIFIER OPEN_PARENS CLOSE_PARENS block
2249 LocatedToken lt = (LocatedToken) $5;
2250 if (lt.Value != current_container.MemberName.Name){
2251 Report.Error (574, lt.Location, "Name of destructor must match name of class");
2252 } else if (current_container.Kind != Kind.Class){
2253 Report.Error (575, lt.Location, "Only class types can contain destructor");
2255 Location l = lt.Location;
2258 if (!RootContext.StdLib && current_container.Name == "System.Object")
2259 m |= Modifiers.PROTECTED | Modifiers.VIRTUAL;
2261 m |= Modifiers.PROTECTED | Modifiers.OVERRIDE;
2263 Method d = new Destructor (
2264 current_class, TypeManager.system_void_expr, m, "Finalize",
2265 Parameters.EmptyReadOnlyParameters, (Attributes) $1, l);
2266 if (RootContext.Documentation != null)
2267 d.DocComment = ConsumeStoredComment ();
2269 d.Block = (ToplevelBlock) $8;
2270 current_container.AddMethod (d);
2278 EVENT type variable_declarators SEMICOLON
2280 foreach (VariableDeclaration var in (ArrayList) $5) {
2282 MemberName name = new MemberName (var.identifier,
2285 EventField e = new EventField (
2286 current_class, (Expression) $4, (int) $2, false, name,
2289 e.Initializer = var.expression_or_array_initializer;
2291 current_container.AddEvent (e);
2293 if (RootContext.Documentation != null) {
2294 e.DocComment = Lexer.consume_doc_comment ();
2295 Lexer.doc_state = XmlCommentState.Allowed;
2301 EVENT type namespace_or_type_name
2304 implicit_value_parameter_type = (Expression) $4;
2305 lexer.EventParsing = true;
2307 event_accessor_declarations
2309 lexer.EventParsing = false;
2313 MemberName name = (MemberName) $5;
2316 Report.Error (65, (Location) $3, "`{0}.{1}': event property must have both add and remove accessors",
2317 current_container.Name, name.ToString ());
2320 Pair pair = (Pair) $8;
2322 if (name.TypeArguments != null)
2323 syntax_error (lexer.Location, "an event can't have type arguments");
2325 if (pair.First == null || pair.Second == null)
2326 // CS0073 is already reported, so no CS0065 here.
2329 Event e = new EventProperty (
2330 current_class, (Expression) $4, (int) $2, false, name,
2331 (Attributes) $1, (Accessor) pair.First, (Accessor) pair.Second);
2332 if (RootContext.Documentation != null) {
2333 e.DocComment = Lexer.consume_doc_comment ();
2334 Lexer.doc_state = XmlCommentState.Allowed;
2337 current_container.AddEvent (e);
2338 implicit_value_parameter_type = null;
2342 | opt_attributes opt_modifiers EVENT type namespace_or_type_name error {
2343 MemberName mn = (MemberName) $5;
2345 if (mn.Left != null)
2346 Report.Error (71, mn.Location, "An explicit interface implementation of an event must use property syntax");
2348 Report.Error (71, mn.Location, "Event declaration should use property syntax");
2350 if (RootContext.Documentation != null)
2351 Lexer.doc_state = XmlCommentState.Allowed;
2355 event_accessor_declarations
2356 : add_accessor_declaration remove_accessor_declaration
2358 $$ = new Pair ($1, $2);
2360 | remove_accessor_declaration add_accessor_declaration
2362 $$ = new Pair ($2, $1);
2364 | add_accessor_declaration { $$ = null; }
2365 | remove_accessor_declaration { $$ = null; }
2368 Report.Error (1055, GetLocation ($1), "An add or remove accessor expected");
2374 add_accessor_declaration
2375 : opt_attributes ADD
2377 Parameter [] args = new Parameter [1];
2378 Parameter implicit_value_parameter = new Parameter (
2379 implicit_value_parameter_type, "value",
2380 Parameter.Modifier.NONE, null, (Location) $2);
2382 args [0] = implicit_value_parameter;
2384 current_local_parameters = new Parameters (args);
2385 lexer.EventParsing = false;
2389 $$ = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, (Location) $2);
2390 lexer.EventParsing = true;
2392 | opt_attributes ADD error {
2393 Report.Error (73, (Location) $2, "An add or remove accessor must have a body");
2396 | opt_attributes modifiers ADD {
2397 Report.Error (1609, (Location) $3, "Modifiers cannot be placed on event accessor declarations");
2402 remove_accessor_declaration
2403 : opt_attributes REMOVE
2405 Parameter [] args = new Parameter [1];
2406 Parameter implicit_value_parameter = new Parameter (
2407 implicit_value_parameter_type, "value",
2408 Parameter.Modifier.NONE, null, (Location) $2);
2410 args [0] = implicit_value_parameter;
2412 current_local_parameters = new Parameters (args);
2413 lexer.EventParsing = false;
2417 $$ = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, (Location) $2);
2418 lexer.EventParsing = true;
2420 | opt_attributes REMOVE error {
2421 Report.Error (73, (Location) $2, "An add or remove accessor must have a body");
2424 | opt_attributes modifiers REMOVE {
2425 Report.Error (1609, (Location) $3, "Modifiers cannot be placed on event accessor declarations");
2431 : opt_attributes opt_modifiers indexer_declarator
2434 IndexerDeclaration decl = (IndexerDeclaration) $3;
2436 implicit_value_parameter_type = decl.type;
2438 lexer.PropertyParsing = true;
2439 parsing_indexer = true;
2441 indexer_parameters = decl.param_list;
2442 iterator_container = SimpleIteratorContainer.GetSimple ();
2444 accessor_declarations
2446 lexer.PropertyParsing = false;
2447 has_get = has_set = false;
2448 parsing_indexer = false;
2455 // The signature is computed from the signature of the indexer. Look
2456 // at section 3.6 on the spec
2458 IndexerDeclaration decl = (IndexerDeclaration) $3;
2459 Pair pair = (Pair) $6;
2460 Accessor get_block = (Accessor) pair.First;
2461 Accessor set_block = (Accessor) pair.Second;
2464 if (decl.interface_type != null)
2465 name = new MemberName (
2466 decl.interface_type, TypeContainer.DefaultIndexerName, decl.location);
2468 name = new MemberName (TypeContainer.DefaultIndexerName, decl.location);
2470 indexer = new Indexer (current_class, decl.type, name,
2471 (int) $2, false, decl.param_list, (Attributes) $1,
2472 get_block, set_block);
2474 if (RootContext.Documentation != null)
2475 indexer.DocComment = ConsumeStoredComment ();
2477 current_container.AddIndexer (indexer);
2479 current_local_parameters = null;
2480 implicit_value_parameter_type = null;
2481 indexer_parameters = null;
2486 : type THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
2488 Parameters pars = (Parameters) $4;
2489 if (pars.HasArglist) {
2490 // "__arglist is not valid in this context"
2491 Report.Error (1669, (Location) $2, "__arglist is not valid in this context");
2492 } else if (pars.Empty){
2493 Report.Error (1551, (Location) $2, "Indexers must have at least one parameter");
2495 if (RootContext.Documentation != null) {
2496 tmpComment = Lexer.consume_doc_comment ();
2497 Lexer.doc_state = XmlCommentState.Allowed;
2500 $$ = new IndexerDeclaration ((Expression) $1, null, pars, (Location) $2);
2502 | type namespace_or_type_name DOT THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
2504 Parameters pars = (Parameters) $6;
2506 if (pars.HasArglist) {
2507 // "__arglist is not valid in this context"
2508 Report.Error (1669, (Location) $4, "__arglist is not valid in this context");
2509 } else if (pars.Empty){
2510 Report.Error (1551, (Location) $4, "Indexers must have at least one parameter");
2513 MemberName name = (MemberName) $2;
2514 $$ = new IndexerDeclaration ((Expression) $1, name, pars, (Location) $4);
2516 if (RootContext.Documentation != null) {
2517 tmpComment = Lexer.consume_doc_comment ();
2518 Lexer.doc_state = XmlCommentState.Allowed;
2529 if (RootContext.Documentation != null)
2530 enumTypeComment = Lexer.consume_doc_comment ();
2535 LocatedToken lt = (LocatedToken) $5;
2536 Location enum_location = lt.Location;
2539 Report.Error (267, lt.Location, "The partial modifier can only appear immediately before `class', `struct' or `interface'");
2540 break; // assumes that the parser put us in a switch
2543 MemberName name = MakeName (new MemberName (lt.Value, enum_location));
2544 Enum e = new Enum (current_namespace, current_class, (Expression) $6, (int) $2,
2545 name, (Attributes) $1);
2547 if (RootContext.Documentation != null)
2548 e.DocComment = enumTypeComment;
2551 EnumMember em = null;
2552 foreach (VariableDeclaration ev in (ArrayList) $8) {
2553 em = new EnumMember (e, em, (Expression) ev.expression_or_array_initializer,
2554 new MemberName (ev.identifier, ev.Location), ev.OptAttributes);
2556 // if (RootContext.Documentation != null)
2557 em.DocComment = ev.DocComment;
2559 e.AddEnumMember (em);
2562 current_container.AddEnum (e);
2563 RootContext.Tree.RecordDecl (current_namespace.NS, name, e);
2570 : /* empty */ { $$ = TypeManager.system_int32_expr; }
2571 | COLON type { $$ = $2; }
2577 if (RootContext.Documentation != null)
2578 Lexer.doc_state = XmlCommentState.Allowed;
2580 opt_enum_member_declarations
2582 // here will be evaluated after CLOSE_BLACE is consumed.
2583 if (RootContext.Documentation != null)
2584 Lexer.doc_state = XmlCommentState.Allowed;
2592 opt_enum_member_declarations
2593 : /* empty */ { $$ = new ArrayList (4); }
2594 | enum_member_declarations opt_comma { $$ = $1; }
2597 enum_member_declarations
2598 : enum_member_declaration
2600 ArrayList l = new ArrayList (4);
2605 | enum_member_declarations COMMA enum_member_declaration
2607 ArrayList l = (ArrayList) $1;
2615 enum_member_declaration
2616 : opt_attributes IDENTIFIER
2618 VariableDeclaration vd = new VariableDeclaration (
2619 (LocatedToken) $2, null, (Attributes) $1);
2621 if (RootContext.Documentation != null) {
2622 vd.DocComment = Lexer.consume_doc_comment ();
2623 Lexer.doc_state = XmlCommentState.Allowed;
2628 | opt_attributes IDENTIFIER
2630 if (RootContext.Documentation != null) {
2631 tmpComment = Lexer.consume_doc_comment ();
2632 Lexer.doc_state = XmlCommentState.NotAllowed;
2637 VariableDeclaration vd = new VariableDeclaration (
2638 (LocatedToken) $2, $5, (Attributes) $1);
2640 if (RootContext.Documentation != null)
2641 vd.DocComment = ConsumeStoredComment ();
2647 delegate_declaration
2652 lexer.ConstraintsParsing = true;
2655 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2657 MemberName name = MakeName ((MemberName) $6);
2658 Delegate del = new Delegate (current_namespace, current_class, (Expression) $5,
2659 (int) $2, name, (Parameters) $8, (Attributes) $1);
2661 if (RootContext.Documentation != null) {
2662 del.DocComment = Lexer.consume_doc_comment ();
2663 Lexer.doc_state = XmlCommentState.Allowed;
2666 current_container.AddDelegate (del);
2667 RootContext.Tree.RecordDecl (current_namespace.NS, name, del);
2669 current_delegate = del;
2671 opt_type_parameter_constraints_clauses
2673 lexer.ConstraintsParsing = false;
2677 current_delegate.SetParameterInfo ((ArrayList) $11);
2678 $$ = current_delegate;
2680 current_delegate = null;
2687 lexer.CheckNullable (false);
2692 lexer.CheckNullable (true);
2697 namespace_or_type_name
2699 | IDENTIFIER DOUBLE_COLON IDENTIFIER {
2700 LocatedToken lt1 = (LocatedToken) $1;
2701 LocatedToken lt2 = (LocatedToken) $3;
2702 $$ = new MemberName (lt1.Value, lt2.Value, lt2.Location);
2704 | namespace_or_type_name DOT IDENTIFIER opt_type_argument_list {
2705 LocatedToken lt = (LocatedToken) $3;
2706 $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $4, lt.Location);
2711 : IDENTIFIER opt_type_argument_list {
2712 LocatedToken lt = (LocatedToken) $1;
2713 $$ = new MemberName (lt.Value, (TypeArguments) $2, lt.Location);
2717 opt_type_argument_list
2718 : /* empty */ { $$ = null; }
2719 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
2722 if (RootContext.Version == LanguageVersion.ISO_1)
2723 Report.FeatureIsNotStandardized (lexer.Location, "generics");
2727 $$ = new TypeArguments ((int) $1, lexer.Location);
2728 if (RootContext.Version == LanguageVersion.ISO_1)
2729 Report.FeatureIsNotStandardized (lexer.Location, "generics");
2734 : opt_attributes type {
2735 TypeArguments type_args = new TypeArguments (lexer.Location);
2737 SimpleName sn = $2 as SimpleName;
2739 Report.Error (1031, lexer.Location, "Type expected");
2741 $2 = new TypeParameterName (sn.Name, (Attributes) $1, lexer.Location);
2743 type_args.Add ((Expression) $2);
2746 | type_arguments COMMA opt_attributes type {
2747 TypeArguments type_args = (TypeArguments) $1;
2749 SimpleName sn = $4 as SimpleName;
2751 Report.Error (1031, lexer.Location, "Type expected");
2753 $4 = new TypeParameterName (sn.Name, (Attributes) $3, lexer.Location);
2755 type_args.Add ((Expression) $4);
2762 * Before you think of adding a return_type, notice that we have been
2763 * using two rules in the places where it matters (one rule using type
2764 * and another identical one that uses VOID as the return type). This
2765 * gets rid of a shift/reduce couple
2768 : namespace_or_type_name opt_nullable
2770 MemberName name = (MemberName) $1;
2771 $$ = name.GetTypeExpression ();
2774 $$ = new ComposedCast ((Expression) $$, "?", lexer.Location);
2776 | builtin_types opt_nullable
2779 $$ = new ComposedCast ((Expression) $1, "?", lexer.Location);
2789 // Note that here only unmanaged types are allowed but we
2790 // can't perform checks during this phase - we do it during
2791 // semantic analysis.
2793 $$ = new ComposedCast ((Expression) $1, "*", Lexer.Location);
2797 $$ = new ComposedCast (TypeManager.system_void_expr, "*", (Location) $1);
2802 : builtin_types opt_nullable
2805 $$ = new ComposedCast ((Expression) $1, "?", lexer.Location);
2807 | non_expression_type rank_specifier
2809 Location loc = GetLocation ($1);
2811 loc = lexer.Location;
2812 $$ = new ComposedCast ((Expression) $1, (string) $2, loc);
2814 | non_expression_type STAR
2816 Location loc = GetLocation ($1);
2818 loc = lexer.Location;
2819 $$ = new ComposedCast ((Expression) $1, "*", loc);
2821 | expression rank_specifiers
2823 $$ = new ComposedCast ((Expression) $1, (string) $2);
2827 $$ = new ComposedCast ((Expression) $1, "*");
2831 // We need this because the parser will happily go and reduce IDENTIFIER STAR
2832 // through this different path
2834 | multiplicative_expression STAR
2836 $$ = new ComposedCast ((Expression) $1, "*");
2843 ArrayList types = new ArrayList (4);
2848 | type_list COMMA type
2850 ArrayList types = (ArrayList) $1;
2858 * replaces all the productions for isolating the various
2859 * simple types, but we need this to reuse it easily in local_variable_type
2862 : OBJECT { $$ = TypeManager.system_object_expr; }
2863 | STRING { $$ = TypeManager.system_string_expr; }
2864 | BOOL { $$ = TypeManager.system_boolean_expr; }
2865 | DECIMAL { $$ = TypeManager.system_decimal_expr; }
2866 | FLOAT { $$ = TypeManager.system_single_expr; }
2867 | DOUBLE { $$ = TypeManager.system_double_expr; }
2872 : SBYTE { $$ = TypeManager.system_sbyte_expr; }
2873 | BYTE { $$ = TypeManager.system_byte_expr; }
2874 | SHORT { $$ = TypeManager.system_int16_expr; }
2875 | USHORT { $$ = TypeManager.system_uint16_expr; }
2876 | INT { $$ = TypeManager.system_int32_expr; }
2877 | UINT { $$ = TypeManager.system_uint32_expr; }
2878 | LONG { $$ = TypeManager.system_int64_expr; }
2879 | ULONG { $$ = TypeManager.system_uint64_expr; }
2880 | CHAR { $$ = TypeManager.system_char_expr; }
2881 | VOID { $$ = TypeManager.system_void_expr; }
2885 : type rank_specifiers opt_nullable
2887 string rank_specifiers = (string) $2;
2889 rank_specifiers += "?";
2891 $$ = current_array_type = new ComposedCast ((Expression) $1, rank_specifiers);
2896 // Expressions, section 7.5
2905 MemberName mn = (MemberName) $1;
2906 $$ = mn.GetTypeExpression ();
2908 | IDENTIFIER DOUBLE_COLON IDENTIFIER
2910 LocatedToken lt1 = (LocatedToken) $1;
2911 LocatedToken lt2 = (LocatedToken) $3;
2912 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, lt2.Location);
2914 | parenthesized_expression
2915 | default_value_expression
2917 | invocation_expression
2921 | post_increment_expression
2922 | post_decrement_expression
2926 | checked_expression
2927 | unchecked_expression
2928 | pointer_member_access
2929 | anonymous_method_expression
2936 | LITERAL_CHARACTER { $$ = new CharLiteral ((char) lexer.Value, lexer.Location); }
2937 | LITERAL_STRING { $$ = new StringLiteral ((string) lexer.Value, lexer.Location); }
2938 | NULL { $$ = new NullLiteral (lexer.Location); }
2942 : LITERAL_FLOAT { $$ = new FloatLiteral ((float) lexer.Value, lexer.Location); }
2943 | LITERAL_DOUBLE { $$ = new DoubleLiteral ((double) lexer.Value, lexer.Location); }
2944 | LITERAL_DECIMAL { $$ = new DecimalLiteral ((decimal) lexer.Value, lexer.Location); }
2949 object v = lexer.Value;
2952 $$ = new IntLiteral ((int) v, lexer.Location);
2953 } else if (v is uint)
2954 $$ = new UIntLiteral ((UInt32) v, lexer.Location);
2956 $$ = new LongLiteral ((Int64) v, lexer.Location);
2957 else if (v is ulong)
2958 $$ = new ULongLiteral ((UInt64) v, lexer.Location);
2960 Console.WriteLine ("OOPS. Unexpected result from scanner");
2965 : TRUE { $$ = new BoolLiteral (true, lexer.Location); }
2966 | FALSE { $$ = new BoolLiteral (false, lexer.Location); }
2969 parenthesized_expression_0
2970 : OPEN_PARENS expression CLOSE_PARENS
2973 lexer.Deambiguate_CloseParens ();
2974 // After this, the next token returned is one of
2975 // CLOSE_PARENS_CAST, CLOSE_PARENS_NO_CAST, CLOSE_PARENS_OPEN_PARENS
2976 // or CLOSE_PARENS_MINUS.
2980 parenthesized_expression
2981 : parenthesized_expression_0 CLOSE_PARENS_NO_CAST
2985 | parenthesized_expression_0 CLOSE_PARENS_MINUS
2987 // If a parenthesized expression is followed by a minus, we need to wrap
2988 // the expression inside a ParenthesizedExpression for the CS0075 check
2989 // in Binary.DoResolve().
2990 $$ = new ParenthesizedExpression ((Expression) $1);
2995 : primary_expression DOT IDENTIFIER opt_type_argument_list
2997 LocatedToken lt = (LocatedToken) $3;
2998 $$ = new MemberAccess ((Expression) $1, lt.Value,
2999 (TypeArguments) $4, lt.Location);
3001 | predefined_type DOT IDENTIFIER opt_type_argument_list
3003 LocatedToken lt = (LocatedToken) $3;
3004 $$ = new MemberAccess ((Expression) $1, lt.Value,
3005 (TypeArguments) $4, lt.Location);
3013 invocation_expression
3014 : primary_expression {
3015 $$ = lexer.Location;
3016 } OPEN_PARENS opt_argument_list CLOSE_PARENS
3019 Location l = (Location) $3;
3020 Report.Error (1, l, "Parse error");
3022 $$ = new Invocation ((Expression) $1, (ArrayList) $4);
3024 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS CLOSE_PARENS
3026 $$ = new Invocation ((Expression) $1, new ArrayList ());
3028 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS primary_expression
3030 $$ = new InvocationOrCast ((Expression) $1, (Expression) $3);
3032 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS non_simple_argument CLOSE_PARENS
3034 ArrayList args = new ArrayList (1);
3036 $$ = new Invocation ((Expression) $1, args);
3038 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS argument_list COMMA argument CLOSE_PARENS
3040 ArrayList args = ((ArrayList) $4);
3042 $$ = new Invocation ((Expression) $1, args);
3047 : /* empty */ { $$ = null; }
3054 ArrayList list = new ArrayList (4);
3058 | argument_list COMMA argument
3060 ArrayList list = (ArrayList) $1;
3064 | argument_list error {
3065 CheckToken (1026, yyToken, "Expected `,' or `)'", GetLocation ($2));
3073 $$ = new Argument ((Expression) $1, Argument.AType.Expression);
3075 | non_simple_argument
3082 : REF variable_reference
3084 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3086 | OUT variable_reference
3088 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3090 | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
3092 ArrayList list = (ArrayList) $3;
3093 Argument[] args = new Argument [list.Count];
3094 list.CopyTo (args, 0);
3096 Expression expr = new Arglist (args, (Location) $1);
3097 $$ = new Argument (expr, Argument.AType.Expression);
3101 $$ = new Argument (new ArglistAccess ((Location) $1), Argument.AType.ArgList);
3106 : expression { note ("section 5.4"); $$ = $1; }
3110 : primary_expression OPEN_BRACKET expression_list CLOSE_BRACKET
3112 $$ = new ElementAccess ((Expression) $1, (ArrayList) $3);
3114 | primary_expression rank_specifiers
3116 // So the super-trick is that primary_expression
3117 // can only be either a SimpleName or a MemberAccess.
3118 // The MemberAccess case arises when you have a fully qualified type-name like :
3120 // SimpleName is when you have
3123 Expression expr = (Expression) $1;
3124 if (expr is ComposedCast){
3125 $$ = new ComposedCast (expr, (string) $2);
3126 } else if (!(expr is SimpleName || expr is MemberAccess || expr is ConstructedType || expr is QualifiedAliasMember)){
3127 Error_ExpectingTypeName (expr);
3128 $$ = TypeManager.system_object_expr;
3131 // So we extract the string corresponding to the SimpleName
3134 $$ = new ComposedCast (expr, (string) $2);
3136 current_array_type = (Expression)$$;
3143 ArrayList list = new ArrayList (4);
3147 | expression_list COMMA expression
3149 ArrayList list = (ArrayList) $1;
3158 $$ = new This (current_block, (Location) $1);
3163 : BASE DOT IDENTIFIER
3165 LocatedToken lt = (LocatedToken) $3;
3166 $$ = new BaseAccess (lt.Value, lt.Location);
3168 | BASE OPEN_BRACKET expression_list CLOSE_BRACKET
3170 $$ = new BaseIndexerAccess ((ArrayList) $3, (Location) $1);
3173 Report.Error (175, (Location) $1, "Use of keyword `base' is not valid in this context");
3178 post_increment_expression
3179 : primary_expression OP_INC
3181 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement,
3182 (Expression) $1, (Location) $2);
3186 post_decrement_expression
3187 : primary_expression OP_DEC
3189 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement,
3190 (Expression) $1, (Location) $2);
3195 : object_or_delegate_creation_expression
3196 | array_creation_expression
3199 object_or_delegate_creation_expression
3200 : NEW type OPEN_PARENS opt_argument_list CLOSE_PARENS
3202 $$ = new New ((Expression) $2, (ArrayList) $4, (Location) $1);
3206 array_creation_expression
3207 : NEW type OPEN_BRACKET expression_list CLOSE_BRACKET
3209 opt_array_initializer
3211 $$ = new ArrayCreation ((Expression) $2, (ArrayList) $4, (string) $6, (ArrayList) $7, (Location) $1);
3213 | NEW type rank_specifiers array_initializer
3215 $$ = new ArrayCreation ((Expression) $2, (string) $3, (ArrayList) $4, (Location) $1);
3219 Report.Error (1031, (Location) $1, "Type expected");
3224 Report.Error (1526, (Location) $1, "A new expression requires () or [] after type");
3240 opt_rank_specifier_or_nullable
3249 | opt_nullable rank_specifiers
3256 | opt_nullable rank_specifiers INTERR
3259 $$ = "?" + $2 + "?";
3266 : rank_specifier opt_rank_specifier
3268 $$ = (string) $2 + (string) $1;
3273 : OPEN_BRACKET opt_dim_separators CLOSE_BRACKET
3275 $$ = "[" + (string) $2 + "]";
3295 | dim_separators COMMA
3297 $$ = (string) $1 + ",";
3301 opt_array_initializer
3313 : OPEN_BRACE CLOSE_BRACE
3315 ArrayList list = new ArrayList (4);
3318 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
3320 $$ = (ArrayList) $2;
3324 variable_initializer_list
3325 : variable_initializer
3327 ArrayList list = new ArrayList (4);
3331 | variable_initializer_list COMMA variable_initializer
3333 ArrayList list = (ArrayList) $1;
3339 void_pointer_expression
3340 : void_pointer_expression STAR
3342 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
3346 $$ = new ComposedCast (TypeManager.system_void_expr, "*", lexer.Location);;
3351 : TYPEOF OPEN_PARENS VOID CLOSE_PARENS
3353 $$ = new TypeOfVoid ((Location) $1);
3355 | TYPEOF OPEN_PARENS void_pointer_expression CLOSE_PARENS
3357 $$ = new TypeOf ((Expression) $3, (Location) $1);
3359 | TYPEOF OPEN_PARENS
3361 lexer.TypeOfParsing = true;
3365 lexer.TypeOfParsing = false;
3366 $$ = new TypeOf ((Expression) $4, lexer.Location);
3371 : SIZEOF OPEN_PARENS type CLOSE_PARENS {
3372 $$ = new SizeOf ((Expression) $3, (Location) $1);
3377 : CHECKED OPEN_PARENS expression CLOSE_PARENS
3379 $$ = new CheckedExpr ((Expression) $3, (Location) $1);
3383 unchecked_expression
3384 : UNCHECKED OPEN_PARENS expression CLOSE_PARENS
3386 $$ = new UnCheckedExpr ((Expression) $3, (Location) $1);
3390 pointer_member_access
3391 : primary_expression OP_PTR IDENTIFIER
3394 LocatedToken lt = (LocatedToken) $3;
3396 deref = new Unary (Unary.Operator.Indirection, (Expression) $1, lt.Location);
3397 $$ = new MemberAccess (deref, lt.Value, lt.Location);
3401 anonymous_method_expression
3402 : DELEGATE opt_anonymous_method_signature
3404 oob_stack.Push (current_local_parameters);
3405 current_local_parameters = (Parameters)$2;
3407 // Force the next block to be created as a ToplevelBlock
3408 oob_stack.Push (current_block);
3409 oob_stack.Push (top_current_block);
3410 current_block = null;
3414 Location loc = (Location) $1;
3415 top_current_block = (Block) oob_stack.Pop ();
3416 current_block = (Block) oob_stack.Pop ();
3417 if (RootContext.Version == LanguageVersion.ISO_1){
3418 Report.FeatureIsNotStandardized (loc, "anonymous methods");
3421 ToplevelBlock anon_block = (ToplevelBlock) $4;
3423 anon_block.Parent = current_block;
3424 $$ = new AnonymousMethod ((Parameters) $2, (ToplevelBlock) top_current_block,
3427 current_local_parameters = (Parameters) oob_stack.Pop ();
3431 opt_anonymous_method_signature
3432 : /* empty */ { $$ = null; }
3433 | anonymous_method_signature
3436 anonymous_method_signature
3437 : OPEN_PARENS opt_anonymous_method_parameter_list CLOSE_PARENS
3440 $$ = Parameters.EmptyReadOnlyParameters;
3442 ArrayList par_list = (ArrayList) $2;
3443 Parameter [] pars = new Parameter [par_list.Count];
3444 par_list.CopyTo (pars);
3445 $$ = new Parameters (pars);
3450 opt_anonymous_method_parameter_list
3451 : /* empty */ { $$ = null; }
3452 | anonymous_method_parameter_list { $$ = $1; }
3455 anonymous_method_parameter_list
3456 : anonymous_method_parameter
3458 ArrayList a = new ArrayList (4);
3462 | anonymous_method_parameter_list COMMA anonymous_method_parameter
3464 ArrayList a = (ArrayList) $1;
3470 anonymous_method_parameter
3471 : opt_parameter_modifier type IDENTIFIER {
3472 LocatedToken lt = (LocatedToken) $3;
3473 $$ = new Parameter ((Expression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
3475 | PARAMS type IDENTIFIER {
3476 Report.Error (1670, ((LocatedToken) $3).Location, "The `params' modifier is not allowed in anonymous method declaration");
3481 default_value_expression
3482 : DEFAULT_OPEN_PARENS type CLOSE_PARENS
3484 $$ = new DefaultValueExpression ((Expression) $2, lexer.Location);
3489 : primary_expression
3490 | BANG prefixed_unary_expression
3492 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, (Location) $1);
3494 | TILDE prefixed_unary_expression
3496 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, (Location) $1);
3502 : parenthesized_expression_0 CLOSE_PARENS_CAST unary_expression
3504 $$ = new Cast ((Expression) $1, (Expression) $3);
3506 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS cast_expression
3508 $$ = new Cast ((Expression) $1, (Expression) $3);
3514 | OPEN_PARENS non_expression_type CLOSE_PARENS prefixed_unary_expression
3516 // TODO: wrong location
3517 $$ = new Cast ((Expression) $2, (Expression) $4, lexer.Location);
3522 // The idea to split this out is from Rhys' grammar
3523 // to solve the problem with casts.
3525 prefixed_unary_expression
3527 | PLUS prefixed_unary_expression
3529 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, (Location) $1);
3531 | MINUS prefixed_unary_expression
3533 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, (Location) $1);
3535 | OP_INC prefixed_unary_expression
3537 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
3538 (Expression) $2, (Location) $1);
3540 | OP_DEC prefixed_unary_expression
3542 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
3543 (Expression) $2, (Location) $1);
3545 | STAR prefixed_unary_expression
3547 $$ = new Unary (Unary.Operator.Indirection, (Expression) $2, (Location) $1);
3549 | BITWISE_AND prefixed_unary_expression
3551 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, (Location) $1);
3555 pre_increment_expression
3556 : OP_INC prefixed_unary_expression
3558 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
3559 (Expression) $2, (Location) $1);
3563 pre_decrement_expression
3564 : OP_DEC prefixed_unary_expression
3566 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
3567 (Expression) $2, (Location) $1);
3571 multiplicative_expression
3572 : prefixed_unary_expression
3573 | multiplicative_expression STAR prefixed_unary_expression
3575 $$ = new Binary (Binary.Operator.Multiply,
3576 (Expression) $1, (Expression) $3);
3578 | multiplicative_expression DIV prefixed_unary_expression
3580 $$ = new Binary (Binary.Operator.Division,
3581 (Expression) $1, (Expression) $3);
3583 | multiplicative_expression PERCENT prefixed_unary_expression
3585 $$ = new Binary (Binary.Operator.Modulus,
3586 (Expression) $1, (Expression) $3);
3591 : multiplicative_expression
3592 | additive_expression PLUS multiplicative_expression
3594 $$ = new Binary (Binary.Operator.Addition,
3595 (Expression) $1, (Expression) $3);
3597 | additive_expression MINUS multiplicative_expression
3599 $$ = new Binary (Binary.Operator.Subtraction,
3600 (Expression) $1, (Expression) $3);
3605 : additive_expression
3606 | shift_expression OP_SHIFT_LEFT additive_expression
3608 $$ = new Binary (Binary.Operator.LeftShift,
3609 (Expression) $1, (Expression) $3);
3611 | shift_expression OP_SHIFT_RIGHT additive_expression
3613 $$ = new Binary (Binary.Operator.RightShift,
3614 (Expression) $1, (Expression) $3);
3625 lexer.PutbackNullable ();
3630 nullable_type_or_conditional
3633 if (((bool) $2) && ($1 is ComposedCast))
3634 $$ = ((ComposedCast) $1).RemoveNullable ();
3640 relational_expression
3642 | relational_expression OP_LT shift_expression
3644 $$ = new Binary (Binary.Operator.LessThan,
3645 (Expression) $1, (Expression) $3);
3647 | relational_expression OP_GT shift_expression
3649 $$ = new Binary (Binary.Operator.GreaterThan,
3650 (Expression) $1, (Expression) $3);
3652 | relational_expression OP_LE shift_expression
3654 $$ = new Binary (Binary.Operator.LessThanOrEqual,
3655 (Expression) $1, (Expression) $3);
3657 | relational_expression OP_GE shift_expression
3659 $$ = new Binary (Binary.Operator.GreaterThanOrEqual,
3660 (Expression) $1, (Expression) $3);
3662 | relational_expression IS
3665 } nullable_type_or_conditional
3667 $$ = new Is ((Expression) $1, (Expression) $4, (Location) $2);
3669 | relational_expression AS
3672 } nullable_type_or_conditional
3674 $$ = new As ((Expression) $1, (Expression) $4, (Location) $2);
3679 : relational_expression
3680 | equality_expression OP_EQ relational_expression
3682 $$ = new Binary (Binary.Operator.Equality,
3683 (Expression) $1, (Expression) $3);
3685 | equality_expression OP_NE relational_expression
3687 $$ = new Binary (Binary.Operator.Inequality,
3688 (Expression) $1, (Expression) $3);
3693 : equality_expression
3694 | and_expression BITWISE_AND equality_expression
3696 $$ = new Binary (Binary.Operator.BitwiseAnd,
3697 (Expression) $1, (Expression) $3);
3701 exclusive_or_expression
3703 | exclusive_or_expression CARRET and_expression
3705 $$ = new Binary (Binary.Operator.ExclusiveOr,
3706 (Expression) $1, (Expression) $3);
3710 inclusive_or_expression
3711 : exclusive_or_expression
3712 | inclusive_or_expression BITWISE_OR exclusive_or_expression
3714 $$ = new Binary (Binary.Operator.BitwiseOr,
3715 (Expression) $1, (Expression) $3);
3719 conditional_and_expression
3720 : inclusive_or_expression
3721 | conditional_and_expression OP_AND inclusive_or_expression
3723 $$ = new Binary (Binary.Operator.LogicalAnd,
3724 (Expression) $1, (Expression) $3);
3728 conditional_or_expression
3729 : conditional_and_expression
3730 | conditional_or_expression OP_OR conditional_and_expression
3732 $$ = new Binary (Binary.Operator.LogicalOr,
3733 (Expression) $1, (Expression) $3);
3737 conditional_expression
3738 : conditional_or_expression
3739 | conditional_or_expression INTERR expression COLON expression
3741 $$ = new Conditional ((Expression) $1, (Expression) $3, (Expression) $5);
3743 | conditional_or_expression INTERR INTERR expression
3745 $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $4, lexer.Location);
3747 // We'll be resolved into a `parenthesized_expression_0' later on.
3748 | conditional_or_expression INTERR CLOSE_PARENS
3750 $$ = new ComposedCast ((Expression) $1, "?", lexer.Location);
3751 lexer.PutbackCloseParens ();
3755 assignment_expression
3756 : prefixed_unary_expression ASSIGN expression
3758 $$ = new Assign ((Expression) $1, (Expression) $3);
3760 | prefixed_unary_expression OP_MULT_ASSIGN expression
3762 $$ = new CompoundAssign (
3763 Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
3765 | prefixed_unary_expression OP_DIV_ASSIGN expression
3767 $$ = new CompoundAssign (
3768 Binary.Operator.Division, (Expression) $1, (Expression) $3);
3770 | prefixed_unary_expression OP_MOD_ASSIGN expression
3772 $$ = new CompoundAssign (
3773 Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
3775 | prefixed_unary_expression OP_ADD_ASSIGN expression
3777 $$ = new CompoundAssign (
3778 Binary.Operator.Addition, (Expression) $1, (Expression) $3);
3780 | prefixed_unary_expression OP_SUB_ASSIGN expression
3782 $$ = new CompoundAssign (
3783 Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
3785 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
3787 $$ = new CompoundAssign (
3788 Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
3790 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
3792 $$ = new CompoundAssign (
3793 Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
3795 | prefixed_unary_expression OP_AND_ASSIGN expression
3797 $$ = new CompoundAssign (
3798 Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
3800 | prefixed_unary_expression OP_OR_ASSIGN expression
3802 $$ = new CompoundAssign (
3803 Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
3805 | prefixed_unary_expression OP_XOR_ASSIGN expression
3807 $$ = new CompoundAssign (
3808 Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
3813 : conditional_expression
3814 | assignment_expression
3834 lexer.ConstraintsParsing = true;
3838 MemberName name = MakeName ((MemberName) $6);
3839 int mod_flags = (int) $2;
3842 ClassPart part = PartialContainer.CreatePart (
3843 current_namespace, current_class, name, mod_flags,
3844 (Attributes) $1, Kind.Class, (Location) $3);
3846 current_container = part.PartialContainer;
3847 current_class = part;
3849 if ((mod_flags & Modifiers.STATIC) != 0) {
3850 current_class = new StaticClass (
3851 current_namespace, current_class, name,
3852 mod_flags, (Attributes) $1);
3854 current_class = new Class (
3855 current_namespace, current_class, name,
3856 mod_flags, (Attributes) $1);
3859 current_container.AddClassOrStruct (current_class);
3860 current_container = current_class;
3861 RootContext.Tree.RecordDecl (current_namespace.NS, name, current_class);
3865 opt_type_parameter_constraints_clauses
3867 lexer.ConstraintsParsing = false;
3870 if (current_class.Name == "System.Object") {
3871 Report.Error (537, current_class.Location,
3872 "The class System.Object cannot have a base " +
3873 "class or implement an interface.");
3875 current_class.Bases = (ArrayList) $8;
3878 current_class.SetParameterInfo ((ArrayList) $9);
3880 if (RootContext.Documentation != null) {
3881 current_class.DocComment = Lexer.consume_doc_comment ();
3882 Lexer.doc_state = XmlCommentState.Allowed;
3887 if (RootContext.Documentation != null)
3888 Lexer.doc_state = XmlCommentState.Allowed;
3892 $$ = pop_current_class ();
3900 { $$ = $1; } // location
3904 : /* empty */ { $$ = (int) 0; }
3910 | modifiers modifier
3915 if ((m1 & m2) != 0) {
3916 Location l = lexer.Location;
3917 Report.Error (1004, l, "Duplicate `{0}' modifier", Modifiers.Name (m2));
3919 $$ = (int) (m1 | m2);
3924 : NEW { $$ = Modifiers.NEW; }
3925 | PUBLIC { $$ = Modifiers.PUBLIC; }
3926 | PROTECTED { $$ = Modifiers.PROTECTED; }
3927 | INTERNAL { $$ = Modifiers.INTERNAL; }
3928 | PRIVATE { $$ = Modifiers.PRIVATE; }
3929 | ABSTRACT { $$ = Modifiers.ABSTRACT; }
3930 | SEALED { $$ = Modifiers.SEALED; }
3931 | STATIC { $$ = Modifiers.STATIC; }
3932 | READONLY { $$ = Modifiers.READONLY; }
3933 | VIRTUAL { $$ = Modifiers.VIRTUAL; }
3934 | OVERRIDE { $$ = Modifiers.OVERRIDE; }
3935 | EXTERN { $$ = Modifiers.EXTERN; }
3936 | VOLATILE { $$ = Modifiers.VOLATILE; }
3937 | UNSAFE { $$ = Modifiers.UNSAFE; }
3941 : /* empty */ { $$ = null; }
3942 | class_base { $$ = $1; }
3946 : COLON type_list { $$ = $2; }
3949 opt_type_parameter_constraints_clauses
3950 : /* empty */ { $$ = null; }
3951 | type_parameter_constraints_clauses
3955 type_parameter_constraints_clauses
3956 : type_parameter_constraints_clause {
3957 ArrayList constraints = new ArrayList (1);
3958 constraints.Add ($1);
3961 | type_parameter_constraints_clauses type_parameter_constraints_clause {
3962 ArrayList constraints = (ArrayList) $1;
3964 constraints.Add ($2);
3969 type_parameter_constraints_clause
3970 : WHERE IDENTIFIER COLON type_parameter_constraints {
3971 LocatedToken lt = (LocatedToken) $2;
3972 $$ = new Constraints (lt.Value, (ArrayList) $4, lt.Location);
3976 type_parameter_constraints
3977 : type_parameter_constraint {
3978 ArrayList constraints = new ArrayList (1);
3979 constraints.Add ($1);
3982 | type_parameter_constraints COMMA type_parameter_constraint {
3983 ArrayList constraints = (ArrayList) $1;
3985 constraints.Add ($3);
3990 type_parameter_constraint
3992 | NEW OPEN_PARENS CLOSE_PARENS {
3993 $$ = SpecialConstraint.Constructor;
3996 $$ = SpecialConstraint.ReferenceType;
3999 $$ = SpecialConstraint.ValueType;
4008 // A block is "contained" on the following places:
4010 // property_declaration as part of the accessor body (get/set)
4011 // operator_declaration
4012 // constructor_declaration
4013 // destructor_declaration
4014 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
4019 if (current_block == null){
4020 current_block = new ToplevelBlock ((ToplevelBlock) top_current_block, current_local_parameters, (Location) $1);
4021 top_current_block = current_block;
4023 current_block = new Block (current_block, (Location) $1, Location.Null);
4026 opt_statement_list CLOSE_BRACE
4028 while (current_block.Implicit)
4029 current_block = current_block.Parent;
4031 current_block.SetEndLocation ((Location) $4);
4032 current_block = current_block.Parent;
4033 if (current_block == null)
4034 top_current_block = null;
4045 | statement_list statement
4049 : declaration_statement
4051 if ($1 != null && (Block) $1 != current_block){
4052 current_block.AddStatement ((Statement) $1);
4053 current_block = (Block) $1;
4056 | valid_declaration_statement
4058 current_block.AddStatement ((Statement) $1);
4063 valid_declaration_statement
4066 | expression_statement
4067 | selection_statement
4068 | iteration_statement
4072 | unchecked_statement
4080 : valid_declaration_statement
4081 | declaration_statement
4083 Report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4088 Report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4096 $$ = EmptyStatement.Value;
4103 LocatedToken lt = (LocatedToken) $1;
4104 LabeledStatement labeled = new LabeledStatement (lt.Value, lt.Location);
4106 if (current_block.AddLabel (lt.Value, labeled, lt.Location))
4107 current_block.AddStatement (labeled);
4112 declaration_statement
4113 : local_variable_declaration SEMICOLON
4116 DictionaryEntry de = (DictionaryEntry) $1;
4117 Expression e = (Expression) de.Key;
4119 $$ = declare_local_variables (e, (ArrayList) de.Value, e.Location);
4123 | local_constant_declaration SEMICOLON
4126 DictionaryEntry de = (DictionaryEntry) $1;
4128 $$ = declare_local_constants ((Expression) de.Key, (ArrayList) de.Value);
4134 * The following is from Rhys' grammar:
4135 * > Types in local variable declarations must be recognized as
4136 * > expressions to prevent reduce/reduce errors in the grammar.
4137 * > The expressions are converted into types during semantic analysis.
4140 : primary_expression opt_rank_specifier_or_nullable
4142 // FIXME: Do something smart here regarding the composition of the type.
4144 // Ok, the above "primary_expression" is there to get rid of
4145 // both reduce/reduce and shift/reduces in the grammar, it should
4146 // really just be "type_name". If you use type_name, a reduce/reduce
4147 // creeps up. If you use namespace_or_type_name (which is all we need
4148 // really) two shift/reduces appear.
4151 // So the super-trick is that primary_expression
4152 // can only be either a SimpleName or a MemberAccess.
4153 // The MemberAccess case arises when you have a fully qualified type-name like :
4155 // SimpleName is when you have
4158 Expression expr = (Expression) $1;
4159 if (!(expr is SimpleName || expr is MemberAccess || expr is ComposedCast || expr is ConstructedType || expr is QualifiedAliasMember)) {
4160 Error_ExpectingTypeName (expr);
4164 // So we extract the string corresponding to the SimpleName
4168 if ((string) $2 == "")
4171 $$ = new ComposedCast ((Expression) $1, (string) $2);
4174 | builtin_types opt_rank_specifier_or_nullable
4176 if ((string) $2 == "")
4179 $$ = current_array_type = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
4183 local_variable_pointer_type
4184 : primary_expression STAR
4186 Expression expr = (Expression) $1;
4188 if (!(expr is SimpleName || expr is MemberAccess || expr is ComposedCast || expr is ConstructedType || expr is QualifiedAliasMember)) {
4189 Error_ExpectingTypeName (expr);
4193 $$ = new ComposedCast ((Expression) $1, "*");
4195 | builtin_types STAR
4197 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
4201 $$ = new ComposedCast (TypeManager.system_void_expr, "*", (Location) $1);
4203 | local_variable_pointer_type STAR
4205 $$ = new ComposedCast ((Expression) $1, "*");
4209 local_variable_declaration
4210 : local_variable_type variable_declarators
4213 $$ = new DictionaryEntry ($1, $2);
4217 | local_variable_pointer_type opt_rank_specifier_or_nullable variable_declarators
4222 if ((string) $2 == "")
4223 t = (Expression) $1;
4225 t = new ComposedCast ((Expression) $1, (string) $2);
4226 $$ = new DictionaryEntry (t, $3);
4232 local_constant_declaration
4233 : CONST local_variable_type constant_declarators
4236 $$ = new DictionaryEntry ($2, $3);
4242 expression_statement
4243 : statement_expression SEMICOLON
4250 // We have to do the wrapping here and not in the case above,
4251 // because statement_expression is used for example in for_statement
4253 statement_expression
4254 : invocation_expression { $$ = new StatementExpression ((ExpressionStatement) $1); }
4255 | object_creation_expression { $$ = new StatementExpression ((ExpressionStatement) $1); }
4256 | assignment_expression { $$ = new StatementExpression ((ExpressionStatement) $1); }
4257 | post_increment_expression { $$ = new StatementExpression ((ExpressionStatement) $1); }
4258 | post_decrement_expression { $$ = new StatementExpression ((ExpressionStatement) $1); }
4259 | pre_increment_expression { $$ = new StatementExpression ((ExpressionStatement) $1); }
4260 | pre_decrement_expression { $$ = new StatementExpression ((ExpressionStatement) $1); }
4262 Report.Error (1002, GetLocation ($1), "Expecting `;'");
4267 object_creation_expression
4268 : object_or_delegate_creation_expression
4269 { note ("complain if this is a delegate maybe?"); }
4278 : IF OPEN_PARENS boolean_expression CLOSE_PARENS
4281 Location l = (Location) $1;
4283 $$ = new If ((Expression) $3, (Statement) $5, l);
4285 // FIXME: location for warning should be loc property of $5.
4286 if ($5 == EmptyStatement.Value)
4287 Report.Warning (642, 3, l, "Possible mistaken empty statement");
4290 | IF OPEN_PARENS boolean_expression CLOSE_PARENS
4291 embedded_statement ELSE embedded_statement
4293 Location l = (Location) $1;
4295 $$ = new If ((Expression) $3, (Statement) $5, (Statement) $7, l);
4297 // FIXME: location for warning should be loc property of $5 and $7.
4298 if ($5 == EmptyStatement.Value)
4299 Report.Warning (642, 3, l, "Possible mistaken empty statement");
4300 if ($7 == EmptyStatement.Value)
4301 Report.Warning (642, 3, l, "Possible mistaken empty statement");
4306 : SWITCH OPEN_PARENS
4308 switch_stack.Push (current_block);
4310 expression CLOSE_PARENS
4313 $$ = new Switch ((Expression) $4, (ArrayList) $6, (Location) $1);
4314 current_block = (Block) switch_stack.Pop ();
4330 Report.Error (1522, lexer.Location, "Empty switch block");
4338 ArrayList sections = new ArrayList (4);
4343 | switch_sections switch_section
4345 ArrayList sections = (ArrayList) $1;
4355 current_block = current_block.CreateSwitchBlock (lexer.Location);
4359 Block topmost = current_block;
4361 while (topmost.Implicit)
4362 topmost = topmost.Parent;
4363 $$ = new SwitchSection ((ArrayList) $1, topmost);
4370 ArrayList labels = new ArrayList (4);
4375 | switch_labels switch_label
4377 ArrayList labels = (ArrayList) ($1);
4385 : CASE constant_expression COLON { $$ = new SwitchLabel ((Expression) $2, (Location) $1); }
4386 | DEFAULT COLON { $$ = new SwitchLabel (null, (Location) $2); }
4389 1523, GetLocation ($1),
4390 "The keyword case or default must precede code in switch block");
4402 : WHILE OPEN_PARENS boolean_expression CLOSE_PARENS embedded_statement
4404 Location l = (Location) $1;
4405 $$ = new While ((Expression) $3, (Statement) $5, l);
4410 : DO embedded_statement
4411 WHILE OPEN_PARENS boolean_expression CLOSE_PARENS SEMICOLON
4413 Location l = (Location) $1;
4415 $$ = new Do ((Statement) $2, (Expression) $5, l);
4421 opt_for_initializer SEMICOLON
4423 Block assign_block = new Block (current_block);
4424 current_block = assign_block;
4426 if ($3 is DictionaryEntry){
4427 DictionaryEntry de = (DictionaryEntry) $3;
4429 Expression type = (Expression) de.Key;
4430 ArrayList var_declarators = (ArrayList) de.Value;
4432 foreach (VariableDeclaration decl in var_declarators){
4436 vi = current_block.AddVariable (type, decl.identifier, decl.Location);
4440 Location l = lexer.Location;
4441 Expression expr = decl.expression_or_array_initializer;
4443 LocalVariableReference var;
4444 var = new LocalVariableReference (assign_block, decl.identifier, l);
4447 Assign a = new Assign (var, expr, decl.Location);
4449 assign_block.AddStatement (new StatementExpression (a));
4453 // Note: the $$ below refers to the value of this code block, not of the LHS non-terminal.
4454 // This can be referred to as $5 below.
4460 opt_for_condition SEMICOLON
4461 opt_for_iterator CLOSE_PARENS
4464 Location l = (Location) $1;
4466 For f = new For ((Statement) $5, (Expression) $6, (Statement) $8, (Statement) $10, l);
4468 current_block.AddStatement (f);
4469 while (current_block.Implicit)
4470 current_block = current_block.Parent;
4472 current_block = current_block.Parent;
4477 : /* empty */ { $$ = EmptyStatement.Value; }
4482 : local_variable_declaration
4483 | statement_expression_list
4487 : /* empty */ { $$ = null; }
4488 | boolean_expression
4492 : /* empty */ { $$ = EmptyStatement.Value; }
4497 : statement_expression_list
4500 statement_expression_list
4501 : statement_expression
4503 // CHANGE: was `null'
4504 Statement s = (Statement) $1;
4505 Block b = new Block (current_block, Block.Flags.Implicit, s.loc, lexer.Location);
4510 | statement_expression_list COMMA statement_expression
4512 Block b = (Block) $1;
4514 b.AddStatement ((Statement) $3);
4520 : FOREACH OPEN_PARENS type IN expression CLOSE_PARENS
4522 Report.Error (230, (Location) $1, "Type and identifier are both required in a foreach statement");
4525 | FOREACH OPEN_PARENS type IDENTIFIER IN
4526 expression CLOSE_PARENS
4528 Block foreach_block = new Block (current_block);
4529 current_block = foreach_block;
4531 LocatedToken lt = (LocatedToken) $4;
4532 Location l = lt.Location;
4535 vi = foreach_block.AddVariable ((Expression) $3, lt.Value, l);
4537 vi.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Foreach);
4539 // Get a writable reference to this read-only variable.
4541 // Note that the $$ here refers to the value of _this_ code block,
4542 // not the value of the LHS non-terminal. This can be referred to as $8 below.
4543 $$ = new LocalVariableReference (foreach_block, lt.Value, l, vi, false);
4550 LocalVariableReference v = (LocalVariableReference) $8;
4551 Location l = (Location) $1;
4554 Foreach f = new Foreach ((Expression) $3, v, (Expression) $6, (Statement) $9, l);
4555 current_block.AddStatement (f);
4558 while (current_block.Implicit)
4559 current_block = current_block.Parent;
4561 current_block = current_block.Parent;
4567 | continue_statement
4577 $$ = new Break ((Location) $1);
4582 : CONTINUE SEMICOLON
4584 $$ = new Continue ((Location) $1);
4589 : GOTO IDENTIFIER SEMICOLON
4591 LocatedToken lt = (LocatedToken) $2;
4592 $$ = new Goto (lt.Value, lt.Location);
4594 | GOTO CASE constant_expression SEMICOLON
4596 $$ = new GotoCase ((Expression) $3, (Location) $1);
4598 | GOTO DEFAULT SEMICOLON
4600 $$ = new GotoDefault ((Location) $1);
4605 : RETURN opt_expression SEMICOLON
4607 $$ = new Return ((Expression) $2, (Location) $1);
4612 : THROW opt_expression SEMICOLON
4614 $$ = new Throw ((Expression) $2, (Location) $1);
4619 : IDENTIFIER RETURN expression SEMICOLON
4621 LocatedToken lt = (LocatedToken) $1;
4622 string s = lt.Value;
4624 Report.Error (1003, lt.Location, "; expected");
4627 if (RootContext.Version == LanguageVersion.ISO_1){
4628 Report.FeatureIsNotStandardized (lt.Location, "yield statement");
4631 if (iterator_container == null){
4632 Report.Error (204, lt.Location, "yield statement can only be used within a method, operator or property");
4635 iterator_container.SetYields ();
4636 $$ = new Yield ((Expression) $3, lt.Location);
4639 | IDENTIFIER RETURN SEMICOLON
4641 Report.Error (1627, (Location) $2, "Expression expected after yield return");
4644 | IDENTIFIER BREAK SEMICOLON
4646 LocatedToken lt = (LocatedToken) $1;
4647 string s = lt.Value;
4649 Report.Error (1003, lt.Location, "; expected");
4652 if (RootContext.Version == LanguageVersion.ISO_1){
4653 Report.FeatureIsNotStandardized (lt.Location, "yield statement");
4656 if (iterator_container == null){
4657 Report.Error (204, lt.Location, "yield statement can only be used within a method, operator or property");
4660 iterator_container.SetYields ();
4661 $$ = new YieldBreak (lt.Location);
4672 : TRY block catch_clauses
4676 ArrayList c = (ArrayList)$3;
4677 for (int i = 0; i < c.Count; ++i) {
4678 Catch cc = (Catch) c [i];
4680 if (i != c.Count - 1)
4681 Report.Error (1017, cc.loc, "Try statement already has an empty catch block");
4688 // Now s contains the list of specific catch clauses
4689 // and g contains the general one.
4691 $$ = new Try ((Block) $2, c, g, null, ((Block) $2).loc);
4693 | TRY block opt_catch_clauses FINALLY block
4696 ArrayList s = new ArrayList (4);
4697 ArrayList catch_list = (ArrayList) $3;
4699 if (catch_list != null){
4700 foreach (Catch cc in catch_list) {
4708 $$ = new Try ((Block) $2, s, g, (Block) $5, ((Block) $2).loc);
4712 Report.Error (1524, (Location) $1, "Expected catch or finally");
4718 : /* empty */ { $$ = null; }
4725 ArrayList l = new ArrayList (4);
4730 | catch_clauses catch_clause
4732 ArrayList l = (ArrayList) $1;
4740 : /* empty */ { $$ = null; }
4745 : CATCH opt_catch_args
4747 Expression type = null;
4750 DictionaryEntry cc = (DictionaryEntry) $2;
4751 type = (Expression) cc.Key;
4752 LocatedToken lt = (LocatedToken) cc.Value;
4755 ArrayList one = new ArrayList (4);
4757 one.Add (new VariableDeclaration (lt, null));
4759 current_block = new Block (current_block);
4760 Block b = declare_local_variables (type, one, lt.Location);
4765 Expression type = null;
4769 DictionaryEntry cc = (DictionaryEntry) $2;
4770 type = (Expression) cc.Key;
4771 LocatedToken lt = (LocatedToken) cc.Value;
4775 while (current_block.Implicit)
4776 current_block = current_block.Parent;
4777 current_block = current_block.Parent;
4781 $$ = new Catch (type, id, (Block) $4, ((Block) $4).loc);
4786 : /* empty */ { $$ = null; }
4791 : OPEN_PARENS type opt_identifier CLOSE_PARENS
4793 $$ = new DictionaryEntry ($2, $3);
4801 $$ = new Checked ((Block) $2);
4808 $$ = new Unchecked ((Block) $2);
4815 RootContext.CheckUnsafeOption ((Location) $1);
4817 $$ = new Unsafe ((Block) $3);
4823 type fixed_pointer_declarators
4826 ArrayList list = (ArrayList) $4;
4827 Expression type = (Expression) $3;
4828 Location l = (Location) $1;
4829 int top = list.Count;
4831 Block assign_block = new Block (current_block);
4832 current_block = assign_block;
4834 for (int i = 0; i < top; i++){
4835 Pair p = (Pair) list [i];
4838 v = current_block.AddVariable (type, (string) p.First, l);
4842 v.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Fixed);
4850 Location l = (Location) $1;
4852 Fixed f = new Fixed ((Expression) $3, (ArrayList) $4, (Statement) $7, l);
4854 current_block.AddStatement (f);
4855 while (current_block.Implicit)
4856 current_block = current_block.Parent;
4858 current_block = current_block.Parent;
4862 fixed_pointer_declarators
4863 : fixed_pointer_declarator {
4864 ArrayList declarators = new ArrayList (4);
4866 declarators.Add ($1);
4869 | fixed_pointer_declarators COMMA fixed_pointer_declarator
4871 ArrayList declarators = (ArrayList) $1;
4873 declarators.Add ($3);
4878 fixed_pointer_declarator
4879 : IDENTIFIER ASSIGN expression
4881 LocatedToken lt = (LocatedToken) $1;
4882 // FIXME: keep location
4883 $$ = new Pair (lt.Value, $3);
4887 Report.Error (210, ((LocatedToken) $1).Location, "You must provide an initializer in a fixed or using statement declaration");
4893 : LOCK OPEN_PARENS expression CLOSE_PARENS
4899 $$ = new Lock ((Expression) $3, (Statement) $6, (Location) $1);
4904 : USING OPEN_PARENS resource_acquisition CLOSE_PARENS
4906 Block assign_block = new Block (current_block);
4907 current_block = assign_block;
4909 if ($3 is DictionaryEntry){
4910 DictionaryEntry de = (DictionaryEntry) $3;
4911 Location l = (Location) $1;
4913 Expression type = (Expression) de.Key;
4914 ArrayList var_declarators = (ArrayList) de.Value;
4916 ArrayList vars = new ArrayList (4);
4918 foreach (VariableDeclaration decl in var_declarators){
4920 LocalInfo vi = current_block.AddVariable (type, decl.identifier, decl.Location);
4923 vi.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Using);
4925 Expression expr = decl.expression_or_array_initializer;
4927 Report.Error (210, l, "You must provide an initializer in a fixed or using statement declaration");
4930 LocalVariableReference var;
4932 // Get a writable reference to this read-only variable.
4933 var = new LocalVariableReference (assign_block, decl.identifier, l, vi, false);
4935 // This is so that it is not a warning on using variables
4938 vars.Add (new DictionaryEntry (var, expr));
4940 // Assign a = new Assign (var, expr, decl.Location);
4941 // assign_block.AddStatement (new StatementExpression (a));
4944 // Note: the $$ here refers to the value of this code block and not of the LHS non-terminal.
4945 // It can be referred to as $5 below.
4946 $$ = new DictionaryEntry (type, vars);
4953 Using u = new Using ($5, (Statement) $6, (Location) $1);
4954 current_block.AddStatement (u);
4955 while (current_block.Implicit)
4956 current_block = current_block.Parent;
4958 current_block = current_block.Parent;
4962 resource_acquisition
4963 : local_variable_declaration
4970 // A class used to pass around variable declarations and constants
4972 public class VariableDeclaration {
4973 public string identifier;
4974 public Expression expression_or_array_initializer;
4975 public Location Location;
4976 public Attributes OptAttributes;
4977 public string DocComment;
4979 public VariableDeclaration (LocatedToken lt, object eoai, Attributes opt_attrs)
4981 this.identifier = lt.Value;
4982 if (eoai is ArrayList) {
4983 if (CSharpParser.current_array_type == null)
4984 Report.Error (622, lt.Location,
4985 "Can only use array initializer expressions to assign to array types. Try using a new expression instead.");
4986 this.expression_or_array_initializer = new ArrayCreation (CSharpParser.current_array_type, "", (ArrayList)eoai, lt.Location);
4988 this.expression_or_array_initializer = (Expression)eoai;
4990 CSharpParser.current_array_type = null;
4991 this.Location = lt.Location;
4992 this.OptAttributes = opt_attrs;
4995 public VariableDeclaration (LocatedToken lt, object eoai) : this (lt, eoai, null)
5001 // A class used to hold info about an indexer declarator
5003 public class IndexerDeclaration {
5004 public Expression type;
5005 public MemberName interface_type;
5006 public Parameters param_list;
5007 public Location location;
5009 public IndexerDeclaration (Expression type, MemberName interface_type,
5010 Parameters param_list, Location loc)
5013 this.interface_type = interface_type;
5014 this.param_list = param_list;
5015 this.location = loc;
5020 // We use this when we do not have an object in advance that is an IIteratorContainer
5022 public class SimpleIteratorContainer : IIteratorContainer {
5025 public static SimpleIteratorContainer Simple = new SimpleIteratorContainer ();
5030 public static SimpleIteratorContainer GetSimple () {
5031 Simple.Yields = false;
5035 public void SetYields () { Yields = true; }
5039 // A class used to hold info about an operator declarator
5041 public class OperatorDeclaration {
5042 public Operator.OpType optype;
5043 public Expression ret_type, arg1type, arg2type;
5044 public string arg1name, arg2name;
5045 public Location location;
5047 public OperatorDeclaration (Operator.OpType op, Expression ret_type,
5048 Expression arg1type, string arg1name,
5049 Expression arg2type, string arg2name, Location location)
5052 this.ret_type = ret_type;
5053 this.arg1type = arg1type;
5054 this.arg1name = arg1name;
5055 this.arg2type = arg2type;
5056 this.arg2name = arg2name;
5057 this.location = location;
5062 void Error_ExpectingTypeName (Expression expr)
5064 if (expr is Invocation){
5065 Report.Error (1002, expr.Location, "Expecting `;'");
5067 Report.Error (201, expr.Location, "Only assignment, call, increment, decrement, and new object expressions can be used as a statement");
5071 TypeContainer pop_current_class ()
5073 TypeContainer retval = current_class;
5075 current_class = (TypeContainer) current_class.Parent;
5076 current_container = (TypeContainer) current_container.Parent;
5078 if (current_class != current_container) {
5079 if (((ClassPart) current_class).PartialContainer != current_container)
5080 throw new InternalErrorException ("current_container and current_class are out of sync");
5081 } else if (current_container is ClassPart)
5082 current_container = ((ClassPart) current_class).PartialContainer;
5088 // Given the @class_name name, it creates a fully qualified name
5089 // based on the containing declaration space
5092 MakeName (MemberName class_name)
5094 Namespace ns = current_namespace.NS;
5096 if (current_container.Name == ""){
5098 return new MemberName (ns.MemberName, class_name);
5102 return new MemberName (current_container.MemberName, class_name);
5106 Block declare_local_variables (Expression type, ArrayList variable_declarators, Location loc)
5108 Block implicit_block;
5109 ArrayList inits = null;
5112 // We use the `Used' property to check whether statements
5113 // have been added to the current block. If so, we need
5114 // to create another block to contain the new declaration
5115 // otherwise, as an optimization, we use the same block to
5116 // add the declaration.
5118 // FIXME: A further optimization is to check if the statements
5119 // that were added were added as part of the initialization
5120 // below. In which case, no other statements have been executed
5121 // and we might be able to reduce the number of blocks for
5122 // situations like this:
5124 // int j = 1; int k = j + 1;
5126 if (current_block.Used)
5127 implicit_block = new Block (current_block, Block.Flags.Implicit, loc, Location.Null);
5129 implicit_block = current_block;
5131 foreach (VariableDeclaration decl in variable_declarators){
5133 if (implicit_block.AddVariable (type, decl.identifier, decl.Location) != null) {
5134 if (decl.expression_or_array_initializer != null){
5136 inits = new ArrayList (4);
5143 return implicit_block;
5145 foreach (VariableDeclaration decl in inits){
5147 Expression expr = decl.expression_or_array_initializer;
5149 LocalVariableReference var;
5150 var = new LocalVariableReference (implicit_block, decl.identifier, loc);
5152 assign = new Assign (var, expr, decl.Location);
5154 implicit_block.AddStatement (new StatementExpression (assign));
5157 return implicit_block;
5160 Block declare_local_constants (Expression type, ArrayList declarators)
5162 Block implicit_block;
5164 if (current_block.Used)
5165 implicit_block = new Block (current_block, Block.Flags.Implicit);
5167 implicit_block = current_block;
5169 foreach (VariableDeclaration decl in declarators){
5170 implicit_block.AddConstant (type, decl.identifier, (Expression) decl.expression_or_array_initializer, decl.Location);
5173 return implicit_block;
5176 void CheckAttributeTarget (string a, Location l)
5180 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
5184 Report.Error (658, l, "`" + a + "' is an invalid attribute target");
5190 void CheckUnaryOperator (Operator.OpType op, Location l)
5194 case Operator.OpType.LogicalNot:
5195 case Operator.OpType.OnesComplement:
5196 case Operator.OpType.Increment:
5197 case Operator.OpType.Decrement:
5198 case Operator.OpType.True:
5199 case Operator.OpType.False:
5200 case Operator.OpType.Addition:
5201 case Operator.OpType.Subtraction:
5206 Report.Error (1019, l, "Overloadable unary operator expected");
5212 void CheckBinaryOperator (Operator.OpType op, Location l)
5216 case Operator.OpType.Addition:
5217 case Operator.OpType.Subtraction:
5218 case Operator.OpType.Multiply:
5219 case Operator.OpType.Division:
5220 case Operator.OpType.Modulus:
5221 case Operator.OpType.BitwiseAnd:
5222 case Operator.OpType.BitwiseOr:
5223 case Operator.OpType.ExclusiveOr:
5224 case Operator.OpType.LeftShift:
5225 case Operator.OpType.RightShift:
5226 case Operator.OpType.Equality:
5227 case Operator.OpType.Inequality:
5228 case Operator.OpType.GreaterThan:
5229 case Operator.OpType.LessThan:
5230 case Operator.OpType.GreaterThanOrEqual:
5231 case Operator.OpType.LessThanOrEqual:
5235 Report.Error (1020, l, "Overloadable binary operator expected");
5241 void syntax_error (Location l, string msg)
5243 Report.Error (1003, l, "Syntax error, " + msg);
5246 void note (string s)
5248 // Used to put annotations
5253 public Tokenizer Lexer {
5259 public CSharpParser (SeekableStreamReader reader, SourceFile file, ArrayList defines)
5261 current_namespace = new NamespaceEntry (null, file, null, Location.Null);
5262 this.name = file.Name;
5264 current_container = RootContext.Tree.Types;
5265 // TODO: Make RootContext.Tree.Types a PartialContainer.
5266 current_class = current_container;
5267 current_container.NamespaceEntry = current_namespace;
5268 oob_stack = new Stack ();
5269 switch_stack = new Stack ();
5271 lexer = new Tokenizer (reader, file, defines);
5274 public void parse ()
5277 if (yacc_verbose_flag > 1)
5278 yyparse (lexer, new yydebug.yyDebugSimple ());
5281 Tokenizer tokenizer = lexer as Tokenizer;
5282 tokenizer.cleanup ();
5283 } catch (Exception e){
5285 // Removed for production use, use parser verbose to get the output.
5287 // Console.WriteLine (e);
5288 Report.Error (-25, lexer.Location, "Parsing error");
5289 if (yacc_verbose_flag > 0)
5290 Console.WriteLine (e);
5293 RootContext.Tree.Types.NamespaceEntry = null;
5296 void CheckToken (int error, int yyToken, string msg, Location loc)
5298 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD){
5299 Report.Error (error, loc, String.Format ("{0}: `{1}' is a keyword", msg, yyNames [yyToken].ToLower ()));
5302 Report.Error (error, loc, msg);
5305 void CheckIdentifierToken (int yyToken, Location loc)
5307 CheckToken (1041, yyToken, "Identifier expected", loc);
5310 string ConsumeStoredComment ()
5312 string s = tmpComment;
5314 Lexer.doc_state = XmlCommentState.Allowed;
5318 Location GetLocation (object obj)
5320 if (obj is MemberCore)
5321 return ((MemberCore) obj).Location;
5322 if (obj is MemberName)
5323 return ((MemberName) obj).Location;
5324 if (obj is LocatedToken)
5325 return ((LocatedToken) obj).Location;
5326 if (obj is Location)
5327 return (Location) obj;
5328 return lexer.Location;