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

📄 vbnet.atg

📁 根据cs源码解析为codedom
💻 ATG
📖 第 1 页 / 共 5 页
字号:
	Expression initializer = null;
	List<Expression> arguments = null;
	ArrayList dimensions = null;
	oce = null;
	bool canBeNormal; bool canBeReDim;
.) =
	"New" NonArrayTypeName<out type, false>
	["(" NormalOrReDimArgumentList<out arguments, out canBeNormal, out canBeReDim> ")"
		[ IF (la.kind == Tokens.OpenParenthesis)
			ArrayTypeModifiers<out dimensions>
			ArrayInitializer<out initializer>
		|	ArrayInitializer<out initializer>
		]
		(. if (canBeReDim && !canBeNormal && initializer == null) initializer = new ArrayInitializerExpression(); .)
	]
	(.
		if (type == null) type = new TypeReference("Object"); // fallback type on parser errors
		if (initializer == null) {
			oce = new ObjectCreateExpression(type, arguments);
		} else {
			if (dimensions == null) dimensions = new ArrayList();
			dimensions.Insert(0, (arguments == null) ? 0 : Math.Max(arguments.Count - 1, 0));
			type.RankSpecifier = (int[])dimensions.ToArray(typeof(int));
			ArrayCreateExpression ace = new ArrayCreateExpression(type, initializer as ArrayInitializerExpression);
			ace.Arguments = arguments;
			oce = ace;
		}
	.)
.

/* 9.3.2 */
ArgumentList<out List<Expression> arguments>
	(.
		arguments = new List<Expression>();
		Expression expr = null;
	.) =
	[ Argument<out expr> ]
	{ "," (. arguments.Add(expr ?? Expression.Null); expr = null; .)
		[ Argument<out expr> ]
		(. if (expr == null) expr = Expression.Null; .)
	}
	(. if (expr != null) arguments.Add(expr); .)
.

/* argument list that hasn't decided if it is method call or array initialisation */
NormalOrReDimArgumentList<out List<Expression> arguments, out bool canBeNormal, out bool canBeRedim>
	(.
		arguments = new List<Expression>();
		canBeNormal = true; canBeRedim = !IsNamedAssign();
		Expression expr = null;
	.)
=
	[ Argument<out expr>
	  [ "To" (. EnsureIsZero(expr); canBeNormal = false; .)
	    Expr<out expr>
	] ]
	{ ","
		(. if (expr == null) canBeRedim = false; .)
		(. arguments.Add(expr ?? Expression.Null); expr = null; .)
		(. canBeRedim &= !IsNamedAssign(); .)
		[ Argument<out expr>
		  [ "To" (. EnsureIsZero(expr); canBeNormal = false; .)
		    Expr<out expr>
		] ]
		(. if (expr == null) { canBeRedim = false; expr = Expression.Null; } .)
	}
	(. if (expr != null) arguments.Add(expr); else canBeRedim = false; .)
.

/* Spec, 11.8 */
Argument<out Expression argumentexpr>
	(.
		Expression expr;
		argumentexpr = null;
		string name;
	.) =
	IF(IsNamedAssign()) Identifier (. name = t.val;  .) ":" "=" Expr<out expr>
	(.
		argumentexpr = new NamedArgumentExpression(name, expr);
	.)
	|
	Expr<out argumentexpr>
.

/* 7.1. */
TypeName<out TypeReference typeref>
(. ArrayList rank = null; .)
=
	NonArrayTypeName<out typeref, false>
	ArrayTypeModifiers<out rank>
	(.	if (rank != null && typeref != null) {
			typeref.RankSpecifier = (int[])rank.ToArray(typeof(int));
		}
	.)
.

GetTypeTypeName<out TypeReference typeref>
(. ArrayList rank = null; .)
=
	NonArrayTypeName<out typeref, true>
	ArrayTypeModifiers<out rank>
	(.	if (rank != null && typeref != null) {
			typeref.RankSpecifier = (int[])rank.ToArray(typeof(int));
		}
	.)
