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

📄 vbnet.atg

📁 根据cs源码解析为codedom
💻 ATG
📖 第 1 页 / 共 5 页
字号:
			Identifier				(. name = t.val; .)
			"Lib" LiteralString		(. library = t.literalValue as string; .)
			["Alias" LiteralString	(. alias = t.literalValue as string; .)]
			[ "("	[ FormalParameterList<p> ] ")" ]
			EOL
			(.
				DeclareDeclaration declareDeclaration = new DeclareDeclaration(name, m.Modifier, null, p, attributes, library, alias, charsetModifer);
				declareDeclaration.StartLocation = m.GetDeclarationLocation(startPos);
				declareDeclaration.EndLocation   = t.EndLocation;
				compilationUnit.AddChild(declareDeclaration);
			.)
		|
			"Function" 
			Identifier					(. name = t.val; .)
			"Lib" LiteralString		(. library = t.literalValue as string; .)
			["Alias" LiteralString	(. alias = t.literalValue as string; .)]
			[ "("	[ FormalParameterList<p> ] ")" ]
			["As" TypeName<out type> ]
			EOL
			(.
				DeclareDeclaration declareDeclaration = new DeclareDeclaration(name, m.Modifier, type, p, attributes, library, alias, charsetModifer);
				declareDeclaration.StartLocation = m.GetDeclarationLocation(startPos);
				declareDeclaration.EndLocation   = t.EndLocation;
				compilationUnit.AddChild(declareDeclaration);
			.)
		)
|
	/* 9. 4 */
	"Event"
	(.
		m.Check(Modifiers.VBEvents);
		Location startPos = t.Location;
		EventDeclaration eventDeclaration;
		string name = String.Empty;
		List<InterfaceImplementation> implementsClause = null;
	.)
	Identifier (. name= t.val; .)
	(
		"As" TypeName<out type>
		|
		[ "("	[ FormalParameterList<p> ] ")" ]
	)
	[ ImplementsClause<out implementsClause> ]
	(.
		eventDeclaration = new EventDeclaration(type, m.Modifier, p, attributes, name, implementsClause);
		eventDeclaration.StartLocation = m.GetDeclarationLocation(startPos);
		eventDeclaration.EndLocation = t.EndLocation;
		compilationUnit.AddChild(eventDeclaration);
	.)
	EOL
| /* 9.6 */
	(. Location startPos = t.Location; .)
	(.
		m.Check(Modifiers.Fields);
		FieldDeclaration fd = new FieldDeclaration(attributes, null, m.Modifier);
		fd.StartLocation = m.GetDeclarationLocation(startPos); 
	.)
	IdentifierForFieldDeclaration (. string name = t.val; .)
	VariableDeclaratorPartAfterIdentifier<variableDeclarators, name>
	{ "," VariableDeclarator<variableDeclarators> }
	EOL
	(.
		fd.EndLocation = t.EndLocation;
		fd.Fields = variableDeclarators;
		compilationUnit.AddChild(fd);
	.)
	| /* 9.4 */
	(. m.Check(Modifiers.Fields); .)
	"Const" (.  m.Add(Modifiers.Const, t.Location);  .)
	(.
		FieldDeclaration fd = new FieldDeclaration(attributes, type, m.Modifier);
		fd.StartLocation = m.GetDeclarationLocation(t.Location);
		List<VariableDeclaration> constantDeclarators = new List<VariableDeclaration>();
	.)
	ConstantDeclarator<constantDeclarators>
	{ "," ConstantDeclarator<constantDeclarators> }
	(.
		fd.Fields = constantDeclarators;
		fd.EndLocation = t.Location;
	.)
	EOL
	(.
		fd.EndLocation = t.EndLocation;
		compilationUnit.AddChild(fd);
	.)
| /* 9.7 */
	"Property"
	(.
		m.Check(Modifiers.VBProperties);
		Location startPos = t.Location;
		List<InterfaceImplementation> implementsClause = null;
	.)
	Identifier (. string propertyName = t.val; .)
	[ "("	[ FormalParameterList<p> ] ")" ]
	[ "As" TypeName<out type> ]
	(.
		if(type == null) {
			type = new TypeReference("System.Object");
		}
	.)
	[ ImplementsClause<out implementsClause> ]
	EOL
	(
	/* abstract properties without a body */
	IF(IsMustOverride(m))
		(.
			PropertyDeclaration pDecl = new PropertyDeclaration(propertyName, type, m.Modifier, attributes);
			pDecl.StartLocation = m.GetDeclarationLocation(startPos);
			pDecl.EndLocation   = t.Location;
			pDecl.TypeReference = type;
			pDecl.InterfaceImplementations = implementsClause;
			pDecl.Parameters = p;
			compilationUnit.AddChild(pDecl);
		.)
	|
		(.
			PropertyDeclaration pDecl = new PropertyDeclaration(propertyName, type, m.Modifier, attributes);
			pDecl.StartLocation = m.GetDeclarationLocation(startPos);
			pDecl.EndLocation   = t.Location;
			pDecl.BodyStart   = t.Location;
			pDecl.TypeReference = type;
			pDecl.InterfaceImplementations = implementsClause;
			pDecl.Parameters = p;
			PropertyGetRegion getRegion;
			PropertySetRegion setRegion;
		.)
		AccessorDecls<out getRegion, out setRegion> 
		"End" "Property"
		EOL
		(.
			pDecl.GetRegion = getRegion;
			pDecl.SetRegion = setRegion;
			pDecl.BodyEnd = t.EndLocation;
			compilationUnit.AddChild(pDecl);
		.)
	)
|
	"Custom" (. Location startPos = t.Location; .) "Event"
	(.
		m.Check(Modifiers.VBCustomEvents);
		EventAddRemoveRegion eventAccessorDeclaration;
		EventAddRegion addHandlerAccessorDeclaration = null;
		EventRemoveRegion removeHandlerAccessorDeclaration = null;
		EventRaiseRegion raiseEventAccessorDeclaration = null;
		List<InterfaceImplementation> implementsClause = null;
	.)
	Identifier (. string customEventName = t.val; .)
	"As" TypeName<out type>
	[ ImplementsClause<out implementsClause> ]
	EOL
	{
		EventAccessorDeclaration<out eventAccessorDeclaration>
		(.
			if(eventAccessorDeclaration is EventAddRegion)
			{
				addHandlerAccessorDeclaration = (EventAddRegion)eventAccessorDeclaration;
			}
			else if(eventAccessorDeclaration is EventRemoveRegion)
			{
				removeHandlerAccessorDeclaration = (EventRemoveRegion)eventAccessorDeclaration;
			}
			else if(eventAccessorDeclaration is EventRaiseRegion)
			{
				raiseEventAccessorDeclaration = (EventRaiseRegion)eventAccessorDeclaration;
			}
		.)
	}
	"End" "Event" EOL
	(.
		if(addHandlerAccessorDeclaration == null)
		{
			Error("Need to provide AddHandler accessor.");
		}
		
		if(removeHandlerAccessorDeclaration == null)
		{
			Error("Need to provide RemoveHandler accessor.");
		}
		
		if(raiseEventAccessorDeclaration == null)
		{
			Error("Need to provide RaiseEvent accessor.");
		}
	
		EventDeclaration decl = new EventDeclaration(type, customEventName, m.Modifier, attributes, null);
		decl.StartLocation = m.GetDeclarationLocation(startPos);
		decl.EndLocation = t.EndLocation;
		decl.AddRegion = addHandlerAccessorDeclaration;
		decl.RemoveRegion = removeHandlerAccessorDeclaration;
		decl.RaiseRegion = raiseEventAccessorDeclaration;
		compilationUnit.AddChild(decl);
	.)
|   (. ConversionType opConversionType = ConversionType.None; .)
	[ "Widening"		(. opConversionType = ConversionType.Implicit; .)
	| "Narrowing"		(. opConversionType = ConversionType.Explicit;.) ]
	"Operator"
	(.
		m.Check(Modifiers.VBOperators);
		Location startPos = t.Location;
		TypeReference returnType = NullTypeReference.Instance;
		TypeReference operandType = NullTypeReference.Instance;
		string operandName;
		OverloadableOperatorType operatorType;
		AttributeSection section;
		List<ParameterDeclarationExpression> parameters = new List<ParameterDeclarationExpression>();
		List<AttributeSection> returnTypeAttributes = new List<AttributeSection>();
	.)
	OverloadableOperator<out operatorType>
	"(" [ "ByVal" ] Identifier (. operandName = t.val; .)
		[ "As" TypeName<out operandType> ]
		(. parameters.Add(new ParameterDeclarationExpression(operandType, operandName, ParameterModifiers.In)); .)
		
		{
			","
			[ "ByVal" ] Identifier (. operandName = t.val; .)
			[ "As" TypeName<out operandType> ]
			(. parameters.Add(new ParameterDeclarationExpression(operandType, operandName, ParameterModifiers.In)); .)
		}
	")"
	(. Location endPos = t.EndLocation; .)
	[ "As" { AttributeSection<out section> (. returnTypeAttributes.Add(section); .) } TypeName<out returnType> (. endPos = t.EndLocation; .) EOL ]
	Block<out stmt> "End" "Operator" EOL
	(.
		OperatorDeclaration operatorDeclaration = new OperatorDeclaration(m.Modifier, 
		                                                                  attributes, 
		                                                                  parameters, 
		                                                                  returnType,
		                                                                  operatorType
		                                                                  );
		operatorDeclaration.ConversionType = opConversionType;
		operatorDeclaration.ReturnTypeAttributes = returnTypeAttributes;
		operatorDeclaration.Body = (BlockStatement)stmt;
		operatorDeclaration.StartLocation = m.GetDeclarationLocation(startPos);
		operatorDeclaration.EndLocation = endPos;
		operatorDeclaration.Body.StartLocation = startPos;
		operatorDeclaration.Body.EndLocation = t.Location;
		compilationUnit.AddChild(operatorDeclaration);
	.)
.

OverloadableOperator<out OverloadableOperatorType operatorType>
	(. operatorType = OverloadableOperatorType.None; .)
	=
	"+"			(. operatorType = OverloadableOperatorType.Add; .)
	|
	"-"			(. operatorType = OverloadableOperatorType.Subtract; .)
	|
	"*"			(. operatorType = OverloadableOperatorType.Multiply; .)
	| 
	"/"			(. operatorType = OverloadableOperatorType.Divide; .)
	| 
	"\\"		(. operatorType = OverloadableOperatorType.DivideInteger; .)
	| 
	"&"			(. operatorType = OverloadableOperatorType.Concat; .)
	| 
	"Like"		(. operatorType = OverloadableOperatorType.Like; .)
	| 
	"Mod"		(. operatorType = OverloadableOperatorType.Modulus; .)
	| 
	"And"		(. operatorType = OverloadableOperatorType.BitwiseAnd; .)
	|
	"Or"		(. operatorType = OverloadableOperatorType.BitwiseOr; .)
	|
	"Xor"		(. operatorType = OverloadableOperatorType.ExclusiveOr; .)
	|
	"^"			(. operatorType = OverloadableOperatorType.Power; .)
	|
	"<<"		(. operatorType = OverloadableOperatorType.ShiftLeft; .)
	|
	">>"		(. operatorType = OverloadableOperatorType.ShiftRight; .)
	|
	"="			(. operatorType = OverloadableOperatorType.Equality; .)
	|
	"<>"		(. operatorType = OverloadableOperatorType.InEquality; .)
	|
	"<"			(. operatorType = OverloadableOperatorType.LessThan; .)
	|
	"<="		(. operatorType = OverloadableOperatorType.LessThanOrEqual; .)
	|
	">"			(. operatorType = OverloadableOperatorType.GreaterThan; .)
	|
	">="		(. operatorType = OverloadableOperatorType.GreaterThanOrEqual; .)
	|
	"CType"		(. operatorType = OverloadableOperatorType.CType; .)
	|
	Identifier
	(.
		string opName = t.val; 
		if (string.Equals(opName, "istrue", StringComparison.InvariantCultureIgnoreCase)) {
			operatorType = OverloadableOperatorType.IsTrue;
		} else if (string.Equals(opName, "isfalse", StringComparison.InvariantCultureIgnoreCase)) {
			operatorType = OverloadableOperatorType.IsFalse;
		} else {
			Error("Invalid operator. Possible operators are '+', '-', 'Not', 'IsTrue', 'IsFalse'.");
		}
	.)
	.

EventAccessorDeclaration<out EventAddRemoveRegion eventAccessorDeclaration>
	(.
		Statement stmt = null;
		List<ParameterDeclarationExpression> p = new List<ParameterDeclarationExpression>();
		AttributeSection section;
		List<AttributeSection> attributes = new List<AttributeSection>();
		eventAccessorDeclaration = null;
	.) =
	{ AttributeSection<out section> (. attributes.Add(section); .) }
	(
			"AddHandler" [ "(" [ FormalParameterList<p> ] ")" ] EOL
			Block<out stmt> "End" "AddHandler" EOL
			(.
				eventAccessorDeclaration = new EventAddRegion(attributes);
				eventAccessorDeclaration.Block = (BlockStatement)stmt;
				eventAccessorDeclaration.Parameters = p;
			.)
		|
			"RemoveHandler" [ "(" [ FormalParameterList<p> ] ")" ] EOL
			Block<out stmt> "End" "RemoveHandler" EOL
			(.
				eventAccessorDeclaration = new EventRemoveRegion(attributes);
				eventAccessorDeclaration.Block = (BlockStatement)stmt;
				eventAccessorDeclaration.Parameters = p;
			.)
		|
			"RaiseEvent" [ "(" [ FormalParameterList<p> ] ")" ] EOL
			Block<out stmt> "End" "RaiseEvent" EOL
			(.
				eventAccessorDeclaration = new EventRaiseRegion(attributes);
				eventAccessorDeclaration.Block = (BlockStatement)stmt;
				eventAccessorDeclaration.Parameters = p;
			.)
	)
	.

/* 9.7 */
AccessorDecls<out PropertyGetRegion getBlock, out PropertySetRegion setBlock>
	(.
		List<AttributeSection> attributes = new List<AttributeSection>();
		AttributeSection section;
		getBlock = null;
		setBlock = null; 
	.) =
	{ AttributeSection<out section> (. attributes.Add(section); .) }
	(
		GetAccessorDecl<out getBlock, attributes>
		[
			(. attributes = new List<AttributeSection>(); .)
			{ AttributeSection<out section> (. attributes.Add(section); .) }
			SetAccessorDecl<out setBlock, attributes>
		]
		|
		SetAccessorDecl<out setBlock, attributes>
		[
			(. attributes = new List<AttributeSection>(); .)
			{ AttributeSection<out section> (. attributes.Add(section); .) }
			GetAccessorDecl<out getBlock, attributes>
		]
	)
	.

/* 9.7.1 */
GetAccessorDecl<out PropertyGetRegion getBlock, List<AttributeSection> attributes>
	(. Statement stmt = null; Modifiers m; .)
=
	PropertyAccessorAccessModifier<out m>
	"Get"
	(. Location startLocation = t.Location; .)
	EOL
	Block<out stmt>
	(. getBlock = new PropertyGetRegion((BlockStatement)stmt, attributes); .)
	"End" "Get"
	(. getBlock.Modifier = m; .)
	(. getBlock.StartLocation = startLocation; getBlock.EndLocation = t.EndLocation; .)
	EOL
	.

/* 9.7.2 */
SetAccessorDecl<out PropertySetRegion setBlock, List<AttributeSection> attributes>
	(.
		Statement stmt = null;
		List<ParameterDeclarationExpression> p = new List<ParameterDeclarationExpression>();
		Modifiers m;
	.)
=
	PropertyAccessorAccessModifier<out m>
	"Set"
	(. Location startLocation = t.Location; .)
	[ "("	[ FormalParameterList<p> ] ")" ]
	EOL
	Block<out stmt>
	(.
		setBlock = new PropertySetRegion((BlockStatement)stmt, attributes);
		setBlock.Modifier = m;
		setBlock.Parameters = p;
	.)
	"End" "Set"
	(. setBlock.StartLocation = startLocation; setBlock.EndLocation = t.EndLocation; .)
	EOL
	.

/* 9.5 */
ConstantDeclarator<List<VariableDeclaration> constantDeclaration>
	(.
		Expression expr = null;
		TypeReference type = null;
		string name = String.Empty;
	.) =
	Identifier				(. name = t.val; .)
	["As" TypeName<out type> ]
	"=" Expr<out expr>
	(.
		VariableDeclaration f = new VariableDeclaration(name, expr);
		f.TypeReference = type;
		constantDeclaration.Add(f);
	.)
.

/* 9.6 */
VariableDeclarator<List<VariableDeclaration> fieldDeclaration>
=
	Identifier (. string name = t.val; .)
	VariableDeclaratorPartAfterIdentifier<fieldDeclaration, name>
.

VariableDeclaratorPartAfterIdentifier<List<VariableDeclaration> fieldDeclaration, string name>
	(.
		Expression expr = null;
		TypeReference type = null;
		ArrayList rank = null;
		List<Expression> dimension = null;
	.) =
	[ IF(IsSize() && !IsDims()) ArrayInitializationModifier<out dimension> ]
	[ IF(IsDims())              ArrayNameModifier<out rank> ]
	(
		IF (IsObjectCreation()) "As" ObjectCreateExpression<out expr>
		(.
			if (expr is ObjectCreateExpression) {
				type = ((ObjectCreateExpression)expr).CreateType;
			} else {
				type = ((ArrayCreateExpression)expr).CreateType;
			}
		.)
	|
		[ "As" TypeName<out type>
		  (.
			if (type != null) {
				for (int i = fieldDeclaration.Count - 1; i >= 0; i--) {
					VariableDeclaration vd = fieldDeclaration[i];
					if (vd.TypeReference.Type.Length > 0) break;
					TypeReference newType = type.Clone();
					newType.RankSpecifier = vd.TypeReference.RankSpecifier;
					vd.TypeReference = newType;
				}
			}
		  .)
		]
		(.
			if (type == null && (dimension != null || rank != null)) {

⌨️ 快捷键说明

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