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

📄 cs.atg

📁 根据cs源码解析为codedom
💻 ATG
📖 第 1 页 / 共 5 页
字号:
	                                  compilationUnit.BlockStart(newType);
	                                  newType.StartLocation = m.GetDeclarationLocation(t.Location);
	                                  
	                                  newType.Type = Types.Class;
	                                .)
	ident                           (. newType.Name = t.val; .)
	
	/* .NET 2.0 */
	[ TypeParameterList<templates> ]
	
	[ ClassBase<out names>          (. newType.BaseTypes = names; .) ]
	
	/* .NET 2.0 */
	{ IF (IdentIsWhere()) TypeParameterConstraintsClause<templates> }
	
	(. newType.BodyStartLocation = t.EndLocation; .)
	"{" ClassBody "}"
	[ ";" ]                         (. newType.EndLocation = t.Location; 
	                                   compilationUnit.BlockEnd();
	                                .)
| /*--- struct declaration: */  (. m.Check(Modifiers.StructsInterfacesEnumsDelegates); .)
	( "struct"                      (. TypeDeclaration newType = new TypeDeclaration(m.Modifier, attributes);
	                                   templates = newType.Templates;
	                                   newType.StartLocation = m.GetDeclarationLocation(t.Location);
	                                   compilationUnit.AddChild(newType);
	                                   compilationUnit.BlockStart(newType);
	                                   newType.Type = Types.Struct; 
	                                 .)
	ident                            (. newType.Name = t.val; .)
	
	/* .NET 2.0 */
	[ TypeParameterList<templates> ]
	
	[ StructInterfaces<out names>    (. newType.BaseTypes = names; .) ]
	
	/* .NET 2.0 */
	{ IF (IdentIsWhere()) TypeParameterConstraintsClause<templates> }
	
	
	(. newType.BodyStartLocation = t.EndLocation; .)
	StructBody
	[ ";" ]                          (. newType.EndLocation = t.Location; 
	                                    compilationUnit.BlockEnd();
	                                 .)
| /*--- interface declaration: */ 
	"interface"                      (. TypeDeclaration newType = new TypeDeclaration(m.Modifier, attributes);
	                                    templates = newType.Templates;
	                                    compilationUnit.AddChild(newType);
	                                    compilationUnit.BlockStart(newType);
	                                    newType.StartLocation = m.GetDeclarationLocation(t.Location);
	                                    newType.Type = Types.Interface;
	                                  .)
	ident                            (. newType.Name = t.val; .)
	
	/* .NET 2.0 */
	[ TypeParameterList<templates> ]
	
	[ InterfaceBase<out names>       (. newType.BaseTypes = names; .) ]
	
	/* .NET 2.0 */
	{ IF (IdentIsWhere()) TypeParameterConstraintsClause<templates> }
	
	(. newType.BodyStartLocation = t.EndLocation; .)
	InterfaceBody
	[ ";" ]                          (. newType.EndLocation = t.Location; 
	                                    compilationUnit.BlockEnd();
	                                 .)
| /*--- enumeration declaration: */
	"enum"                           (. TypeDeclaration newType = new TypeDeclaration(m.Modifier, attributes);
	                                    compilationUnit.AddChild(newType);
	                                    compilationUnit.BlockStart(newType);
	                                    newType.StartLocation = m.GetDeclarationLocation(t.Location);
	                                    newType.Type = Types.Enum;
	                                  .)
	ident                            (. newType.Name = t.val; .)
	[ ":" IntegralType<out name>     (. newType.BaseTypes.Add(new TypeReference(name)); .)
	]
	(. newType.BodyStartLocation = t.EndLocation; .)
	EnumBody 
	[ ";" ]                          (. newType.EndLocation = t.Location; 
	                                    compilationUnit.BlockEnd();
	                                 .)
| /*--- delegate declaration: */
	"delegate"                       (. DelegateDeclaration delegateDeclr = new DelegateDeclaration(m.Modifier, attributes);
	                                    templates = delegateDeclr.Templates;
	                                    delegateDeclr.StartLocation = m.GetDeclarationLocation(t.Location);
	                                 .)
	( IF (NotVoidPointer()) "void"   (. delegateDeclr.ReturnType = new TypeReference("void", 0, null); .)
		| Type<out type>             (. delegateDeclr.ReturnType = type; .)
	)
	ident                            (. delegateDeclr.Name = t.val; .)
	
	/* .NET 2.0 */
	[ TypeParameterList<templates> ]
	
	"(" [ FormalParameterList<p> (. delegateDeclr.Parameters = p; .)
	] ")"
	
	/* .NET 2.0 */
	{ IF (IdentIsWhere()) TypeParameterConstraintsClause<templates> }
	
	";"                              (. delegateDeclr.EndLocation = t.Location;
	                                    compilationUnit.AddChild(delegateDeclr);
	                                 .)
	)
.

Qualident<out string qualident>
=
	ident                              (. qualidentBuilder.Length = 0; qualidentBuilder.Append(t.val); .)
	{ IF (DotAndIdent()) "." ident     (. qualidentBuilder.Append('.');
	                                      qualidentBuilder.Append(t.val); 
	                                    .)
	} (. qualident = qualidentBuilder.ToString(); .)
.

ClassBase<out List<TypeReference> names>
(.
	TypeReference typeRef;
	names = new List<TypeReference>();
.)
=
	":" ClassType<out typeRef, false>  (. if (typeRef != null) { names.Add(typeRef); } .)
	{ "," TypeName<out typeRef, false> (. if (typeRef != null) { names.Add(typeRef); } .) }
.

ClassBody
(. AttributeSection section; .)
=
	{                                  (.List<AttributeSection> attributes = new List<AttributeSection>();
		                                 ModifierList m = new ModifierList();
		                               .)
		{ AttributeSection<out section> (. attributes.Add(section); .) }
		MemberModifiers<m>
		ClassMemberDecl<m, attributes> 
	}
.

StructInterfaces<out List<TypeReference> names>
(.
	TypeReference typeRef;
	names = new List<TypeReference>();
.)
=
	":" TypeName<out typeRef, false>   (. if (typeRef != null) { names.Add(typeRef); } .)
	{ "," TypeName<out typeRef, false> (. if (typeRef != null) { names.Add(typeRef); } .) }
.

StructBody
(. AttributeSection section; .)
=
	"{"
	{                                    (.List<AttributeSection> attributes = new List<AttributeSection>();
		                                   ModifierList m = new ModifierList();
		                                 .)
		{ AttributeSection<out section>  (. attributes.Add(section); .) }
		MemberModifiers<m>
		StructMemberDecl<m, attributes> 
	}
	"}" 
.

InterfaceBase<out List<TypeReference> names>
(.
	TypeReference typeRef;
	names = new List<TypeReference>();
.)
=
	":" TypeName<out typeRef, false>   (. if (typeRef != null) { names.Add(typeRef); } .)
	{ "," TypeName<out typeRef, false> (. if (typeRef != null) { names.Add(typeRef); } .) }
.

InterfaceBody
= "{"
  { InterfaceMemberDecl }
  "}"
.

EnumBody                                 (. FieldDeclaration f; .)
=
	"{"
	[ EnumMemberDecl<out f>          (. compilationUnit.AddChild(f); .)
	{ IF (NotFinalComma()) ","
		EnumMemberDecl<out f> (. compilationUnit.AddChild(f); .)
	}
	[","] ] "}"
.

Type<out TypeReference type>
=
	TypeWithRestriction<out type, true, false>
.

TypeWithRestriction<out TypeReference type, bool allowNullable, bool canBeUnbound>
(.
	string name;
	int pointer = 0;
	type = null;
.)
=
	( ClassType<out type, canBeUnbound>
	| SimpleType<out name> (. type = new TypeReference(name); .)
	| "void" "*"                         (. pointer = 1; type = new TypeReference("void"); .)
	)                                    (. List<int> r = new List<int>(); .)
	
	[ IF (allowNullable && la.kind == Tokens.Question) NullableQuestionMark<ref type> ]
	
	{ IF (IsPointerOrDims())             (. int i = 0; .)
		( "*"                            (. ++pointer; .)
		| "[" { "," (. ++i; .) } "]"     (. r.Add(i); .)
		)
	}
	(. if (type != null) {
		type.RankSpecifier = r.ToArray();
		type.PointerNestingLevel = pointer;
	   }
	.)
.


NonArrayType<out TypeReference type>
(.
	string name;
	int pointer = 0;
	type = null;
.)
=
	( ClassType<out type, false>
	| SimpleType<out name> (. type = new TypeReference(name); .)
	| "void" "*"           (. pointer = 1; type = new TypeReference("void"); .)
	)
	
	[ NullableQuestionMark<ref type> ]
	
	{ IF (IsPointer())
		"*" (. ++pointer; .)
	}
	(. if (type != null) { type.PointerNestingLevel = pointer; } .)
.

SimpleType<out string name>
(. name = String.Empty; .)
=
	IntegralType<out name> 
	| "float"   (. name = "float"; .)
	| "double"  (. name = "double"; .)
	| "decimal" (. name = "decimal"; .)
	| "bool"    (. name = "bool"; .)
.


FormalParameterList<List<ParameterDeclarationExpression> parameter>
(.
	
	ParameterDeclarationExpression p;
	AttributeSection section;
	List<AttributeSection> attributes = new List<AttributeSection>();
.)
=
	{ AttributeSection<out section> (.attributes.Add(section); .) }
	(
		FixedParameter<out p> (. bool paramsFound = false;
		                         p.Attributes = attributes;
		                         parameter.Add(p);
		                      .)
		{
			","                              (. attributes = new List<AttributeSection>(); if (paramsFound) Error("params array must be at end of parameter list"); .)
			{ AttributeSection<out section> (.attributes.Add(section); .) }
			(
				FixedParameter<out p>        (. p.Attributes = attributes; parameter.Add(p); .)
				| ParameterArray<out p>      (. paramsFound = true; p.Attributes = attributes; parameter.Add(p); .)
			)
		}
		| ParameterArray<out p>              (. p.Attributes = attributes; parameter.Add(p); .)
	)
.

FixedParameter<out ParameterDeclarationExpression p>
(.
	TypeReference type;
	ParameterModifiers mod = ParameterModifiers.In;
	Location start = t.Location;
.)
=
	[
		"ref"    (. mod = ParameterModifiers.Ref; .)
		| "out"  (. mod = ParameterModifiers.Out; .)
	]
	Type<out type> ident (. p = new ParameterDeclarationExpression(type, t.val, mod); p.StartLocation = start; p.EndLocation = t.Location; .)
.

ParameterArray<out ParameterDeclarationExpression p>
(. TypeReference type; .)
=
	"params" Type<out type> ident (. p = new ParameterDeclarationExpression(type, t.val, ParameterModifiers.Params); .)
. 

AccessorModifiers<out ModifierList m>
(. m = new ModifierList(); .)
=
	"private"          (. m.Add(Modifiers.Private, t.Location); .)
	| "protected"      (. m.Add(Modifiers.Protected, t.Location); .)
	  ["internal"      (. m.Add(Modifiers.Internal, t.Location); .)]
	| "internal"       (. m.Add(Modifiers.Internal, t.Location); .)
	  ["protected"     (. m.Add(Modifiers.Protected, t.Location); .)]
.

TypeModifier<ModifierList m>
=
	"new"                              (. m.Add(Modifiers.New, t.Location); .)
	| "public"                         (. m.Add(Modifiers.Public, t.Location); .)
	| "protected"                      (. m.Add(Modifiers.Protected, t.Location); .)
	| "internal"                       (. m.Add(Modifiers.Internal, t.Location); .)
	| "private"                        (. m.Add(Modifiers.Private, t.Location); .)
	| "unsafe"                         (. m.Add(Modifiers.Unsafe, t.Location); .)
	| "abstract"                       (. m.Add(Modifiers.Abstract, t.Location); .)
	| "sealed"                         (. m.Add(Modifiers.Sealed, t.Location); .)
	| "static"                         (. m.Add(Modifiers.Static, t.Location); .)
	| ident                            (. if (t.val == "partial") { m.Add(Modifiers.Partial, t.Location); } else { Error("Unexpected identifier"); } .)
.

ClassType<out TypeReference typeRef, bool canBeUnbound>
(. TypeReference r; typeRef = null; .)
=
	TypeName<out r, canBeUnbound> (. typeRef = r; .)
	| "object"                    (. typeRef = new TypeReference("object"); .)
	| "string"                    (. typeRef = new TypeReference("string"); .)
.

⌨️ 快捷键说明

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