.

/* 7.1 */
NonArrayTypeName<out TypeReference typeref, bool canBeUnbound>
(.
	string name;
	typeref = null;
	bool isGlobal = false;
.) =
	(
		[ "Global" "." (. isGlobal = true; .) ]
		QualIdentAndTypeArguments<out typeref, canBeUnbound>
		(. typeref.IsGlobal = isGlobal; .)
		{ "." (. TypeReference nestedTypeRef; .)
			QualIdentAndTypeArguments<out nestedTypeRef, canBeUnbound>
			(. typeref = new InnerClassTypeReference(typeref, nestedTypeRef.Type, nestedTypeRef.GenericTypes); .)
		}
	)
	| "Object" (. typeref = new TypeReference("System.Object"); .)
	| PrimitiveTypeName<out name> (. typeref = new TypeReference(name); .)
.

QualIdentAndTypeArguments<out TypeReference typeref, bool canBeUnbound>
(. string name; typeref = null; .)
=
	Qualident<out name>
	(. typeref = new TypeReference(name); .)
	[IF (la.kind == Tokens.OpenParenthesis && Peek(1).kind == Tokens.Of)
		"(" "Of"
		( IF (canBeUnbound && (la.kind == Tokens.CloseParenthesis || la.kind == Tokens.Comma))
			(. typeref.GenericTypes.Add(NullTypeReference.Instance); .)
			{ "," (. typeref.GenericTypes.Add(NullTypeReference.Instance); .) }
		  | TypeArgumentList<typeref.GenericTypes>
		)
		")"
	]
.

/* 7.9 */
ArrayNameModifier<out ArrayList arrayModifiers>
(.
	arrayModifiers = null;
.) =
	ArrayTypeModifiers<out arrayModifiers>
.


/* 7.9 */
ArrayTypeModifiers<out ArrayList arrayModifiers>
(.
	arrayModifiers = new ArrayList();
	int i = 0;
.) =
	{	IF (IsDims())
		"("
		[ RankList<out i>]
		(.
			arrayModifiers.Add(i);
		.)
		")"
	}
	(.
		if(arrayModifiers.Count == 0) {
			 arrayModifiers = null;
		}
	.)
.

/* 7.9 */
RankList<out int i>
(. i = 0; .) =
	{ "," (. ++i; .) }
.

/* 7.12 */
TypeArgumentList<List<TypeReference> typeArguments>
(.
	TypeReference typeref;
.) =
	TypeName<out typeref> (. if (typeref != null) typeArguments.Add(typeref); .)
	{
		","
		TypeName<out typeref> (. if (typeref != null) typeArguments.Add(typeref); .)
	}
.

GlobalAttributeSection =
	"<" (. Location startPos = t.Location; .)
	("Assembly" | "Module")
		(.  string attributeTarget = t.val.ToLower(System.Globalization.CultureInfo.InvariantCulture);
			List<ASTAttribute> attributes = new List<ASTAttribute>();
			ASTAttribute attribute;
		.)
	":" Attribute<out attribute> (. attributes.Add(attribute); .)
	{ IF (NotFinalComma()) ["," ("Assembly" | "Module") ":"] Attribute<out attribute> (. attributes.Add(attribute); .)}
	[ "," ]
	">"
	EndOfStmt
		(.
			AttributeSection section = new AttributeSection(attributeTarget, attributes);
			section.StartLocation = startPos;
			section.EndLocation = t.EndLocation;
			compilationUnit.AddChild(section);
		.)
	.

/* Spec, 5. */
Attribute<out ASTAttribute attribute>
(. string name;
   List<Expression> positional = new List<Expression>();
   List<NamedArgumentExpression> named = new List<NamedArgumentExpression>();
.) =
	[ "Global" "." ]
	Qualident<out name>
	[ AttributeArguments<positional, named> ]
	(. attribute  = new ASTAttribute(name, positional, named); .)
.

/* Spec, 5.2.2 */
AttributeArguments<List<Expression> positional, List<NamedArgumentExpression> named>
	(.
		bool nameFound = false;
		string name = "";
		Expression expr;
	.) =
	"("
	[
		IF (IsNotClosingParenthesis()) ( 
			[
				IF (IsNamedAssign()) (. nameFound = true; .)
				IdentifierOrKeyword<out name>
				[":"] "="
			] Expr<out expr>
				(.
					if (expr != null) {
						if (string.IsNullOrEmpty(name)) { positional.Add(expr); }
						else { named.Add(new NamedArgumentExpression(name, expr)); name = ""; }
					}
				.)
			{
				","
					(
						IF (IsNamedAssign())	(. nameFound = true; .)
						IdentifierOrKeyword<out name>
						[ ":" ] "="
						| (. if (nameFound) Error("no positional argument after named argument"); .)
					) Expr<out expr>	(. 	if (expr != null) { if(name == "") positional.Add(expr);
											else { named.Add(new NamedArgumentExpression(name, expr)); name = ""; }
											}
										.)
			}
		)
	]
	")"
	.

/* Spec, 5. */
AttributeSection<out AttributeSection section>
	(.
		string attributeTarget = "";List<ASTAttribute> attributes = new List<ASTAttribute>();
		ASTAttribute attribute;
		
	.) =
	"<" (. Location startPos = t.Location; .)
	[ IF (IsLocalAttrTarget())
		( "Event"		(. attributeTarget = "event";.)
		| "Return"		(. attributeTarget = "return";.)
		| Identifier
			(.
				string val = t.val.ToLower(System.Globalization.CultureInfo.InvariantCulture);
				if (val != "field"	|| val != "method" ||
					val != "module" || val != "param"  ||
					val != "property" || val != "type")
				Error("attribute target specifier (event, return, field," +
						"method, module, param, property, or type) expected");
				attributeTarget = t.val;
			.)
		) ":" 
	]
	Attribute<out attribute>	(. attributes.Add(attribute); .)
	{ IF (NotFinalComma()) "," Attribute<out attribute> (. attributes.Add(attribute); .) }
	[ "," ]
	">"
		(.
			section = new AttributeSection(attributeTarget, attributes);
			section.StartLocation = startPos;
			section.EndLocation = t.EndLocation;
		.)
	.

/* 9.2.5 */
FormalParameterList<List<ParameterDeclarationExpression> parameter>
	(.
		ParameterDeclarationExpression p;
		AttributeSection section;
		List<AttributeSection> attributes = new List<AttributeSection>();
	.) =
	{ AttributeSection<out section> (.attributes.Add(section); .) }
	(
		FormalParameter<out p>
		(.
			bool paramsFound = false;
			p.Attributes = attributes;
			parameter.Add(p);
		.)
		{
			","	(. if (paramsFound) Error("params array must be at end of parameter list"); .)
			{ AttributeSection<out section> (.attributes.Add(section); .) }
			(
				FormalParameter <out p>	(. p.Attributes = attributes; parameter.Add(p); .)
			)
		}
	)
	.
/* 9.2.5 */
FormalParameter<out ParameterDeclarationExpression p>
	(.
		TypeReference type = null;
		ParamModifierList mod = new ParamModifierList(this);
		Expression expr = null;
		p = null;ArrayList arrayModifiers = null;
	.) =
	{ ParameterModifier<mod> }
	Identifier (. string parameterName = t.val; .)
	[ IF(IsDims()) ArrayTypeModifiers<out arrayModifiers> ]
	[ "As" TypeName<out type> ]
	(.
		if(type != null) {
			if (arrayModifiers != null) {
				if (type.RankSpecifier != null) {
					Error("array rank only allowed one time");
				} else {
					type.RankSpecifier = (int[])arrayModifiers.ToArray(typeof(int));
				}
			}
		} else {
			type = new TypeReference("System.Object", arrayModifiers == null ? null : (int[])arrayModifiers.ToArray(typeof(int)));
		}
	.)
	[ "=" Expr<out expr> ]
	(.
		mod.Check();
		p = new ParameterDeclarationExpression(type, parameterName, mod.Modifier, expr);
	.)
	.

