⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cs-parser.jay

📁 C#编译器源代码。Micorsoft开放源代码
💻 JAY
📖 第 1 页 / 共 5 页
字号:
			int m = (int) $2;			if (!RootContext.StdLib && current_container.Name == "System.Object")				m |= Modifiers.PROTECTED | Modifiers.VIRTUAL;			else				m |= Modifiers.PROTECTED | Modifiers.OVERRIDE;                        			Method d = new Destructor (				current_class, TypeManager.system_void_expr, m, "Finalize", 				new Parameters (null, null), (Attributes) $1, l);			if (RootContext.Documentation != null)				d.DocComment = ConsumeStoredComment ();		  			d.Block = (ToplevelBlock) $8;			current_container.AddMethod (d);		}	  }	;event_declaration	: opt_attributes	  opt_modifiers	  EVENT type variable_declarators SEMICOLON	  {		foreach (VariableDeclaration var in (ArrayList) $5) {			MemberName name = new MemberName (var.identifier,				var.Location);			Event e = new EventField (				current_class, (Expression) $4, (int) $2, false, name,				var.expression_or_array_initializer, (Attributes) $1);			current_container.AddEvent (e);			if (RootContext.Documentation != null) {				e.DocComment = Lexer.consume_doc_comment ();				Lexer.doc_state = XmlCommentState.Allowed;			}		}	  }	| opt_attributes	  opt_modifiers	  EVENT type namespace_or_type_name	  OPEN_BRACE	  {		implicit_value_parameter_type = (Expression) $4;  		lexer.EventParsing = true;	  }	  event_accessor_declarations	  {		lexer.EventParsing = false;  	  }	  CLOSE_BRACE	  {		MemberName name = (MemberName) $5;		if ($8 == null){			Report.Error (65, (Location) $3, "`{0}.{1}': event property must have both add and remove accessors",				current_container.Name, name);			$$ = null;		} else {			Pair pair = (Pair) $8;			if (pair.First == null || pair.Second == null)				// CS0073 is already reported, so no CS0065 here.				$$ = null;			else {				Event e = new EventProperty (					current_class, (Expression) $4, (int) $2, false, name, null,					(Attributes) $1, (Accessor) pair.First, (Accessor) pair.Second);				if (RootContext.Documentation != null) {					e.DocComment = Lexer.consume_doc_comment ();					Lexer.doc_state = XmlCommentState.Allowed;				}				current_container.AddEvent (e);				implicit_value_parameter_type = null;			}		}	  }	| opt_attributes opt_modifiers EVENT type namespace_or_type_name error {		MemberName mn = (MemberName) $5;		if (mn.Left != null)			Report.Error (71, mn.Location, "An explicit interface implementation of an event must use property syntax");		else 			Report.Error (71, mn.Location, "Event declaration should use property syntax");		if (RootContext.Documentation != null)			Lexer.doc_state = XmlCommentState.Allowed;	  }	;event_accessor_declarations	: add_accessor_declaration remove_accessor_declaration	  {		$$ = new Pair ($1, $2);	  }	| remove_accessor_declaration add_accessor_declaration	  {		$$ = new Pair ($2, $1);	  }		| add_accessor_declaration  { $$ = null; } 	| remove_accessor_declaration { $$ = null; } 	| error	  { 		Report.Error (1055, GetLocation ($1), "An add or remove accessor expected");		$$ = null;	  }	| { $$ = null; }	;add_accessor_declaration	: opt_attributes ADD	  {		Parameter [] args = new Parameter [1];		Parameter implicit_value_parameter = new Parameter (			implicit_value_parameter_type, "value", 			Parameter.Modifier.NONE, null, (Location) $2);		args [0] = implicit_value_parameter;				current_local_parameters = new Parameters (args, null);  		lexer.EventParsing = false;	  }          block	  {		$$ = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, (Location) $2);		lexer.EventParsing = true;	  }	| opt_attributes ADD error {		Report.Error (73, (Location) $2, "An add or remove accessor must have a body");		$$ = null;	  }	| opt_attributes modifiers ADD {		Report.Error (1609, (Location) $3, "Modifiers cannot be placed on event accessor declarations");		$$ = null;	  }	;remove_accessor_declaration	: opt_attributes REMOVE	  {		Parameter [] args = new Parameter [1];		Parameter implicit_value_parameter = new Parameter (			implicit_value_parameter_type, "value", 			Parameter.Modifier.NONE, null, (Location) $2);		args [0] = implicit_value_parameter;				current_local_parameters = new Parameters (args, null);  		lexer.EventParsing = false;	  }          block	  {		$$ = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, (Location) $2);		lexer.EventParsing = true;	  }	| opt_attributes REMOVE error {		Report.Error (73, (Location) $2, "An add or remove accessor must have a body");		$$ = null;	  }	| opt_attributes modifiers REMOVE {		Report.Error (1609, (Location) $3, "Modifiers cannot be placed on event accessor declarations");		$$ = null;	  }	;indexer_declaration	: opt_attributes opt_modifiers indexer_declarator 	  OPEN_BRACE	  {		IndexerDeclaration decl = (IndexerDeclaration) $3;		implicit_value_parameter_type = decl.type;				lexer.PropertyParsing = true;		parsing_indexer  = true;				indexer_parameters = decl.param_list;	  }          accessor_declarations 	  {		  lexer.PropertyParsing = false;		  has_get = has_set = false;		  parsing_indexer  = false;	  }	  CLOSE_BRACE	  { 		if ($6 == null)			break;		// The signature is computed from the signature of the indexer.  Look	 	// at section 3.6 on the spec		Indexer indexer;		IndexerDeclaration decl = (IndexerDeclaration) $3;		Location loc = decl.location;		Pair pair = (Pair) $6;		Accessor get_block = (Accessor) pair.First;		Accessor set_block = (Accessor) pair.Second;		MemberName name;		if (decl.interface_type != null)			name = new MemberName (decl.interface_type, TypeContainer.DefaultIndexerName, loc);		else			name = new MemberName (TypeContainer.DefaultIndexerName, loc);		indexer = new Indexer (current_class, decl.type, name,				       (int) $2, false, decl.param_list, (Attributes) $1,				       get_block, set_block);		if (RootContext.Documentation != null)			indexer.DocComment = ConsumeStoredComment ();		current_container.AddIndexer (indexer);				current_local_parameters = null;		implicit_value_parameter_type = null;		indexer_parameters = null;	  }	;indexer_declarator	: type THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET	  {		Parameters pars = (Parameters) $4;		if (pars.HasArglist) {			// "__arglist is not valid in this context"			Report.Error (1669, (Location) $2, "__arglist is not valid in this context");		} else if (pars.FixedParameters == null && pars.ArrayParameter == null){			Report.Error (1551, (Location) $2, "Indexers must have at least one parameter");		}		if (RootContext.Documentation != null) {			tmpComment = Lexer.consume_doc_comment ();			Lexer.doc_state = XmlCommentState.Allowed;		}		$$ = new IndexerDeclaration ((Expression) $1, null, pars, (Location) $2);	  }	| type namespace_or_type_name DOT THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET	  {		Parameters pars = (Parameters) $6;		if (pars.HasArglist) {			// "__arglist is not valid in this context"			Report.Error (1669, (Location) $4, "__arglist is not valid in this context");		} else if (pars.FixedParameters == null && pars.ArrayParameter == null){			Report.Error (1551, (Location) $4, "Indexers must have at least one parameter");		}		MemberName name = (MemberName) $2;		$$ = new IndexerDeclaration ((Expression) $1, name, pars, (Location) $4);		if (RootContext.Documentation != null) {			tmpComment = Lexer.consume_doc_comment ();			Lexer.doc_state = XmlCommentState.Allowed;		}	  }	;enum_declaration	: opt_attributes	  opt_modifiers	  opt_partial	  ENUM IDENTIFIER 	  opt_enum_base {		if (RootContext.Documentation != null)			enumTypeComment = Lexer.consume_doc_comment ();	  }	  enum_body	  opt_semicolon	  {		LocatedToken lt = (LocatedToken) $5;		Location enum_location = lt.Location;		if ($3 != null) {			Report.Error (267, lt.Location, "The partial modifier can only appear immediately before `class', `struct' or `interface'");			break;	// assumes that the parser put us in a switch		}		MemberName name = MakeName (new MemberName (lt.Value, enum_location));		Enum e = new Enum (current_namespace, current_class, (Expression) $6, (int) $2,				   name, (Attributes) $1);				if (RootContext.Documentation != null)			e.DocComment = enumTypeComment;		EnumMember em = null;		foreach (VariableDeclaration ev in (ArrayList) $8) {			em = new EnumMember (e, em, (Expression) ev.expression_or_array_initializer,				new MemberName (ev.identifier, ev.Location), ev.OptAttributes);//			if (RootContext.Documentation != null)				em.DocComment = ev.DocComment;			e.AddEnumMember (em);		}		current_container.AddEnum (e);		RootContext.Tree.RecordDecl (current_namespace.NS, name, e);		$$ = e;	  }	;opt_enum_base	: /* empty */		{ $$ = TypeManager.system_int32_expr; }	| COLON type		{ $$ = $2;   }	;enum_body	: OPEN_BRACE	  {		if (RootContext.Documentation != null)			Lexer.doc_state = XmlCommentState.Allowed;	  }	  opt_enum_member_declarations	  {	  	// here will be evaluated after CLOSE_BLACE is consumed.		if (RootContext.Documentation != null)			Lexer.doc_state = XmlCommentState.Allowed;	  }	  CLOSE_BRACE	  {		$$ = $3;	  }	;opt_enum_member_declarations	: /* empty */			{ $$ = new ArrayList (4); }	| enum_member_declarations opt_comma { $$ = $1; }	;enum_member_declarations	: enum_member_declaration 	  {		ArrayList l = new ArrayList (4);		l.Add ($1);		$$ = l;	  }	| enum_member_declarations COMMA enum_member_declaration	  {		ArrayList l = (ArrayList) $1;		l.Add ($3);		$$ = l;	  }	;enum_member_declaration	: opt_attributes IDENTIFIER 	  {		VariableDeclaration vd = new VariableDeclaration (			(LocatedToken) $2, null, (Attributes) $1);		if (RootContext.Documentation != null) {			vd.DocComment = Lexer.consume_doc_comment ();			Lexer.doc_state = XmlCommentState.Allowed;		}		$$ = vd;	  }	| opt_attributes IDENTIFIER	  {		if (RootContext.Documentation != null) {			tmpComment = Lexer.consume_doc_comment ();			Lexer.doc_state = XmlCommentState.NotAllowed;		}	  }          ASSIGN expression	  { 		VariableDeclaration vd = new VariableDeclaration (			(LocatedToken) $2, $5, (Attributes) $1);		if (RootContext.Documentation != null)			vd.DocComment = ConsumeStoredComment ();		$$ = vd;	  }	;delegate_declaration	: opt_attributes	  opt_modifiers	  DELEGATE type member_name	  OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS 	  SEMICOLON	  {		MemberName name = MakeName ((MemberName) $5);		Delegate del = new Delegate (current_namespace, current_class, (Expression) $4,					     (int) $2, name, (Parameters) $7, (Attributes) $1);		if (RootContext.Documentation != null) {			del.DocComment = Lexer.consume_doc_comment ();			Lexer.doc_state = XmlCommentState.Allowed;		}		current_container.AddDelegate (del);		RootContext.Tree.RecordDecl (current_namespace.NS, name, del);		$$ = del;	  }		;namespace_or_type_name	: member_name	| IDENTIFIER DOUBLE_COLON IDENTIFIER {		LocatedToken lt1 = (LocatedToken) $1;		LocatedToken lt2 = (LocatedToken) $3;		$$ = new MemberName (lt1.Value, lt2.Value, lt2.Location);	  }	| namespace_or_type_name DOT IDENTIFIER {		LocatedToken lt = (LocatedToken) $3;		$$ = new MemberName ((MemberName) $1, lt.Value);	  }	;member_name	: IDENTIFIER {		LocatedToken lt = (LocatedToken) $1;		$$ = new MemberName (lt.Value, lt.Location);	  }	;/*  * Before you think of adding a return_type, notice that we have been * using two rules in the places where it matters (one rule using type * and another identical one that uses VOID as the return type).  This * gets rid of a shift/reduce couple */type	: namespace_or_type_name	  {		MemberName name = (MemberName) $1;		$$ = name.GetTypeExpression ();	  }	| builtin_types	| array_type	| pointer_type	  	;pointer_type	: type STAR	  {		//		// Note that here only unmanaged types are allowed but we		// can't perform checks during this phase - we do it during		// semantic analysis.		//		$$ = new ComposedCast ((Expression) $1, "*", Lexer.Location);	  }	| VOID STAR	  {		$$ = new ComposedCast (TypeManager.system_void_expr, "*", (Location) $1);	  }	;non_expression_type	: builtin_types		| non_expression_type rank_specifier	  {		Location loc = GetLocation ($1);		if (loc.IsNull)			loc = lexer.Location;		$$ = new ComposedCast ((Expression) $1, (string) $2, loc);	  }	| non_expression_type STAR	  {		Location loc = GetLocation ($1);		if (loc.IsNull)			loc = lexer.Location;		$$ = new ComposedCast ((Expression) $1, "*", loc);	  }	| expression rank_specifiers 	  {		$$ = new ComposedCast ((Expression) $1, (string) $2);	  }	| expression STAR 	  {		$$ = new ComposedCast ((Expression) $1, "*");	  }		//	// We need this because the parser will happily go and reduce IDENTIFIER STAR	// through this different path	//	| multiplicative_expression STAR 	  {		$$ = new ComposedCast ((Expression) $1, "*");	  }	;type_list	: type	  {		ArrayList types = new ArrayList (4);		types.Add ($1);		$$ = types;	  }	| type_list COMMA type	  {		ArrayList types = (ArrayList) $1;		types.Add ($3);		$$ = types;	  }	;/* * replaces all the productions for isolating the various * simple types, but we need this to reuse it easily in local_variable_type */builtin_types	: OBJECT	{ $$ = TypeManager.system_object_expr; }	| STRING	{ $$ = TypeManager.system_string_expr; }	| BOOL		{ $$ = TypeManager.system_boolean_expr; }	| DECIMAL	{ $$ = TypeManager.system_decimal_expr; }	| FLOAT		{ $$ = TypeManager.system_single_expr; }	| 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -