コード例 #1
0
		public static Expression CreateDefaultValueForType(TypeReference type)
		{
			if (type != null && !type.IsArrayType) {
				switch (type.Type) {
					case "System.SByte":
					case "System.Byte":
					case "System.Int16":
					case "System.UInt16":
					case "System.Int32":
					case "System.UInt32":
					case "System.Int64":
					case "System.UInt64":
					case "System.Single":
					case "System.Double":
						return new PrimitiveExpression(0, "0");
					case "System.Char":
						return new PrimitiveExpression('\0', "'\\0'");
					case "System.Object":
					case "System.String":
						return new PrimitiveExpression(null, "null");
					case "System.Boolean":
						return new PrimitiveExpression(false, "false");
					default:
						return new DefaultValueExpression(type);
				}
			} else {
				return new PrimitiveExpression(null, "null");
			}
		}
コード例 #2
0
		public LocalLookupVariable(string name, TypeReference typeRef, Location startPos, Location endPos, bool isConst, bool isLoopVariable, Expression initializer, LambdaExpression parentLambdaExpression, bool isQueryContinuation)
		{
			this.Name = name;
			this.TypeRef = typeRef;
			this.StartPos = startPos;
			this.EndPos = endPos;
			this.IsConst = isConst;
			this.IsLoopVariable = isLoopVariable;
			this.Initializer = initializer;
			this.ParentLambdaExpression = parentLambdaExpression;
			this.IsQueryContinuation = isQueryContinuation;
		}
コード例 #3
0
		string GetDotNetNameFromTypeReference(TypeReference type)
		{
			string name;
			InnerClassTypeReference ictr = type as InnerClassTypeReference;
			if (ictr != null) {
				name = GetDotNetNameFromTypeReference(ictr.BaseType) + "+" + ictr.Type;
			} else {
				name = type.Type;
			}
			if (type.GenericTypes.Count != 0)
				name = name + "`" + type.GenericTypes.Count.ToString();
			return name;
		}
コード例 #4
0
		public void AddVariable(TypeReference typeRef, string name,
		                        Location startPos, Location endPos, bool isConst,
		                        bool isLoopVariable, Expression initializer,
		                        LambdaExpression parentLambdaExpression,
		                        bool isQueryContinuation)
		{
			if (name == null || name.Length == 0) {
				return;
			}
			List<LocalLookupVariable> list;
			if (!variables.ContainsKey(name)) {
				variables[name] = list = new List<LocalLookupVariable>();
			} else {
				list = (List<LocalLookupVariable>)variables[name];
			}
			list.Add(new LocalLookupVariable(name, typeRef, startPos, endPos, isConst, isLoopVariable, initializer, parentLambdaExpression, isQueryContinuation));
		}
コード例 #5
0
		public virtual object VisitTypeReference(TypeReference typeReference, object data) {
			throw new global::System.NotImplementedException("TypeReference");
		}
コード例 #6
0
ファイル: TypeReference.cs プロジェクト: ThomasZitzler/ILSpy
		public static bool AreEqualReferences(TypeReference a, TypeReference b)
		{
			if (a == b) return true;
			if (a == null || b == null) return false;
			if (a is InnerClassTypeReference) a = ((InnerClassTypeReference)a).CombineToNormalTypeReference();
			if (b is InnerClassTypeReference) b = ((InnerClassTypeReference)b).CombineToNormalTypeReference();
			if (a.type != b.type) return false;
			if (a.IsKeyword != b.IsKeyword) return false;
			if (a.IsGlobal != b.IsGlobal) return false;
			if (a.pointerNestingLevel != b.pointerNestingLevel) return false;
			if (a.IsArrayType != b.IsArrayType) return false;
			if (a.IsArrayType) {
				if (a.rankSpecifier.Length != b.rankSpecifier.Length) return false;
				for (int i = 0; i < a.rankSpecifier.Length; i++) {
					if (a.rankSpecifier[i] != b.rankSpecifier[i]) return false;
				}
			}
			if (a.genericTypes.Count != b.genericTypes.Count) return false;
			for (int i = 0; i < a.genericTypes.Count; i++) {
				if (!AreEqualReferences(a.genericTypes[i], b.genericTypes[i]))
					return false;
			}
			return true;
		}
コード例 #7
0
ファイル: TypeReference.cs プロジェクト: ThomasZitzler/ILSpy
		/// <summary>
		/// Removes the last identifier from the type.
		/// e.g. "System.String.Length" becomes "System.String" or
		/// "System.Collections.IEnumerable(of string).Current" becomes "System.Collections.IEnumerable(of string)"
		/// This is used for explicit interface implementation in VB.
		/// </summary>
		public static string StripLastIdentifierFromType(ref TypeReference tr)
		{
			if (tr is InnerClassTypeReference && ((InnerClassTypeReference)tr).Type.IndexOf('.') < 0) {
				string ident = ((InnerClassTypeReference)tr).Type;
				tr = ((InnerClassTypeReference)tr).BaseType;
				return ident;
			} else {
				int pos = tr.Type.LastIndexOf('.');
				if (pos < 0)
					return tr.Type;
				string ident = tr.Type.Substring(pos + 1);
				tr.Type = tr.Type.Substring(0, pos);
				return ident;
			}
		}
コード例 #8
0
ファイル: TypeReference.cs プロジェクト: ThomasZitzler/ILSpy
		public virtual TypeReference Clone()
		{
			TypeReference c = new TypeReference(type);
			CopyFields(this, c);
			return c;
		}
コード例 #9
0
ファイル: Parser.cs プロジェクト: ThomasZitzler/ILSpy
	void NonArrayTypeName(out TypeReference typeref, bool canBeUnbound) {
		string name;
		typeref = null;
		bool isGlobal = false;

		if (StartOf(12)) {
			if (la.kind == 130) {
				Get();
				Expect(26);
				isGlobal = true;
			}
			QualIdentAndTypeArguments(out typeref, canBeUnbound);
			typeref.IsGlobal = isGlobal;
			while (la.kind == 26) {
				Get();
				TypeReference nestedTypeRef;
				QualIdentAndTypeArguments(out nestedTypeRef, canBeUnbound);
				typeref = new InnerClassTypeReference(typeref, nestedTypeRef.Type, nestedTypeRef.GenericTypes);
			}
		} else if (la.kind == 168) {
			Get();
			typeref = new TypeReference("System.Object", true);
			if (la.kind == 33) {
				Get();
				List<TypeReference> typeArguments = new List<TypeReference>(1);
				  	if (typeref != null) typeArguments.Add(typeref);
					typeref = new TypeReference("System.Nullable", typeArguments) { IsKeyword = true };

			}
		} else if (StartOf(13)) {
			PrimitiveTypeName(out name);
			typeref = new TypeReference(name, true);
			if (la.kind == 33) {
				Get();
				List<TypeReference> typeArguments = new List<TypeReference>(1);
				  	if (typeref != null) typeArguments.Add(typeref);
					typeref = new TypeReference("System.Nullable", typeArguments) { IsKeyword = true };

			}
		} else SynErr(255);
	}
コード例 #10
0
ファイル: Parser.cs プロジェクト: ThomasZitzler/ILSpy
	void TypeParameterConstraint(out TypeReference constraint) {
		constraint = null; Location startLocation = la.Location;
		if (la.kind == 84) {
			Get();
			constraint = TypeReference.ClassConstraint;
		} else if (la.kind == 209) {
			Get();
			constraint = TypeReference.StructConstraint;
		} else if (la.kind == 162) {
			Get();
			constraint = TypeReference.NewConstraint;
		} else if (StartOf(9)) {
			TypeName(out constraint);
		} else SynErr(254);
	}
コード例 #11
0
ファイル: Generated.cs プロジェクト: ThomasZitzler/ILSpy
		public CollectionRangeVariable() {
			identifier = "";
			expression = Expression.Null;
			type = TypeReference.Null;
		}
コード例 #12
0
ファイル: Generated.cs プロジェクト: ThomasZitzler/ILSpy
		public CatchClause(Statement statementBlock) {
			StatementBlock = statementBlock;
			typeReference = TypeReference.Null;
			variableName = "";
			condition = Expression.Null;
		}
コード例 #13
0
ファイル: Generated.cs プロジェクト: ThomasZitzler/ILSpy
		public CatchClause(TypeReference typeReference, string variableName, Statement statementBlock, Expression condition) {
			TypeReference = typeReference;
			VariableName = variableName;
			StatementBlock = statementBlock;
			Condition = condition;
		}
コード例 #14
0
ファイル: Generated.cs プロジェクト: ThomasZitzler/ILSpy
		public CatchClause(TypeReference typeReference, string variableName, Statement statementBlock) {
			TypeReference = typeReference;
			VariableName = variableName;
			StatementBlock = statementBlock;
			condition = Expression.Null;
		}
コード例 #15
0
ファイル: Generated.cs プロジェクト: ThomasZitzler/ILSpy
		public CastExpression(TypeReference castTo, Expression expression, CastType castType) {
			CastTo = castTo;
			Expression = expression;
			CastType = castType;
		}
コード例 #16
0
ファイル: Parser.cs プロジェクト: ThomasZitzler/ILSpy
	void 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) {
			Expect(37);
			Expect(169);
			if (canBeUnbound && (la.kind == Tokens.CloseParenthesis || la.kind == Tokens.Comma)) {
				typeref.GenericTypes.Add(NullTypeReference.Instance);
				while (la.kind == 22) {
					Get();
					typeref.GenericTypes.Add(NullTypeReference.Instance);
				}
			} else if (StartOf(9)) {
				TypeArgumentList(typeref.GenericTypes);
			} else SynErr(300);
			Expect(38);
		}
	}
コード例 #17
0
ファイル: Parser.cs プロジェクト: ThomasZitzler/ILSpy
	void LoopControlVariable(out TypeReference type, out string name) {
		ArrayList arrayModifiers = null;
		type = null;

		Qualident(out name);
		if (IsDims()) {
			ArrayTypeModifiers(out arrayModifiers);
		}
		if (la.kind == 63) {
			Get();
			TypeName(out type);
			if (name.IndexOf('.') > 0) { Error("No type def for 'for each' member indexer allowed."); }
		}
		if (type != null) {
				if(type.RankSpecifier != null && arrayModifiers != null) {
					Error("array rank only allowed one time");
				} else if (arrayModifiers != null) {
					type.RankSpecifier = (int[])arrayModifiers.ToArray(typeof(int));
				}
			}

	}
コード例 #18
0
ファイル: Parser.cs プロジェクト: ThomasZitzler/ILSpy
	void StructureMemberDecl(ModifierList m, List<AttributeSection> attributes) {
		TypeReference type = null;
		List<ParameterDeclarationExpression> p = new List<ParameterDeclarationExpression>();
		Statement stmt = null;
		List<VariableDeclaration> variableDeclarators = new List<VariableDeclaration>();
		List<TemplateDefinition> templates = new List<TemplateDefinition>();

		switch (la.kind) {
		case 84: case 103: case 115: case 142: case 155: case 209: {
			NonModuleDeclaration(m, attributes);
			break;
		}
		case 210: {
			Get();
			Location startPos = t.Location;

			if (StartOf(5)) {
				string name = String.Empty;
					MethodDeclaration methodDeclaration; List<string> handlesClause = null;
					List<InterfaceImplementation> implementsClause = null;

				Identifier();
				name = t.val;
					m.Check(Modifiers.VBMethods);

				TypeParameterList(templates);
				if (la.kind == 37) {
					Get();
					if (StartOf(7)) {
						FormalParameterList(p);
					}
					Expect(38);
				}
				if (la.kind == 134 || la.kind == 136) {
					if (la.kind == 136) {
						ImplementsClause(out implementsClause);
					} else {
						HandlesClause(out handlesClause);
					}
				}
				Location endLocation = t.EndLocation;
				if (IsMustOverride(m)) {
					EndOfStmt();
					methodDeclaration = new MethodDeclaration {
							Name = name, Modifier = m.Modifier, Parameters = p, Attributes = attributes,
							StartLocation = m.GetDeclarationLocation(startPos), EndLocation = endLocation,
							TypeReference = new TypeReference("System.Void", true),
							Templates = templates,
							HandlesClause = handlesClause,
							InterfaceImplementations = implementsClause
						};
						AddChild(methodDeclaration);

				} else if (la.kind == 1) {
					Get();
					methodDeclaration = new MethodDeclaration {
							Name = name, Modifier = m.Modifier, Parameters = p, Attributes = attributes,
							StartLocation = m.GetDeclarationLocation(startPos), EndLocation = endLocation,
							TypeReference = new TypeReference("System.Void", true),
							Templates = templates,
							HandlesClause = handlesClause,
							InterfaceImplementations = implementsClause
						};
						AddChild(methodDeclaration);

					if (ParseMethodBodies) {
					Block(out stmt);
					Expect(113);
					Expect(210);
					} else {
						// don't parse method body
						lexer.SkipCurrentBlock(Tokens.Sub); stmt = new BlockStatement();
					   }

					methodDeclaration.Body  = (BlockStatement)stmt;
					methodDeclaration.Body.EndLocation = t.EndLocation;
					EndOfStmt();
				} else SynErr(257);
			} else if (la.kind == 162) {
				Get();
				if (la.kind == 37) {
					Get();
					if (StartOf(7)) {
						FormalParameterList(p);
					}
					Expect(38);
				}
				m.Check(Modifiers.Constructors);
				Location constructorEndLocation = t.EndLocation;
				Expect(1);
				if (ParseMethodBodies) {
				Block(out stmt);
				Expect(113);
				Expect(210);
				} else {
					// don't parse method body
					lexer.SkipCurrentBlock(Tokens.Sub); stmt = new BlockStatement();
				   }

				Location endLocation = t.EndLocation;
				EndOfStmt();
				ConstructorDeclaration cd = new ConstructorDeclaration("New", m.Modifier, p, attributes);
					cd.StartLocation = m.GetDeclarationLocation(startPos);
					cd.EndLocation   = constructorEndLocation;
					cd.Body = (BlockStatement)stmt;
					cd.Body.EndLocation   = endLocation;
					AddChild(cd);

			} else SynErr(258);
			break;
		}
		case 127: {
			Get();
			m.Check(Modifiers.VBMethods);
				string name = String.Empty;
				Location startPos = t.Location;
				MethodDeclaration methodDeclaration;List<string> handlesClause = null;
				List<InterfaceImplementation> implementsClause = null;
				AttributeSection returnTypeAttributeSection = null;

			Identifier();
			name = t.val;
			TypeParameterList(templates);
			if (la.kind == 37) {
				Get();
				if (StartOf(7)) {
					FormalParameterList(p);
				}
				Expect(38);
			}
			if (la.kind == 63) {
				Get();
				while (la.kind == 40) {
					AttributeSection(out returnTypeAttributeSection);
					if (returnTypeAttributeSection != null) {
							returnTypeAttributeSection.AttributeTarget = "return";
							attributes.Add(returnTypeAttributeSection);
						}

				}
				TypeName(out type);
			}
			if(type == null) {
					type = new TypeReference("System.Object", true);
				}

			if (la.kind == 134 || la.kind == 136) {
				if (la.kind == 136) {
					ImplementsClause(out implementsClause);
				} else {
					HandlesClause(out handlesClause);
				}
			}
			Location endLocation = t.EndLocation;
			if (IsMustOverride(m)) {
				EndOfStmt();
				methodDeclaration = new MethodDeclaration {
						Name = name, Modifier = m.Modifier, TypeReference = type,
						Parameters = p, Attributes = attributes,
						StartLocation = m.GetDeclarationLocation(startPos),
						EndLocation   = endLocation,
						HandlesClause = handlesClause,
						Templates     = templates,
						InterfaceImplementations = implementsClause
					};
					
					AddChild(methodDeclaration);

			} else if (la.kind == 1) {
				Get();
				methodDeclaration = new MethodDeclaration {
						Name = name, Modifier = m.Modifier, TypeReference = type,
						Parameters = p, Attributes = attributes,
						StartLocation = m.GetDeclarationLocation(startPos),
						EndLocation   = endLocation,
						Templates     = templates,
						HandlesClause = handlesClause,
						InterfaceImplementations = implementsClause
					};
					
					AddChild(methodDeclaration);

					if (ParseMethodBodies) {
				Block(out stmt);
				Expect(113);
				Expect(127);
				} else {
						// don't parse method body
						lexer.SkipCurrentBlock(Tokens.Function); stmt = new BlockStatement();
					}
					methodDeclaration.Body = (BlockStatement)stmt;
					methodDeclaration.Body.StartLocation = methodDeclaration.EndLocation;
					methodDeclaration.Body.EndLocation   = t.EndLocation;

				EndOfStmt();
			} else SynErr(259);
			break;
		}
		case 101: {
			Get();
			m.Check(Modifiers.VBExternalMethods);
				Location startPos = t.Location;
				CharsetModifier charsetModifer = CharsetModifier.None;
				string library = String.Empty;
				string alias = null;
				string name = String.Empty;

			if (StartOf(16)) {
				Charset(out charsetModifer);
			}
			if (la.kind == 210) {
				Get();
				Identifier();
				name = t.val;
				Expect(149);
				Expect(3);
				library = t.literalValue as string;
				if (la.kind == 59) {
					Get();
					Expect(3);
					alias = t.literalValue as string;
				}
				if (la.kind == 37) {
					Get();
					if (StartOf(7)) {
						FormalParameterList(p);
					}
					Expect(38);
				}
				EndOfStmt();
				DeclareDeclaration declareDeclaration = new DeclareDeclaration(name, m.Modifier, null, p, attributes, library, alias, charsetModifer);
					declareDeclaration.StartLocation = m.GetDeclarationLocation(startPos);
					declareDeclaration.EndLocation   = t.EndLocation;
					AddChild(declareDeclaration);

			} else if (la.kind == 127) {
				Get();
				Identifier();
				name = t.val;
				Expect(149);
				Expect(3);
				library = t.literalValue as string;
				if (la.kind == 59) {
					Get();
					Expect(3);
					alias = t.literalValue as string;
				}
				if (la.kind == 37) {
					Get();
					if (StartOf(7)) {
						FormalParameterList(p);
					}
					Expect(38);
				}
				if (la.kind == 63) {
					Get();
					TypeName(out type);
				}
				EndOfStmt();
				DeclareDeclaration declareDeclaration = new DeclareDeclaration(name, m.Modifier, type, p, attributes, library, alias, charsetModifer);
					declareDeclaration.StartLocation = m.GetDeclarationLocation(startPos);
					declareDeclaration.EndLocation   = t.EndLocation;
					AddChild(declareDeclaration);

			} else SynErr(260);
			break;
		}
		case 119: {
			Get();
			m.Check(Modifiers.VBEvents);
				Location startPos = t.Location;
				EventDeclaration eventDeclaration;
				string name = String.Empty;
				List<InterfaceImplementation> implementsClause = null;

			Identifier();
			name= t.val;
			if (la.kind == 63) {
				Get();
				TypeName(out type);
			} else if (StartOf(17)) {
				if (la.kind == 37) {
					Get();
					if (StartOf(7)) {
						FormalParameterList(p);
					}
					Expect(38);
				}
			} else SynErr(261);
			if (la.kind == 136) {
				ImplementsClause(out implementsClause);
			}
			eventDeclaration = new EventDeclaration {
					Name = name, TypeReference = type, Modifier = m.Modifier, 
					Parameters = p, Attributes = attributes, InterfaceImplementations = implementsClause,
					StartLocation = m.GetDeclarationLocation(startPos),
					EndLocation = t.EndLocation
				};
				AddChild(eventDeclaration);

			EndOfStmt();
			break;
		}
		case 2: case 58: case 62: case 64: case 65: case 66: case 67: case 70: case 87: case 104: case 107: case 116: case 121: case 126: case 133: case 139: case 143: case 146: case 147: case 170: case 176: case 178: case 184: case 203: case 212: case 213: case 223: case 224: case 230: {
			m.Check(Modifiers.Fields);
				FieldDeclaration fd = new FieldDeclaration(attributes, null, m.Modifier);

			IdentifierForFieldDeclaration();
			string name = t.val;
			fd.StartLocation = m.GetDeclarationLocation(t.Location);
			VariableDeclaratorPartAfterIdentifier(variableDeclarators, name);
			while (la.kind == 22) {
				Get();
				VariableDeclarator(variableDeclarators);
			}
			EndOfStmt();
			fd.EndLocation = t.EndLocation;
				fd.Fields = variableDeclarators;
				AddChild(fd);

			break;
		}
		case 88: {
			m.Check(Modifiers.Fields);
			Get();
			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);
			while (la.kind == 22) {
				Get();
				ConstantDeclarator(constantDeclarators);
			}
			fd.Fields = constantDeclarators;
				fd.EndLocation = t.Location;

			EndOfStmt();
			fd.EndLocation = t.EndLocation;
				AddChild(fd);

			break;
		}
		case 186: {
			Get();
			m.Check(Modifiers.VBProperties);
				Location startPos = t.Location;
				List<InterfaceImplementation> implementsClause = null;
				AttributeSection returnTypeAttributeSection = null;
				Expression initializer = null;

			Identifier();
			string propertyName = t.val;
			if (la.kind == 37) {
				Get();
				if (StartOf(7)) {
					FormalParameterList(p);
				}
				Expect(38);
			}
			if (la.kind == 63) {
				Get();
				while (la.kind == 40) {
					AttributeSection(out returnTypeAttributeSection);
					if (returnTypeAttributeSection != null) {
							returnTypeAttributeSection.AttributeTarget = "return";
							attributes.Add(returnTypeAttributeSection);
						}

				}
				if (IsNewExpression()) {
					ObjectCreateExpression(out initializer);
					if (initializer is ObjectCreateExpression) {
							type = ((ObjectCreateExpression)initializer).CreateType.Clone();
						} else {
							type = ((ArrayCreateExpression)initializer).CreateType.Clone();
						}

				} else if (StartOf(9)) {
					TypeName(out type);
				} else SynErr(262);
			}
			if (la.kind == 20) {
				Get();
				Expr(out initializer);
			}
			if (la.kind == 136) {
				ImplementsClause(out implementsClause);
			}
			EndOfStmt();
			if (IsMustOverride(m) || IsAutomaticProperty()) {
				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;
					if (initializer != null)
						pDecl.Initializer = initializer;
					AddChild(pDecl);

			} else if (StartOf(18)) {
				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);
				Expect(113);
				Expect(186);
				EndOfStmt();
				pDecl.GetRegion = getRegion;
					pDecl.SetRegion = setRegion;
					pDecl.BodyEnd = t.Location; // t = EndOfStmt; not "Property"
					AddChild(pDecl);

			} else SynErr(263);
			break;
		}
		case 98: {
			Get();
			Location startPos = t.Location;
			Expect(119);
			m.Check(Modifiers.VBCustomEvents);
				EventAddRemoveRegion eventAccessorDeclaration;
				EventAddRegion addHandlerAccessorDeclaration = null;
				EventRemoveRegion removeHandlerAccessorDeclaration = null;
				EventRaiseRegion raiseEventAccessorDeclaration = null;
				List<InterfaceImplementation> implementsClause = null;

			Identifier();
			string customEventName = t.val;
			Expect(63);
			TypeName(out type);
			if (la.kind == 136) {
				ImplementsClause(out implementsClause);
			}
			EndOfStmt();
			while (StartOf(19)) {
				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;
					}

			}
			Expect(113);
			Expect(119);
			EndOfStmt();
			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 {
					TypeReference = type, Name = customEventName, Modifier = m.Modifier,
					Attributes = attributes,
					StartLocation = m.GetDeclarationLocation(startPos),
					EndLocation = t.EndLocation,
					AddRegion = addHandlerAccessorDeclaration,
					RemoveRegion = removeHandlerAccessorDeclaration,
					RaiseRegion = raiseEventAccessorDeclaration
				};
				AddChild(decl);

			break;
		}
		case 161: case 172: case 232: {
			ConversionType opConversionType = ConversionType.None;
			if (la.kind == 161 || la.kind == 232) {
				if (la.kind == 232) {
					Get();
					opConversionType = ConversionType.Implicit;
				} else {
					Get();
					opConversionType = ConversionType.Explicit;
				}
			}
			Expect(172);
			m.Check(Modifiers.VBOperators);
				Location startPos = t.Location;
				TypeReference returnType = NullTypeReference.Instance;
				TypeReference operandType = NullTypeReference.Instance;
				OverloadableOperatorType operatorType;
				AttributeSection section;
				ParameterDeclarationExpression param;
				List<ParameterDeclarationExpression> parameters = new List<ParameterDeclarationExpression>();

			OverloadableOperator(out operatorType);
			Expect(37);
			FormalParameter(out param);
			if (param != null) parameters.Add(param);
			if (la.kind == 22) {
				Get();
				FormalParameter(out param);
				if (param != null) parameters.Add(param);
			}
			Expect(38);
			Location endPos = t.EndLocation;
			if (la.kind == 63) {
				Get();
				while (la.kind == 40) {
					AttributeSection(out section);
					if (section != null) {
						section.AttributeTarget = "return";
						attributes.Add(section);
					}
				}
				TypeName(out returnType);
				endPos = t.EndLocation;
			}
			Expect(1);
			Block(out stmt);
			Expect(113);
			Expect(172);
			EndOfStmt();
			OperatorDeclaration operatorDeclaration = new OperatorDeclaration {
					Modifier = m.Modifier,
					Attributes = attributes,
					Parameters = parameters,
					TypeReference = returnType,
					OverloadableOperator = operatorType,
					ConversionType = opConversionType,
					Body = (BlockStatement)stmt,
					StartLocation = m.GetDeclarationLocation(startPos),
					EndLocation = endPos
				};
				operatorDeclaration.Body.StartLocation = startPos;
				operatorDeclaration.Body.EndLocation = t.Location;
				AddChild(operatorDeclaration);

			break;
		}
		default: SynErr(264); break;
		}
	}
コード例 #19
0
ファイル: Parser.cs プロジェクト: ThomasZitzler/ILSpy
	void ClassBaseType(out TypeReference typeRef) {
		typeRef = null;

		Expect(140);
		TypeName(out typeRef);
		EndOfStmt();
	}
コード例 #20
0
ファイル: Parser.cs プロジェクト: ThomasZitzler/ILSpy
	void InterfaceMemberDecl() {
		TypeReference type =null;
		List<ParameterDeclarationExpression> p = new List<ParameterDeclarationExpression>();
		List<TemplateDefinition> templates = new List<TemplateDefinition>();
		AttributeSection section, returnTypeAttributeSection = null;
		ModifierList mod = new ModifierList();
		List<AttributeSection> attributes = new List<AttributeSection>();
		string name;

		if (StartOf(20)) {
			while (la.kind == 40) {
				AttributeSection(out section);
				attributes.Add(section);
			}
			while (StartOf(11)) {
				MemberModifier(mod);
			}
			if (la.kind == 119) {
				Get();
				mod.Check(Modifiers.VBInterfaceEvents);
					Location startLocation = t.Location;

				Identifier();
				name = t.val;
				if (la.kind == 37) {
					Get();
					if (StartOf(7)) {
						FormalParameterList(p);
					}
					Expect(38);
				}
				if (la.kind == 63) {
					Get();
					TypeName(out type);
				}
				EndOfStmt();
				EventDeclaration ed = new EventDeclaration {
						Name = name, TypeReference = type, Modifier = mod.Modifier,
						Parameters = p, Attributes = attributes,
						StartLocation = startLocation, EndLocation = t.EndLocation
					};
					AddChild(ed);

			} else if (la.kind == 210) {
				Get();
				Location startLocation =  t.Location;
					mod.Check(Modifiers.VBInterfaceMethods);

				Identifier();
				name = t.val;
				TypeParameterList(templates);
				if (la.kind == 37) {
					Get();
					if (StartOf(7)) {
						FormalParameterList(p);
					}
					Expect(38);
				}
				EndOfStmt();
				MethodDeclaration md = new MethodDeclaration {
						Name = name, 
						Modifier = mod.Modifier, 
						Parameters = p,
						Attributes = attributes,
						TypeReference = new TypeReference("System.Void", true),
						StartLocation = startLocation,
						EndLocation = t.EndLocation,
						Templates = templates
					};
					AddChild(md);

			} else if (la.kind == 127) {
				Get();
				mod.Check(Modifiers.VBInterfaceMethods);
					Location startLocation = t.Location;

				Identifier();
				name = t.val;
				TypeParameterList(templates);
				if (la.kind == 37) {
					Get();
					if (StartOf(7)) {
						FormalParameterList(p);
					}
					Expect(38);
				}
				if (la.kind == 63) {
					Get();
					while (la.kind == 40) {
						AttributeSection(out returnTypeAttributeSection);
					}
					TypeName(out type);
				}
				if(type == null) {
						type = new TypeReference("System.Object", true);
					}
					MethodDeclaration md = new MethodDeclaration {
						Name = name, Modifier = mod.Modifier, 
						TypeReference = type, Parameters = p, Attributes = attributes
					};
					if (returnTypeAttributeSection != null) {
						returnTypeAttributeSection.AttributeTarget = "return";
						md.Attributes.Add(returnTypeAttributeSection);
					}
					md.StartLocation = startLocation;
					md.EndLocation = t.EndLocation;
					md.Templates = templates;
					AddChild(md);

				EndOfStmt();
			} else if (la.kind == 186) {
				Get();
				Location startLocation = t.Location;
					mod.Check(Modifiers.VBInterfaceProperties);

				Identifier();
				name = t.val; 
				if (la.kind == 37) {
					Get();
					if (StartOf(7)) {
						FormalParameterList(p);
					}
					Expect(38);
				}
				if (la.kind == 63) {
					Get();
					TypeName(out type);
				}
				if(type == null) {
						type = new TypeReference("System.Object", true);
					}

				EndOfStmt();
				PropertyDeclaration pd = new PropertyDeclaration(name, type, mod.Modifier, attributes);
					pd.Parameters = p;
					pd.EndLocation = t.EndLocation;
					pd.StartLocation = startLocation;
					AddChild(pd);

			} else SynErr(265);
		} else if (StartOf(21)) {
			NonModuleDeclaration(mod, attributes);
		} else SynErr(266);
	}
コード例 #21
0
		public virtual object VisitTypeReference(TypeReference typeReference, object data) {
			Debug.Assert((typeReference != null));
			Debug.Assert((typeReference.GenericTypes != null));
			for (int i = 0; i < typeReference.GenericTypes.Count; i++) {
				TypeReference o = typeReference.GenericTypes[i];
				Debug.Assert(o != null);
				nodeStack.Push(o);
				o.AcceptVisitor(this, data);
				o = (TypeReference)nodeStack.Pop();
				if (o == null)
					typeReference.GenericTypes.RemoveAt(i--);
				else
					typeReference.GenericTypes[i] = o;
			}
			return null;
		}
コード例 #22
0
ファイル: Parser.cs プロジェクト: ThomasZitzler/ILSpy
	void VariableDeclaratorPartAfterIdentifier(List<VariableDeclaration> fieldDeclaration, string name) {
		Expression expr = null;
		TypeReference type = null;
		ArrayList rank = null;
		List<Expression> dimension = null;
		Location startLocation = t.Location;

		if (IsSize() && !IsDims()) {
			ArrayInitializationModifier(out dimension);
		}
		if (IsDims()) {
			ArrayNameModifier(out rank);
		}
		if (IsObjectCreation()) {
			Expect(63);
			ObjectCreateExpression(out expr);
			if (expr is ObjectCreateExpression) {
					type = ((ObjectCreateExpression)expr).CreateType.Clone();
				} else {
					type = ((ArrayCreateExpression)expr).CreateType.Clone();
				}

		} else if (StartOf(23)) {
			if (la.kind == 63) {
				Get();
				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)) {
					type = new TypeReference("");
				}
				if (dimension != null) {
					if(type.RankSpecifier != null) {
						Error("array rank only allowed one time");
					} else {
						if (rank == null) {
							type.RankSpecifier = new int[] { dimension.Count - 1 };
						} else {
							rank.Insert(0, dimension.Count - 1);
							type.RankSpecifier = (int[])rank.ToArray(typeof(int));
						}
						expr = new ArrayCreateExpression(type.Clone(), dimension);
					}
				} else if (rank != null) {
					if(type.RankSpecifier != null) {
						Error("array rank only allowed one time");
					} else {
						type.RankSpecifier = (int[])rank.ToArray(typeof(int));
					}
				}

			if (la.kind == 20) {
				Get();
				Expr(out expr);
			}
		} else SynErr(271);
		VariableDeclaration varDecl = new VariableDeclaration(name, expr, type);
			varDecl.StartLocation = startLocation;
			varDecl.EndLocation = t.Location;
			fieldDeclaration.Add(varDecl);

	}
コード例 #23
0
ファイル: TypeReference.cs プロジェクト: ThomasZitzler/ILSpy
		/// <summary>
		/// Copies the pointerNestingLevel, RankSpecifier, GenericTypes and IsGlobal flag
		/// from <paramref name="from"/> to <paramref name="to"/>.
		/// </summary>
		/// <remarks>
		/// If <paramref name="to"/> already contains generics, the new generics are appended to the list.
		/// </remarks>
		protected static void CopyFields(TypeReference from, TypeReference to)
		{
			to.pointerNestingLevel = from.pointerNestingLevel;
			if (from.rankSpecifier != null) {
				to.rankSpecifier = (int[])from.rankSpecifier.Clone();
			}
			foreach (TypeReference r in from.genericTypes) {
				to.genericTypes.Add(r.Clone());
			}
			to.IsGlobal = from.IsGlobal;
			to.IsKeyword = from.IsKeyword;
		}
コード例 #24
0
ファイル: Parser.cs プロジェクト: ThomasZitzler/ILSpy
	void SimpleNonInvocationExpression(out Expression pexpr) {
		Expression expr;
		CollectionInitializerExpression cie;
		TypeReference type = null;
		string name = String.Empty;
		Location startLocation = la.Location;
		pexpr = null;

		if (StartOf(34)) {
			switch (la.kind) {
			case 3: {
				Get();
				pexpr = new PrimitiveExpression(t.literalValue, t.val) { LiteralFormat = t.literalFormat }; 
				break;
			}
			case 4: {
				Get();
				pexpr = new PrimitiveExpression(t.literalValue, t.val) { LiteralFormat = t.literalFormat }; 
				break;
			}
			case 7: {
				Get();
				pexpr = new PrimitiveExpression(t.literalValue, t.val) { LiteralFormat = t.literalFormat }; 
				break;
			}
			case 6: {
				Get();
				pexpr = new PrimitiveExpression(t.literalValue, t.val) { LiteralFormat = t.literalFormat }; 
				break;
			}
			case 5: {
				Get();
				pexpr = new PrimitiveExpression(t.literalValue, t.val) { LiteralFormat = t.literalFormat }; 
				break;
			}
			case 9: {
				Get();
				pexpr = new PrimitiveExpression(t.literalValue, t.val) { LiteralFormat = t.literalFormat }; 
				break;
			}
			case 8: {
				Get();
				pexpr = new PrimitiveExpression(t.literalValue, t.val) { LiteralFormat = t.literalFormat }; 
				break;
			}
			case 217: {
				Get();
				pexpr = new PrimitiveExpression(true, "true"); 
				break;
			}
			case 122: {
				Get();
				pexpr = new PrimitiveExpression(false, "false");
				break;
			}
			case 165: {
				Get();
				pexpr = new PrimitiveExpression(null, "null"); 
				break;
			}
			case 37: {
				Get();
				Expr(out expr);
				Expect(38);
				pexpr = new ParenthesizedExpression(expr);
				break;
			}
			case 2: case 58: case 62: case 64: case 65: case 66: case 67: case 70: case 87: case 98: case 104: case 107: case 116: case 121: case 126: case 133: case 139: case 143: case 146: case 147: case 170: case 176: case 178: case 184: case 203: case 212: case 213: case 223: case 224: case 230: {
				Identifier();
				pexpr = new IdentifierExpression(t.val);
					pexpr.StartLocation = t.Location; pexpr.EndLocation = t.EndLocation;

				if (la.kind == Tokens.OpenParenthesis && Peek(1).kind == Tokens.Of) {
					Expect(37);
					Expect(169);
					TypeArgumentList(((IdentifierExpression)pexpr).TypeArguments);
					Expect(38);
				}
				break;
			}
			case 68: case 71: case 82: case 99: case 100: case 109: case 141: case 151: case 168: case 196: case 201: case 202: case 208: case 221: case 222: case 225: {
				string val = String.Empty;
				if (StartOf(13)) {
					PrimitiveTypeName(out val);
				} else {
					Get();
					val = "System.Object";
				}
				pexpr = new TypeReferenceExpression(new TypeReference(val, true));
				break;
			}
			case 153: {
				Get();
				pexpr = new ThisReferenceExpression();
				break;
			}
			case 158: case 159: {
				Expression retExpr = null;
				if (la.kind == 158) {
					Get();
					retExpr = new BaseReferenceExpression() { StartLocation = t.Location, EndLocation = t.EndLocation };
				} else {
					Get();
					retExpr = new ClassReferenceExpression() { StartLocation = t.Location, EndLocation = t.EndLocation };
				}
				Expect(26);
				IdentifierOrKeyword(out name);
				pexpr = new MemberReferenceExpression(retExpr, name) { StartLocation = startLocation, EndLocation = t.EndLocation };
				break;
			}
			case 130: {
				Get();
				Expect(26);
				Identifier();
				type = new TypeReference(t.val ?? "");
				type.IsGlobal = true;
				pexpr = new TypeReferenceExpression(type);
				break;
			}
			case 162: {
				ObjectCreateExpression(out expr);
				pexpr = expr;
				break;
			}
			case 35: {
				CollectionInitializer(out cie);
				pexpr = cie;
				break;
			}
			case 94: case 106: case 219: {
				CastType castType = CastType.Cast;
				if (la.kind == 106) {
					Get();
				} else if (la.kind == 94) {
					Get();
					castType = CastType.Conversion;
				} else {
					Get();
					castType = CastType.TryCast;
				}
				Expect(37);
				Expr(out expr);
				Expect(22);
				TypeName(out type);
				Expect(38);
				pexpr = new CastExpression(type, expr, castType);
				break;
			}
			case 76: case 77: case 78: case 79: case 80: case 81: case 83: case 85: case 86: case 90: case 91: case 92: case 93: case 95: case 96: case 97: {
				CastTarget(out type);
				Expect(37);
				Expr(out expr);
				Expect(38);
				pexpr = new CastExpression(type, expr, CastType.PrimitiveConversion);
				break;
			}
			case 57: {
				Get();
				SimpleExpr(out expr);
				pexpr = new AddressOfExpression(expr);
				break;
			}
			case 129: {
				Get();
				Expect(37);
				GetTypeTypeName(out type);
				Expect(38);
				pexpr = new TypeOfExpression(type);
				break;
			}
			case 220: {
				Get();
				SimpleExpr(out expr);
				Expect(144);
				TypeName(out type);
				pexpr = new TypeOfIsExpression(expr, type);
				break;
			}
			case 135: {
				ConditionalExpression(out pexpr);
				break;
			}
			case 10: case 16: case 17: case 18: case 19: {
				XmlLiteralExpression(out pexpr);
				break;
			}
			}
		} else if (StartOf(35)) {
			if (la.kind == 26) {
				Get();
				if (la.kind == 10) {
					Get();
					IdentifierOrKeyword(out name);
					Expect(11);
					pexpr = new XmlMemberAccessExpression(null, XmlAxisType.Element, name, true) { StartLocation = startLocation, EndLocation = t.EndLocation };
				} else if (StartOf(33)) {
					IdentifierOrKeyword(out name);
					pexpr = new MemberReferenceExpression(null, name) { StartLocation = startLocation, EndLocation = t.EndLocation };
				} else SynErr(281);
			} else if (la.kind == 29) {
				Get();
				IdentifierOrKeyword(out name);
				pexpr = new BinaryOperatorExpression(null, BinaryOperatorType.DictionaryAccess, new PrimitiveExpression(name, name) { StartLocation = t.Location, EndLocation = t.EndLocation });
			} else {
				XmlAxisType axisType = XmlAxisType.Element; bool isXmlIdentifier = false;
				if (la.kind == 27) {
					Get();
					axisType = XmlAxisType.Descendents;
				} else {
					Get();
					axisType = XmlAxisType.Attribute;
				}
				if (la.kind == 10) {
					Get();
					isXmlIdentifier = true;
				}
				IdentifierOrKeyword(out name);
				if (la.kind == 11) {
					Get();
				}
				pexpr = new XmlMemberAccessExpression(null, axisType, name, isXmlIdentifier);
			}
		} else SynErr(282);
		if (pexpr != null) {
				pexpr.StartLocation = startLocation;
				pexpr.EndLocation = t.EndLocation;
			}

	}
コード例 #25
0
ファイル: TypeReference.cs プロジェクト: ThomasZitzler/ILSpy
		public static TypeReference CheckNull(TypeReference typeReference)
		{
			return typeReference ?? NullTypeReference.Instance;
		}
コード例 #26
0
ファイル: Parser.cs プロジェクト: ThomasZitzler/ILSpy
	void CastTarget(out TypeReference type) {
		type = null;

		switch (la.kind) {
		case 76: {
			Get();
			type = new TypeReference("System.Boolean", true);
			break;
		}
		case 77: {
			Get();
			type = new TypeReference("System.Byte", true);
			break;
		}
		case 90: {
			Get();
			type = new TypeReference("System.SByte", true);
			break;
		}
		case 78: {
			Get();
			type = new TypeReference("System.Char", true);
			break;
		}
		case 79: {
			Get();
			type = new TypeReference("System.DateTime", true);
			break;
		}
		case 81: {
			Get();
			type = new TypeReference("System.Decimal", true);
			break;
		}
		case 80: {
			Get();
			type = new TypeReference("System.Double", true);
			break;
		}
		case 91: {
			Get();
			type = new TypeReference("System.Int16", true);
			break;
		}
		case 83: {
			Get();
			type = new TypeReference("System.Int32", true);
			break;
		}
		case 85: {
			Get();
			type = new TypeReference("System.Int64", true);
			break;
		}
		case 97: {
			Get();
			type = new TypeReference("System.UInt16", true);
			break;
		}
		case 95: {
			Get();
			type = new TypeReference("System.UInt32", true);
			break;
		}
		case 96: {
			Get();
			type = new TypeReference("System.UInt64", true);
			break;
		}
		case 86: {
			Get();
			type = new TypeReference("System.Object", true);
			break;
		}
		case 92: {
			Get();
			type = new TypeReference("System.Single", true);
			break;
		}
		case 93: {
			Get();
			type = new TypeReference("System.String", true);
			break;
		}
		default: SynErr(284); break;
		}
	}
コード例 #27
0
ファイル: TypeReference.cs プロジェクト: ThomasZitzler/ILSpy
		public InnerClassTypeReference(TypeReference outerClass, string innerType, List<TypeReference> innerGenericTypes)
			: base(innerType, innerGenericTypes)
		{
			this.baseType = outerClass;
		}
コード例 #28
0
ファイル: Parser.cs プロジェクト: ThomasZitzler/ILSpy
	void 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));
			}

	}
コード例 #29
0
		public virtual object VisitTypeReference(TypeReference typeReference, object data) {
			Debug.Assert((typeReference != null));
			Debug.Assert((typeReference.GenericTypes != null));
			foreach (TypeReference o in typeReference.GenericTypes) {
				Debug.Assert(o != null);
				o.AcceptVisitor(this, data);
			}
			return null;
		}
コード例 #30
0
ファイル: Parser.cs プロジェクト: ThomasZitzler/ILSpy
	void TypeName(out TypeReference typeref) {
		ArrayList rank = null; Location startLocation = la.Location;
		NonArrayTypeName(out typeref, false);
		ArrayTypeModifiers(out rank);
		if (typeref != null) {
				if (rank != null) {
					typeref.RankSpecifier = (int[])rank.ToArray(typeof(int));
				}
				typeref.StartLocation = startLocation;
				typeref.EndLocation = t.EndLocation;
			}

	}