/* 10.1 */
Block<out Statement stmt>
	=
	(.
		BlockStatement blockStmt = new BlockStatement();
		/* in snippet parsing mode, t might be null */
		if (t != null) blockStmt.StartLocation = t.Location;
		compilationUnit.BlockStart(blockStmt);
	.)
	{	
			IF (IsEndStmtAhead()) "End" EndOfStmt (. compilationUnit.AddChild(new EndStatement()); .)
			| Statement EndOfStmt
/*	 	IF (!LeaveBlock()) { }*/
	}
	(.
		stmt = blockStmt;
		if (t != null) blockStmt.EndLocation = t.EndLocation;
		compilationUnit.BlockEnd();
	.)
	.

Statement
	(.
		Statement stmt = null;
		Location startPos = la.Location;
		string label = String.Empty;
		
	.) =
	(
		| IF (IsLabel()) LabelName<out label>
		(.
			compilationUnit.AddChild(new LabelStatement(t.val));
		.)
		":" Statement
		| EmbeddedStatement<out stmt>			(. compilationUnit.AddChild(stmt); .)
		| LocalDeclarationStatement<out stmt>	(. compilationUnit.AddChild(stmt); .)
	)
	(.
		if (stmt != null) {
			stmt.StartLocation = startPos;
			stmt.EndLocation = t.Location;
		}
	.)
.

/* 10.2 */
LocalDeclarationStatement<out Statement statement>
	(.
		ModifierList m = new ModifierList();
		LocalVariableDeclaration localVariableDeclaration;
		bool dimfound = false;
	.) =
	/* this differs from the spec: dim static x	compiles with vbc. */
	{
		"Const" 	(. m.Add(Modifiers.Const, t.Location); .)
		| "Static"	(. m.Add(Modifiers.Static, t.Location); .)
		| "Dim"		(. dimfound = true; .)
	}
	(.
		if(dimfound && (m.Modifier & Modifiers.Const) != 0) {
			Error("Dim is not allowed on constants.");
		}
		
		if(m.isNone && dimfound == false) {
			Error("Const, Dim or Static expected");
		}
		
		localVariableDeclaration = new LocalVariableDeclaration(m.Modifier);
		localVariableDeclaration.StartLocation = t.Location;
	.)
	VariableDeclarator<localVariableDeclaration.Variables>
	{ "," VariableDeclarator<localVariableDeclaration.Variables> }
	(.
		statement = localVariableDeclaration;
	.)
.

EmbeddedStatement<out Statement statement>
	(.
		Statement embeddedStatement = null;
		statement = null;
		Expression expr = null;
		string name = String.Empty;
		List<Expression> p = null;
	.) =
		"Exit"				(. ExitType exitType = ExitType.None; .)
		(
		"Sub"				(. exitType = ExitType.Sub; .)
		|
		"Function"			(. exitType = ExitType.Function; .)
		|
		"Property"			(. exitType = ExitType.Property; .)
		|
		"Do"				(. exitType = ExitType.Do; .)
		|
		"For"				(. exitType = ExitType.For; .)
		|
		"Try"				(. exitType = ExitType.Try; .)
		|
		"While"				(. exitType = ExitType.While; .)
		|
		"Select"			(. exitType = ExitType.Select; .)
		)
	(. statement = new ExitStatement(exitType); .)
	| TryStatement<out statement>
	| "Continue" (. ContinueType continueType = ContinueType.None; .) [ "Do" (. continueType = ContinueType.Do; .) | "For" (. continueType = ContinueType.For; .) | "While" (. continueType = ContinueType.W

⌨️ 快捷键说明

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