From d900a171fa7c8ef1185f15cf0a7eed0aa9de945b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Artur=20Zgodzi=C5=84ski?= Date: Mon, 2 May 2011 13:24:19 +0200 Subject: [PATCH 1/5] Improved decompilation of new modifier. --- ICSharpCode.Decompiler/Ast/AstBuilder.cs | 117 ++++- .../Ast/TypesHierarchyHelpers.cs | 228 +++++++-- .../Tests/ICSharpCode.Decompiler.Tests.csproj | 4 +- .../Tests/Types/S_TypeMemberDeclarations.cs | 460 +++++++++++++++++- 4 files changed, 730 insertions(+), 79 deletions(-) diff --git a/ICSharpCode.Decompiler/Ast/AstBuilder.cs b/ICSharpCode.Decompiler/Ast/AstBuilder.cs index daab20f0f..7d5d047cd 100644 --- a/ICSharpCode.Decompiler/Ast/AstBuilder.cs +++ b/ICSharpCode.Decompiler/Ast/AstBuilder.cs @@ -232,7 +232,9 @@ namespace ICSharpCode.Decompiler.Ast foreach (TypeDefinition nestedTypeDef in typeDef.NestedTypes) { if (MemberIsHidden(nestedTypeDef, context.Settings)) continue; - astType.AddChild(CreateType(nestedTypeDef), TypeDeclaration.MemberRole); + var nestedType = CreateType(nestedTypeDef); + SetNewModifier(nestedType); + astType.AddChild(nestedType, TypeDeclaration.MemberRole); } AttributedNode result = astType; @@ -627,7 +629,7 @@ namespace ICSharpCode.Decompiler.Ast // Create mapping - used in debugger MemberMapping methodMapping = methodDef.CreateCodeMapping(this.CodeMappings); - MethodDeclaration astMethod = new MethodDeclaration(); + MethodDeclaration astMethod = new MethodDeclaration().WithAnnotation(methodMapping); astMethod.AddAnnotation(methodDef); astMethod.ReturnType = ConvertType(methodDef.ReturnType, methodDef.MethodReturnType); astMethod.Name = CleanName(methodDef.Name); @@ -638,14 +640,8 @@ namespace ICSharpCode.Decompiler.Ast if (!methodDef.DeclaringType.IsInterface) { if (!methodDef.HasOverrides) { astMethod.Modifiers = ConvertModifiers(methodDef); - if (methodDef.IsVirtual ^ !methodDef.IsNewSlot) { - try { - if (TypesHierarchyHelpers.FindBaseMethods(methodDef).Any()) - astMethod.Modifiers |= Modifiers.New; - } catch (ReferenceResolvingException) { - // TODO: add some kind of notification (a comment?) about possible problems with decompiled code due to unresolved references. - } - } + if (methodDef.IsVirtual == methodDef.IsNewSlot) + SetNewModifier(astMethod); } else { astMethod.PrivateImplementationType = ConvertType(methodDef.Overrides.First().DeclaringType); } @@ -675,7 +671,6 @@ namespace ICSharpCode.Decompiler.Ast return op; } } - astMethod.WithAnnotation(methodMapping); return astMethod; } @@ -775,10 +770,6 @@ namespace ICSharpCode.Decompiler.Ast } } } - if (accessor.IsVirtual ^ !accessor.IsNewSlot) { - if (TypesHierarchyHelpers.FindBaseProperties(propDef).Any()) - astProp.Modifiers |= Modifiers.New; - } } catch (ReferenceResolvingException) { // TODO: add some kind of notification (a comment?) about possible problems with decompiled code due to unresolved references. } @@ -791,7 +782,7 @@ namespace ICSharpCode.Decompiler.Ast astProp.Getter = new Accessor(); astProp.Getter.Body = CreateMethodBody(propDef.GetMethod); - astProp.AddAnnotation(propDef.GetMethod); + astProp.Getter.AddAnnotation(propDef.GetMethod); ConvertAttributes(astProp.Getter, propDef.GetMethod); if ((getterModifiers & Modifiers.VisibilityMask) != (astProp.Modifiers & Modifiers.VisibilityMask)) @@ -815,11 +806,14 @@ namespace ICSharpCode.Decompiler.Ast astProp.Setter.WithAnnotation(methodMapping); } ConvertCustomAttributes(astProp, propDef); - + + MemberDeclaration member = astProp; if(propDef.IsIndexer()) - return ConvertPropertyToIndexer(astProp, propDef); - else - return astProp; + member = ConvertPropertyToIndexer(astProp, propDef); + if(!accessor.HasOverrides && !accessor.DeclaringType.IsInterface) + if (accessor.IsVirtual == accessor.IsNewSlot) + SetNewModifier(member); + return member; } IndexerDeclaration ConvertPropertyToIndexer(PropertyDeclaration astProp, PropertyDefinition propDef) @@ -882,9 +876,8 @@ namespace ICSharpCode.Decompiler.Ast astEvent.RemoveAccessor.WithAnnotation(methodMapping); } MethodDefinition accessor = eventDef.AddMethod ?? eventDef.RemoveMethod; - if (accessor.IsVirtual ^ !accessor.IsNewSlot) { - if (TypesHierarchyHelpers.FindBaseMethods(accessor).Any()) - astEvent.Modifiers |= Modifiers.New; + if (accessor.IsVirtual == accessor.IsNewSlot) { + SetNewModifier(astEvent); } return astEvent; } @@ -921,6 +914,7 @@ namespace ICSharpCode.Decompiler.Ast } } ConvertAttributes(astField, fieldDef); + SetNewModifier(astField); return astField; } @@ -1367,6 +1361,83 @@ namespace ICSharpCode.Decompiler.Ast return type.CustomAttributes.Any(attr => attr.AttributeType.FullName == "System.FlagsAttribute"); } + + /// + /// Sets new modifier if the member hides some other member from a base type. + /// + /// The node of the member which new modifier state should be determined. + static void SetNewModifier(AttributedNode member) + { + try { + bool addNewModifier = false; + if (member is IndexerDeclaration) { + var propertyDef = member.Annotation(); + var baseProperties = + TypesHierarchyHelpers.FindBaseProperties(propertyDef); + addNewModifier = baseProperties.Any(); + } else + addNewModifier = HidesBaseMember(member); + + if (addNewModifier) + member.Modifiers |= Modifiers.New; + } + catch (ReferenceResolvingException) { + // TODO: add some kind of notification (a comment?) about possible problems with decompiled code due to unresolved references. + } + } + + private static bool HidesBaseMember(AttributedNode member) + { + var memberDefinition = member.Annotation(); + bool addNewModifier = false; + var methodDefinition = memberDefinition as MethodDefinition; + if (methodDefinition != null) { + addNewModifier = HidesByName(memberDefinition, includeBaseMethods: false); + if (!addNewModifier) + addNewModifier = TypesHierarchyHelpers.FindBaseMethods(methodDefinition).Any(); + } else + addNewModifier = HidesByName(memberDefinition, includeBaseMethods: true); + return addNewModifier; + } + + /// + /// Determines whether any base class member has the same name as the given member. + /// + /// The derived type's member. + /// true if names of methods declared in base types should also be checked. + /// true if any base member has the same name as given member, otherwise false. + static bool HidesByName(IMemberDefinition member, bool includeBaseMethods) + { + Debug.Assert(!(member is PropertyDefinition) || !((PropertyDefinition)member).IsIndexer()); + + if (member.DeclaringType.BaseType != null) { + var baseTypeRef = member.DeclaringType.BaseType; + while (baseTypeRef != null) { + var baseType = baseTypeRef.ResolveOrThrow(); + if (baseType.HasProperties && AnyIsHiddenBy(baseType.Properties, member, m => !m.IsIndexer())) + return true; + if (baseType.HasEvents && AnyIsHiddenBy(baseType.Events, member)) + return true; + if (baseType.HasFields && AnyIsHiddenBy(baseType.Fields, member)) + return true; + if (includeBaseMethods && baseType.HasMethods + && AnyIsHiddenBy(baseType.Methods, member, m => !m.IsSpecialName)) + return true; + if (baseType.HasNestedTypes && AnyIsHiddenBy(baseType.NestedTypes, member)) + return true; + baseTypeRef = baseType.BaseType; + } + } + return false; + } + + static bool AnyIsHiddenBy(IEnumerable members, IMemberDefinition derived, Predicate condition = null) + where T : IMemberDefinition + { + return members.Any(m => m.Name == derived.Name + && (condition == null || condition(m)) + && TypesHierarchyHelpers.IsVisibleFromDerived(m, derived.DeclaringType)); + } /// /// diff --git a/ICSharpCode.Decompiler/Ast/TypesHierarchyHelpers.cs b/ICSharpCode.Decompiler/Ast/TypesHierarchyHelpers.cs index 5104ea7ba..3679229ec 100644 --- a/ICSharpCode.Decompiler/Ast/TypesHierarchyHelpers.cs +++ b/ICSharpCode.Decompiler/Ast/TypesHierarchyHelpers.cs @@ -27,6 +27,13 @@ namespace ICSharpCode.Decompiler.Ast } } + /// + /// Determines whether one method overrides or hides another method. + /// + /// The method declared in a base type. + /// The method declared in a derived type. + /// true if hides or overrides , + /// otherwise false. public static bool IsBaseMethod(MethodDefinition parentMethod, MethodDefinition childMethod) { if (parentMethod == null) @@ -44,6 +51,13 @@ namespace ICSharpCode.Decompiler.Ast return FindBaseMethods(childMethod).Any(m => m == parentMethod);// || (parentMethod.HasGenericParameters && m.); } + /// + /// Determines whether a property overrides or hides another property. + /// + /// The property declared in a base type. + /// The property declared in a derived type. + /// true if the hides or overrides , + /// otherwise false. public static bool IsBaseProperty(PropertyDefinition parentProperty, PropertyDefinition childProperty) { if (parentProperty == null) @@ -69,6 +83,11 @@ namespace ICSharpCode.Decompiler.Ast return FindBaseEvents(childEvent).Any(m => m == parentEvent); } + /// + /// Finds all methods from base types overridden or hidden by the specified method. + /// + /// The method which overrides or hides methods from base types. + /// Methods overriden or hidden by the specified method. public static IEnumerable FindBaseMethods(MethodDefinition method) { if (method == null) @@ -79,30 +98,41 @@ namespace ICSharpCode.Decompiler.Ast foreach (var baseType in BaseTypes(method.DeclaringType)) foreach (var baseMethod in baseType.Item.Methods) - if (MatchMethod(baseType.ApplyTo(baseMethod), gMethod) && IsVisbleFrom(baseMethod, method)) { + if (MatchMethod(baseType.ApplyTo(baseMethod), gMethod) && IsVisibleFromDerived(baseMethod, method.DeclaringType)) { yield return baseMethod; - if (!(baseMethod.IsNewSlot ^ baseMethod.IsVirtual)) + if (baseMethod.IsNewSlot == baseMethod.IsVirtual) yield break; } } - public static IEnumerable FindBaseProperties(PropertyDefinition property, bool ignoreResolveExceptions = false) + /// + /// Finds all properties from base types overridden or hidden by the specified property. + /// + /// The property which overrides or hides properties from base types. + /// Properties overriden or hidden by the specified property. + public static IEnumerable FindBaseProperties(PropertyDefinition property) { if (property == null) throw new ArgumentNullException("property"); + if ((property.GetMethod ?? property.SetMethod).HasOverrides) + yield break; + var typeContext = CreateGenericContext(property.DeclaringType); var gProperty = typeContext.ApplyTo(property); + bool isIndexer = property.IsIndexer(); foreach (var baseType in BaseTypes(property.DeclaringType)) foreach (var baseProperty in baseType.Item.Properties) - if (MatchProperty(baseType.ApplyTo(baseProperty), gProperty) && IsVisbleFrom(baseProperty, property)) { + if (MatchProperty(baseType.ApplyTo(baseProperty), gProperty) + && IsVisibleFromDerived(baseProperty, property.DeclaringType)) { + if (isIndexer != baseProperty.IsIndexer()) + continue; yield return baseProperty; var anyPropertyAccessor = baseProperty.GetMethod ?? baseProperty.SetMethod; - if (!(anyPropertyAccessor.IsNewSlot ^ anyPropertyAccessor.IsVirtual)) + if (anyPropertyAccessor.IsNewSlot == anyPropertyAccessor.IsVirtual) yield break; } - } public static IEnumerable FindBaseEvents(EventDefinition eventDef) @@ -115,40 +145,78 @@ namespace ICSharpCode.Decompiler.Ast foreach (var baseType in BaseTypes(eventDef.DeclaringType)) foreach (var baseEvent in baseType.Item.Events) - if (MatchEvent(baseType.ApplyTo(baseEvent), gEvent) && IsVisbleFrom(baseEvent, eventDef)) { + if (MatchEvent(baseType.ApplyTo(baseEvent), gEvent) && IsVisibleFromDerived(baseEvent, eventDef.DeclaringType)) { yield return baseEvent; var anyEventAccessor = baseEvent.AddMethod ?? baseEvent.RemoveMethod; - if (!(anyEventAccessor.IsNewSlot ^ anyEventAccessor.IsVirtual)) + if (anyEventAccessor.IsNewSlot == anyEventAccessor.IsVirtual) yield break; } } - private static bool IsVisbleFrom(MethodDefinition baseCandidate, MethodDefinition method) + /// + /// Determinates whether member of the base type is visible from a derived type. + /// + /// The member which visibility is checked. + /// The derived type. + /// true if the member is visible from derived type, othewise false. + public static bool IsVisibleFromDerived(IMemberDefinition baseMember, TypeDefinition derivedType) { - if (baseCandidate.IsPrivate) - return false; - if ((baseCandidate.IsAssembly || baseCandidate.IsFamilyAndAssembly) && baseCandidate.Module != method.Module) - return false; - return true; - } + if (baseMember == null) + throw new ArgumentNullException("baseMember"); + if (derivedType == null) + throw new ArgumentNullException("derivedType"); - private static bool IsVisbleFrom(PropertyDefinition baseCandidate, PropertyDefinition property) - { - if (baseCandidate.GetMethod != null && property.GetMethod != null && IsVisbleFrom(baseCandidate.GetMethod, property.GetMethod)) - return true; - if (baseCandidate.SetMethod != null && property.SetMethod != null && IsVisbleFrom(baseCandidate.SetMethod, property.SetMethod)) + var visibility = IsVisibleFromDerived(baseMember); + if (visibility.HasValue) + return visibility.Value; + + if (baseMember.DeclaringType.Module == derivedType.Module) return true; + // TODO: Check also InternalsVisibleToAttribute. return false; } - private static bool IsVisbleFrom(EventDefinition baseCandidate, EventDefinition eventDef) + private static bool? IsVisibleFromDerived(IMemberDefinition member) { - if (baseCandidate.AddMethod != null && eventDef.AddMethod != null && IsVisbleFrom(baseCandidate.AddMethod, eventDef.AddMethod)) - return true; - if (baseCandidate.RemoveMethod != null && eventDef.RemoveMethod != null && IsVisbleFrom(baseCandidate.RemoveMethod, eventDef.RemoveMethod)) - return true; - return false; + MethodAttributes attrs = GetAccessAttributes(member) & MethodAttributes.MemberAccessMask; + if (attrs == MethodAttributes.Private) + return false; + if (attrs == MethodAttributes.Assembly || attrs == MethodAttributes.FamANDAssem) + return null; + return true; + } + + private static MethodAttributes GetAccessAttributes(IMemberDefinition member) + { + var fld = member as FieldDefinition; + if (fld != null) + return (MethodAttributes)fld.Attributes; + + var method = member as MethodDefinition; + if (method != null) + return method.Attributes; + + var prop = member as PropertyDefinition; + if (prop != null) { + return (prop.GetMethod ?? prop.SetMethod).Attributes; + } + + var evnt = member as EventDefinition; + if (evnt != null) { + return (evnt.AddMethod ?? evnt.RemoveMethod).Attributes; + } + + var nestedType = member as TypeDefinition; + if (nestedType != null) { + if (nestedType.IsNestedPrivate) + return MethodAttributes.Private; + if (nestedType.IsNestedAssembly || nestedType.IsNestedFamilyAndAssembly) + return MethodAttributes.Assembly; + return MethodAttributes.Public; + } + + throw new NotSupportedException(); } private static bool MatchMethod(GenericContext candidate, GenericContext method) @@ -161,7 +229,7 @@ namespace ICSharpCode.Decompiler.Ast if (mCandidate.HasOverrides) return false; - if (!IsSameType(candidate.ResolveWithContext(mCandidate.ReturnType), method.ResolveWithContext(mMethod.ReturnType))) + if (mCandidate.IsSpecialName != method.Item.IsSpecialName) return false; if (mCandidate.HasGenericParameters || mMethod.HasGenericParameters) { @@ -182,7 +250,8 @@ namespace ICSharpCode.Decompiler.Ast return true; } - private static bool MatchProperty(GenericContext candidate, GenericContext property) + private static bool MatchProperty(GenericContext candidate, + GenericContext property) { var mCandidate = candidate.Item; var mProperty = property.Item; @@ -192,9 +261,6 @@ namespace ICSharpCode.Decompiler.Ast if ((mCandidate.GetMethod ?? mCandidate.SetMethod).HasOverrides) return false; - if (!IsSameType(candidate.ResolveWithContext(mCandidate.PropertyType), property.ResolveWithContext(mProperty.PropertyType))) - return false; - if (mCandidate.HasParameters || mProperty.HasParameters) { if (!mCandidate.HasParameters || !mProperty.HasParameters || mCandidate.Parameters.Count != mProperty.Parameters.Count) return false; @@ -226,6 +292,9 @@ namespace ICSharpCode.Decompiler.Ast private static bool MatchParameters(GenericContext baseParameterType, GenericContext parameterType) { + if (baseParameterType.Item.IsIn != parameterType.Item.IsIn || + baseParameterType.Item.IsOut != parameterType.Item.IsOut) + return false; var baseParam = baseParameterType.ResolveWithContext(baseParameterType.Item.ParameterType); var param = parameterType.ResolveWithContext(parameterType.Item.ParameterType); return IsSameType(baseParam, param); @@ -238,8 +307,12 @@ namespace ICSharpCode.Decompiler.Ast if (tr1 == null || tr2 == null) return false; + if (tr1.GetType() != tr2.GetType()) + return false; + if (tr1.Name == tr2.Name && tr1.FullName == tr2.FullName) return true; + return false; } @@ -272,6 +345,10 @@ namespace ICSharpCode.Decompiler.Ast struct GenericContext where T : class { private static readonly ReadOnlyCollection Empty = new ReadOnlyCollection(new List()); + private static readonly GenericParameter UnresolvedGenericTypeParameter = + new DummyGenericParameterProvider(false).DummyParameter; + private static readonly GenericParameter UnresolvedGenericMethodParameter = + new DummyGenericParameterProvider(true).DummyParameter; public readonly T Item; public readonly ReadOnlyCollection TypeArguments; @@ -308,28 +385,99 @@ namespace ICSharpCode.Decompiler.Ast public TypeReference ResolveWithContext(TypeReference type) { var genericParameter = type as GenericParameter; - if (genericParameter != null && genericParameter.Owner.GenericParameterType == GenericParameterType.Type) { - return this.TypeArguments[genericParameter.Position]; + if (genericParameter != null) + if (genericParameter.Owner.GenericParameterType == GenericParameterType.Type) + return this.TypeArguments[genericParameter.Position]; + else + return genericParameter.Owner.GenericParameterType == GenericParameterType.Type + ? UnresolvedGenericTypeParameter : UnresolvedGenericMethodParameter; + var typeSpecification = type as TypeSpecification; + if (typeSpecification != null) { + var resolvedElementType = ResolveWithContext(typeSpecification.ElementType); + return ReplaceElementType(typeSpecification, resolvedElementType); } - var arrayType = type as ArrayType; + return type.ResolveOrThrow(); + } + + private TypeReference ReplaceElementType(TypeSpecification ts, TypeReference newElementType) + { + var arrayType = ts as ArrayType; if (arrayType != null) { - var resolvedElementType = ResolveWithContext(arrayType.ElementType); - if (resolvedElementType == null) - return null; - if (resolvedElementType == arrayType.ElementType) + if (newElementType == arrayType.ElementType) return arrayType; - var newArrayType = new ArrayType(resolvedElementType, arrayType.Rank); + var newArrayType = new ArrayType(newElementType, arrayType.Rank); for (int dimension = 0; dimension < arrayType.Rank; dimension++) newArrayType.Dimensions[dimension] = arrayType.Dimensions[dimension]; return newArrayType; } - return type.ResolveOrThrow(); + var byReferenceType = ts as ByReferenceType; + if (byReferenceType != null) { + return new ByReferenceType(newElementType); + } + // TODO: should we throw an exception instead calling Resolve method? + return ts.ResolveOrThrow(); } public GenericContext ApplyTo(T2 item) where T2 : class { return new GenericContext(item, this.TypeArguments); } + + private class DummyGenericParameterProvider : IGenericParameterProvider + { + readonly Mono.Cecil.GenericParameterType type; + readonly Mono.Collections.Generic.Collection parameters; + + public DummyGenericParameterProvider(bool methodTypeParameter) + { + type = methodTypeParameter ? Mono.Cecil.GenericParameterType.Method : + Mono.Cecil.GenericParameterType.Type; + parameters = new Mono.Collections.Generic.Collection(1); + parameters.Add(new GenericParameter(this)); + } + + public GenericParameter DummyParameter + { + get { return parameters[0]; } + } + + bool IGenericParameterProvider.HasGenericParameters + { + get { throw new NotImplementedException(); } + } + + bool IGenericParameterProvider.IsDefinition + { + get { throw new NotImplementedException(); } + } + + ModuleDefinition IGenericParameterProvider.Module + { + get { throw new NotImplementedException(); } + } + + Mono.Collections.Generic.Collection IGenericParameterProvider.GenericParameters + { + get { return parameters; } + } + + GenericParameterType IGenericParameterProvider.GenericParameterType + { + get { return type; } + } + + MetadataToken IMetadataTokenProvider.MetadataToken + { + get + { + throw new NotImplementedException(); + } + set + { + throw new NotImplementedException(); + } + } + } } } } diff --git a/ICSharpCode.Decompiler/Tests/ICSharpCode.Decompiler.Tests.csproj b/ICSharpCode.Decompiler/Tests/ICSharpCode.Decompiler.Tests.csproj index 90a2db494..b4906c60f 100644 --- a/ICSharpCode.Decompiler/Tests/ICSharpCode.Decompiler.Tests.csproj +++ b/ICSharpCode.Decompiler/Tests/ICSharpCode.Decompiler.Tests.csproj @@ -69,7 +69,7 @@ - + @@ -107,4 +107,4 @@ - + \ No newline at end of file diff --git a/ICSharpCode.Decompiler/Tests/Types/S_TypeMemberDeclarations.cs b/ICSharpCode.Decompiler/Tests/Types/S_TypeMemberDeclarations.cs index 401bfab61..22458bcfc 100644 --- a/ICSharpCode.Decompiler/Tests/Types/S_TypeMemberDeclarations.cs +++ b/ICSharpCode.Decompiler/Tests/Types/S_TypeMemberDeclarations.cs @@ -428,8 +428,8 @@ namespace IndexerOverrideRestrictedAccessorOnly } } } -//$$ PropertyHiding -namespace PropertyHiding +//$$ HideProperty +namespace HideProperty { public class A { @@ -467,8 +467,397 @@ namespace PropertyHiding } } } -//$$ IndexerHidingGeneric -namespace IndexerHidingGeneric +//$$ HideMembers +namespace HideMembers +{ + public class A + { + public int F; + public int Prop + { + get + { + return 3; + } + } + public int G + { + get + { + return 3; + } + } + } + public class B : A + { + public new int F + { + get + { + return 3; + } + } + public new string Prop + { + get + { + return "a"; + } + } + } + public class C : A + { + public new int G; + } + public class D : A + { + public new void F() + { + } + } + public class D1 : D + { + public new int F; + } + public class E : A + { + private new class F + { + } + } +} +//$$ HideMembers2 +namespace HideMembers2 +{ + public class G + { + public int Item + { + get + { + return 1; + } + } + } + public class G2 : G + { + public int this[int i] + { + get + { + return 2; + } + } + } + public class G3 : G2 + { + public new int Item + { + get + { + return 4; + } + } + } + public class H + { + public int this[int j] + { + get + { + return 0; + } + } + } + public class H2 : H + { + public int Item + { + get + { + return 2; + } + } + } + public class H3 : H2 + { + public new string this[int j] + { + get + { + return null; + } + } + } +} +//$$ HideMembers2a +namespace HideMembers2a +{ + public interface IA + { + int this[int i] + { + get; + } + } + public class A : IA + { + int IA.this[int i] + { + get + { + throw new NotImplementedException(); + } + } + } + public class A1 : A + { + public int this[int i] + { + get + { + return 3; + } + } + } +} +//$$ HideMembers3 +namespace HideMembers3 +{ + public class G + { + public void M1(T p) + { + } + public int M2(int t) + { + return 3; + } + } + public class G1 : G + { + public new int M1(int i) + { + return 0; + } + public int M2(T i) + { + return 2; + } + } + public class G2 : G + { + public int M1(T p) + { + return 4; + } + } + public class J + { + public int P + { + get + { + return 2; + } + } + } + public class J2 : J + { + public int get_P; + } +} +//$$ HideMembers4 +namespace HideMembers4 +{ + public class A + { + public void M(T t) + { + } + } + public class A1 : A + { + public new void M(K t) + { + } + public void M(int t) + { + } + } + public class B + { + public void M() + { + } + public void M1() + { + } + public void M2(T t) + { + } + } + public class B1 : B + { + public void M() + { + } + public new void M1() + { + } + public new void M2(R r) + { + } + } + public class C + { + public void M(T t) + { + } + } + public class C1 : C + { + public void M(TT t) + { + } + } +} +//$$ HideMembers5 +namespace HideMembers5 +{ + public class A + { + public void M(int t) + { + } + } + public class A1 : A + { + public void M(ref int t) + { + } + } + public class B + { + public void M(ref int l) + { + } + } + public class B1 : B + { + public void M(out int l) + { + l = 2; + } + public void M(ref long l) + { + } + } +} +//$$ HideMemberSkipNotVisible +namespace HideMemberSkipNotVisible +{ + public class A + { + protected int F; + protected string P + { + get + { + return null; + } + } + } + public class B : A + { + private new string F; + private new int P + { + set + { + } + } + } +} +//$$ HideNestedClass +namespace HideNestedClass +{ + public class A + { + public class N1 + { + } + protected class N2 + { + } + private class N3 + { + } + internal class N4 + { + } + protected internal class N5 + { + } + } + public class B : A + { + public new int N1; + public new int N2; + public int N3; + public new int N4; + public new int N5; + } +} +//$$ HidePropertyReservedMethod +namespace HidePropertyReservedMethod +{ + public class A + { + public int P + { + get + { + return 1; + } + } + } + public class B : A + { + public int get_P() + { + return 2; + } + public void set_P(int value) + { + } + } +} +//$$ HideIndexerDiffAccessor +namespace HideIndexerDiffAccessor +{ + public class A + { + public int this[int i] + { + get + { + return 2; + } + } + } + public class B : A + { + public new int this[int j] + { + set + { + } + } + } +} +//$$ HideIndexerGeneric +namespace HideIndexerGeneric { public class A { @@ -515,8 +904,8 @@ namespace IndexerHidingGeneric } } } -//$$ MethodHiding -namespace MethodHiding +//$$ HideMethod +namespace HideMethod { public class A { @@ -539,8 +928,8 @@ namespace MethodHiding } } } -//$$ MethodHideGeneric -namespace MethodHideGeneric +//$$ HideMethodGeneric +namespace HideMethodGeneric { public class A { @@ -583,8 +972,8 @@ namespace MethodHideGeneric } } } -//$$ MethodHideGenericSkipPrivate -namespace MethodHideGenericSkipPrivate +//$$ HideMethodGenericSkipPrivate +namespace HideMethodGenericSkipPrivate { public class A { @@ -617,8 +1006,8 @@ namespace MethodHideGenericSkipPrivate } } } -//$$ MethodHideGeneric2 -namespace MethodHideGeneric2 +//$$ HideMethodGeneric2 +namespace HideMethodGeneric2 { public class A { @@ -669,8 +1058,51 @@ namespace MethodHideGeneric2 } } } -//$$ EventHiding -namespace EventHiding +//$$ HideMethodDiffSignatures +namespace HideMethodDiffSignatures +{ + public class C1 + { + public virtual void M(T arg) + { + } + } + public class C2 : C1 + { + public new virtual void M(T2 arg) + { + } + } + public class C3 : C2 + { + public new virtual void M(bool arg) + { + } + } +} +//$$ HideMethodStatic +namespace HideMethodStatic +{ + public class A + { + public int N + { + get + { + return 0; + } + } + } + public class B + { + public int N() + { + return 0; + } + } +} +//$$ HideEvent +namespace HideEvent { public class A { From e552ae0fa1baaf7506ff6d994b1c2513c51b488a Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Wed, 4 May 2011 20:12:13 +0200 Subject: [PATCH 2/5] Display XML documentation in decompiler output. --- ICSharpCode.Decompiler/DecompilerSettings.cs | 15 ++++ ILSpy/CSharpLanguage.cs | 24 +++--- ILSpy/DecompilerSettingsPanel.xaml | 1 + ILSpy/DecompilerSettingsPanel.xaml.cs | 2 + ILSpy/ILSpy.csproj | 1 + ILSpy/TextView/DecompilerTextView.cs | 6 +- ILSpy/XmlDoc/AddXmlDocTransform.cs | 80 ++++++++++++++++++++ 7 files changed, 116 insertions(+), 13 deletions(-) create mode 100644 ILSpy/XmlDoc/AddXmlDocTransform.cs diff --git a/ICSharpCode.Decompiler/DecompilerSettings.cs b/ICSharpCode.Decompiler/DecompilerSettings.cs index 32b257eda..4d5d62d76 100644 --- a/ICSharpCode.Decompiler/DecompilerSettings.cs +++ b/ICSharpCode.Decompiler/DecompilerSettings.cs @@ -209,6 +209,21 @@ namespace ICSharpCode.Decompiler } } + bool showXmlDocumentation = true; + + /// + /// Gets/Sets whether to include XML documentation comments in the decompiled code + /// + public bool ShowXmlDocumentation { + get { return showXmlDocumentation; } + set { + if (showXmlDocumentation != value) { + showXmlDocumentation = value; + OnPropertyChanged("ShowXmlDocumentation"); + } + } + } + public event PropertyChangedEventHandler PropertyChanged; protected virtual void OnPropertyChanged(string propertyName) diff --git a/ILSpy/CSharpLanguage.cs b/ILSpy/CSharpLanguage.cs index 8e6948e14..50afed4ea 100644 --- a/ILSpy/CSharpLanguage.cs +++ b/ILSpy/CSharpLanguage.cs @@ -32,6 +32,7 @@ using ICSharpCode.Decompiler; using ICSharpCode.Decompiler.Ast; using ICSharpCode.Decompiler.Ast.Transforms; using ICSharpCode.ILSpy.Baml; +using ICSharpCode.ILSpy.XmlDoc; using ICSharpCode.NRefactory.CSharp; using Mono.Cecil; @@ -89,8 +90,7 @@ namespace ICSharpCode.ILSpy WriteCommentLine(output, TypeToString(method.DeclaringType, includeNamespace: true)); AstBuilder codeDomBuilder = CreateAstBuilder(options, currentType: method.DeclaringType, isSingleMember: true); codeDomBuilder.AddMethod(method); - codeDomBuilder.RunTransformations(transformAbortCondition); - codeDomBuilder.GenerateCode(output); + RunTransformsAndGenerateCode(codeDomBuilder, output, options); } public override void DecompileProperty(PropertyDefinition property, ITextOutput output, DecompilationOptions options) @@ -98,8 +98,7 @@ namespace ICSharpCode.ILSpy WriteCommentLine(output, TypeToString(property.DeclaringType, includeNamespace: true)); AstBuilder codeDomBuilder = CreateAstBuilder(options, currentType: property.DeclaringType, isSingleMember: true); codeDomBuilder.AddProperty(property); - codeDomBuilder.RunTransformations(transformAbortCondition); - codeDomBuilder.GenerateCode(output); + RunTransformsAndGenerateCode(codeDomBuilder, output, options); } public override void DecompileField(FieldDefinition field, ITextOutput output, DecompilationOptions options) @@ -107,8 +106,7 @@ namespace ICSharpCode.ILSpy WriteCommentLine(output, TypeToString(field.DeclaringType, includeNamespace: true)); AstBuilder codeDomBuilder = CreateAstBuilder(options, currentType: field.DeclaringType, isSingleMember: true); codeDomBuilder.AddField(field); - codeDomBuilder.RunTransformations(transformAbortCondition); - codeDomBuilder.GenerateCode(output); + RunTransformsAndGenerateCode(codeDomBuilder, output, options); } public override void DecompileEvent(EventDefinition ev, ITextOutput output, DecompilationOptions options) @@ -116,16 +114,22 @@ namespace ICSharpCode.ILSpy WriteCommentLine(output, TypeToString(ev.DeclaringType, includeNamespace: true)); AstBuilder codeDomBuilder = CreateAstBuilder(options, currentType: ev.DeclaringType, isSingleMember: true); codeDomBuilder.AddEvent(ev); - codeDomBuilder.RunTransformations(transformAbortCondition); - codeDomBuilder.GenerateCode(output); + RunTransformsAndGenerateCode(codeDomBuilder, output, options); } public override void DecompileType(TypeDefinition type, ITextOutput output, DecompilationOptions options) { AstBuilder codeDomBuilder = CreateAstBuilder(options, currentType: type); codeDomBuilder.AddType(type); - codeDomBuilder.RunTransformations(transformAbortCondition); - codeDomBuilder.GenerateCode(output); + RunTransformsAndGenerateCode(codeDomBuilder, output, options); + } + + void RunTransformsAndGenerateCode(AstBuilder astBuilder, ITextOutput output, DecompilationOptions options) + { + astBuilder.RunTransformations(transformAbortCondition); + if (options.DecompilerSettings.ShowXmlDocumentation) + AddXmlDocTransform.Run(astBuilder.CompilationUnit); + astBuilder.GenerateCode(output); } public override void DecompileAssembly(LoadedAssembly assembly, ITextOutput output, DecompilationOptions options) diff --git a/ILSpy/DecompilerSettingsPanel.xaml b/ILSpy/DecompilerSettingsPanel.xaml index d9f0e938e..ae1a96404 100644 --- a/ILSpy/DecompilerSettingsPanel.xaml +++ b/ILSpy/DecompilerSettingsPanel.xaml @@ -7,5 +7,6 @@ Decompile enumerators (yield return) Decompile query expressions Use variable names from debug symbols, if available + Show XML documentation in decompiled code \ No newline at end of file diff --git a/ILSpy/DecompilerSettingsPanel.xaml.cs b/ILSpy/DecompilerSettingsPanel.xaml.cs index a9b04086b..d868afa66 100644 --- a/ILSpy/DecompilerSettingsPanel.xaml.cs +++ b/ILSpy/DecompilerSettingsPanel.xaml.cs @@ -62,6 +62,7 @@ namespace ICSharpCode.ILSpy s.YieldReturn = (bool?)e.Attribute("yieldReturn") ?? s.YieldReturn; s.QueryExpressions = (bool?)e.Attribute("queryExpressions") ?? s.QueryExpressions; s.UseDebugSymbols = (bool?)e.Attribute("useDebugSymbols") ?? s.UseDebugSymbols; + s.ShowXmlDocumentation = (bool?)e.Attribute("xmlDoc") ?? s.ShowXmlDocumentation; return s; } @@ -73,6 +74,7 @@ namespace ICSharpCode.ILSpy section.SetAttributeValue("yieldReturn", s.YieldReturn); section.SetAttributeValue("queryExpressions", s.QueryExpressions); section.SetAttributeValue("useDebugSymbols", s.UseDebugSymbols); + section.SetAttributeValue("xmlDoc", s.ShowXmlDocumentation); XElement existingElement = root.Element("DecompilerSettings"); if (existingElement != null) diff --git a/ILSpy/ILSpy.csproj b/ILSpy/ILSpy.csproj index 836318799..e14465833 100644 --- a/ILSpy/ILSpy.csproj +++ b/ILSpy/ILSpy.csproj @@ -156,6 +156,7 @@ + diff --git a/ILSpy/TextView/DecompilerTextView.cs b/ILSpy/TextView/DecompilerTextView.cs index f655e3f8a..1241037b1 100644 --- a/ILSpy/TextView/DecompilerTextView.cs +++ b/ILSpy/TextView/DecompilerTextView.cs @@ -138,17 +138,17 @@ namespace ICSharpCode.ILSpy.TextView } else if (mr is MethodReference) { mr = ((MethodReference)mr).Resolve() ?? mr; } + XmlDocRenderer renderer = new XmlDocRenderer(); + renderer.AppendText(MainWindow.Instance.CurrentLanguage.GetTooltip(mr)); XmlDocumentationProvider docProvider = XmlDocLoader.LoadDocumentation(mr.Module); if (docProvider != null) { - XmlDocRenderer renderer = new XmlDocRenderer(); - renderer.AppendText(MainWindow.Instance.CurrentLanguage.GetTooltip(mr)); string documentation = docProvider.GetDocumentation(XmlDocKeyProvider.GetKey(mr)); if (documentation != null) { renderer.AppendText(Environment.NewLine); renderer.AddXmlDocumentation(documentation); } - return renderer.CreateTextBlock(); } + return renderer.CreateTextBlock(); } return null; } diff --git a/ILSpy/XmlDoc/AddXmlDocTransform.cs b/ILSpy/XmlDoc/AddXmlDocTransform.cs new file mode 100644 index 000000000..dd0fb3311 --- /dev/null +++ b/ILSpy/XmlDoc/AddXmlDocTransform.cs @@ -0,0 +1,80 @@ +// Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of this +// software and associated documentation files (the "Software"), to deal in the Software +// without restriction, including without limitation the rights to use, copy, modify, merge, +// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons +// to whom the Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE +// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +using System; +using System.IO; +using ICSharpCode.NRefactory.CSharp; +using Mono.Cecil; + +namespace ICSharpCode.ILSpy.XmlDoc +{ + /// + /// Adds XML documentation for member definitions. + /// + static class AddXmlDocTransform + { + public static void Run(AstNode node) + { + if (node is AttributedNode) { + MemberReference mr = node.Annotation(); + if (mr != null && mr.Module != null) { + var xmldoc = XmlDocLoader.LoadDocumentation(mr.Module); + if (xmldoc != null) { + string doc = xmldoc.GetDocumentation(XmlDocKeyProvider.GetKey(mr)); + if (doc != null) { + InsertXmlDocumentation(node, new StringReader(doc)); + } + } + } + if (!(node is TypeDeclaration)) + return; // don't recurse into attributed nodes, except for type definitions + } + foreach (AstNode child in node.Children) + Run(child); + } + + static void InsertXmlDocumentation(AstNode node, StringReader r) + { + // Find the first non-empty line: + string firstLine; + do { + firstLine = r.ReadLine(); + if (firstLine == null) + return; + } while (string.IsNullOrWhiteSpace(firstLine)); + string indentation = firstLine.Substring(0, firstLine.Length - firstLine.TrimStart().Length); + string line = firstLine; + int skippedWhitespaceLines = 0; + // Copy all lines from input to output, except for empty lines at the end. + while (line != null) { + if (string.IsNullOrWhiteSpace(line)) { + skippedWhitespaceLines++; + } else { + while (skippedWhitespaceLines > 0) { + node.Parent.InsertChildBefore(node, new Comment(string.Empty, CommentType.Documentation), AstNode.Roles.Comment); + skippedWhitespaceLines--; + } + if (line.StartsWith(indentation, StringComparison.Ordinal)) + line = line.Substring(indentation.Length); + node.Parent.InsertChildBefore(node, new Comment(" " + line, CommentType.Documentation), AstNode.Roles.Comment); + } + line = r.ReadLine(); + } + } + } +} From 44b577af40d2b2db2350a0213fc4837fe4de2ba0 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Fri, 6 May 2011 13:54:41 +0200 Subject: [PATCH 3/5] Trying to fix #46 ("Check for updates" fails behind a web proxy). --- ILSpy/AboutPage.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ILSpy/AboutPage.cs b/ILSpy/AboutPage.cs index 101d244d6..c88f832dc 100644 --- a/ILSpy/AboutPage.cs +++ b/ILSpy/AboutPage.cs @@ -177,7 +177,7 @@ namespace ICSharpCode.ILSpy { var tcs = new TaskCompletionSource(); WebClient wc = new WebClient(); - wc.Proxy = new WebProxy() { UseDefaultCredentials = true }; + wc.UseDefaultCredentials = true; wc.DownloadDataCompleted += delegate(object sender, DownloadDataCompletedEventArgs e) { if (e.Error != null) { tcs.SetException(e.Error); From 553ea3f6988e5869c5196132b1c74987b42ca8db Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Fri, 6 May 2011 14:27:00 +0200 Subject: [PATCH 4/5] Ignore exceptions while reading debug symbols. Closes #169. --- ILSpy/LoadedAssembly.cs | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/ILSpy/LoadedAssembly.cs b/ILSpy/LoadedAssembly.cs index 29cc0c59e..8285be9ae 100644 --- a/ILSpy/LoadedAssembly.cs +++ b/ILSpy/LoadedAssembly.cs @@ -88,24 +88,28 @@ namespace ICSharpCode.ILSpy // runs on background thread ReaderParameters p = new ReaderParameters(); p.AssemblyResolver = new MyAssemblyResolver(this); - try { - if (DecompilerSettingsPanel.CurrentDecompilerSettings.UseDebugSymbols) { - SetSymbolSettings(p); + AssemblyDefinition asm = AssemblyDefinition.ReadAssembly(fileName, p); + if (DecompilerSettingsPanel.CurrentDecompilerSettings.UseDebugSymbols) { + try { + LoadSymbols(asm.MainModule); + } catch (IOException) { + } catch (UnauthorizedAccessException) { + } catch (InvalidOperationException) { + // ignore any errors during symbol loading } - return AssemblyDefinition.ReadAssembly(fileName, p); - } finally { - if (p.SymbolStream != null) - p.SymbolStream.Dispose(); } + return asm; } - private void SetSymbolSettings(ReaderParameters p) + private void LoadSymbols(ModuleDefinition module) { // search for pdb in same directory as dll string pdbName = Path.Combine(Path.GetDirectoryName(fileName), Path.GetFileNameWithoutExtension(fileName) + ".pdb"); if (File.Exists(pdbName)) { - p.ReadSymbols = true; - p.SymbolStream = File.OpenRead(pdbName); + using (Stream s = File.OpenRead(pdbName)) { + module.ReadSymbols(new Mono.Cecil.Pdb.PdbReaderProvider().GetSymbolReader(module, s)); + } + return; } // TODO: use symbol cache, get symbols from microsoft From fc02629e1a5244cc761d17dc39cd9c7800e3a88a Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sat, 7 May 2011 18:25:37 +0200 Subject: [PATCH 5/5] Squashed 'NRefactory/' changes from b8330be..1e4a1d9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1e4a1d9 add missing CSDemo files b5c5547 finished implementation of global level VB constructs a810296 - fixed bugs/missing features in ExpressionFinder.atg - add QualifiedType - partially implement TypeName in the parser dd8c7f7 add new VBDemo 99d4a8f remove code from MainForm in sample 13a8348 add XmlLiteralString d82f280 reimplemented tests for OptionStatement cb5a173 deactivated uncompilable unit tests; added XmlIdentifier; removed old classes b8599fc remove old parser code and further cleanup e1ee10a start implementing new VB AST; remove AST generator b9aa1ec Added some null checks. 3b051e5 Fixed alias 'global' member location. 8be17ea Updated mcs/fixed qualifiedalias member location. 5d83bea C# type system convert visitor: add support for attribute arguments. a917b1c Evaluate constant expressions in the correct context. 344476e Fix contracts. e1ac50d Implemented C# attributes. eb24135 Implemented IConstantValue for C#. Fixed bugs when resolving conditional expressions. git-subtree-dir: NRefactory git-subtree-split: 1e4a1d911cb430db2a4199695ee73dfd89bcc543 --- .../CSDemo.Designer.cs | 151 + ICSharpCode.NRefactory.Demo/CSDemo.cs | 232 + ICSharpCode.NRefactory.Demo/CSDemo.resx | 120 + .../ICSharpCode.NRefactory.Demo.csproj | 25 +- .../MainForm.Designer.cs | 162 +- ICSharpCode.NRefactory.Demo/MainForm.cs | 194 - ICSharpCode.NRefactory.Demo/VBAstView.cs | 172 +- .../VBDemo.Designer.cs | 67 +- ICSharpCode.NRefactory.Demo/VBDemo.cs | 120 +- .../Resolver/ConditionalOperatorTests.cs | 85 + .../ICSharpCode.NRefactory.Tests.csproj | 4 +- .../TypeSystem/StructureTests.cs | 22 + .../TypeSystem/TestInterningProvider.cs | 2 +- .../TypeSystem/TypeSystemTests.cs | 26 +- .../General/UnitTest.cs | 149 +- .../ICSharpCode.NRefactory.VB.Tests.csproj | 79 +- .../Lexer/CustomLexerTests.cs | 2 +- .../Lexer/ImplicitLineContinuationTests.cs | 2 +- .../Lexer/LexerContextTests.cs | 2 +- .../Lexer/LexerPositionTests.cs | 42 +- .../Lexer/LexerTests.cs | 2 +- .../Lexer/LiteralsTests.cs | 2 +- .../Lexer/XmlModeLexerTests.cs | 4 +- .../CodeDOM/InvocationExpressionTest.cs | 4 +- .../Output/SpecialOutputVisitorTest.cs | 2 +- .../Parser/CheckParentVisitor.cs | 35 - .../BinaryOperatorExpressionTests.cs | 72 +- .../Parser/Expressions/CastExpressionTests.cs | 14 +- .../Expressions/InvocationExpressionTests.cs | 18 +- .../MemberReferenceExpressionTests.cs | 8 +- .../ObjectCreateExpressionTests.cs | 8 +- .../Expressions/QueryExpressionTests.cs | 4 +- .../Expressions/TypeOfIsExpressionTests.cs | 4 +- .../UnaryOperatorExpressionTests.cs | 2 +- .../Parser/Expressions/XmlExpressionTests.cs | 4 +- .../GlobalScope/AttributeSectionTests.cs | 116 +- .../GlobalScope/DelegateDeclarationTests.cs | 42 - .../GlobalScope/ImportsStatementTests.cs | 168 + .../GlobalScope/NamespaceDeclarationTests.cs | 58 +- .../GlobalScope/OptionDeclarationTests.cs | 87 - .../GlobalScope/OptionStatementTests.cs | 113 + .../GlobalScope/TypeDeclarationTests.cs | 378 +- .../GlobalScope/UsingDeclarationTests.cs | 207 - .../Parser/LocationAssignmentCheckVisitor.cs | 26 - .../Parser/ParseUtil.cs | 148 +- .../Parser/SnippetParserTests.cs | 16 +- .../Parser/Statements/SwitchStatementTests.cs | 4 +- ICSharpCode.NRefactory.VB/Ast/AbstractNode.cs | 73 - ICSharpCode.NRefactory.VB/Ast/AstLocation.cs | 137 + ICSharpCode.NRefactory.VB/Ast/AstNode.cs | 730 ++ .../Ast/AstNodeCollection.cs | 209 + ICSharpCode.NRefactory.VB/Ast/Enums.cs | 111 +- .../Ast/Expressions/Expression.cs | 33 + .../Ast/Expressions/PrimitiveExpression.cs | 75 + .../Ast/Expressions/SimpleNameExpression.cs | 27 + .../Ast/Expressions/XmlIdentifier.cs | 72 + .../Ast/Expressions/XmlLiteralString.cs | 69 + .../Ast/General/Attribute.cs | 93 + .../Ast/General/AttributeBlock.cs | 36 + .../Ast/General/AttributedNode.cs | 67 + .../Ast/General/BlockStatement.cs | 58 - .../Ast/General/CompilationUnit.cs | 73 +- .../Ast/General/Expression.cs | 103 - .../Ast/General/LocalVariableDeclaration.cs | 99 - .../Ast/General/ParameterDeclaration.cs | 40 + .../Ast/General/PrimitiveExpression.cs | 53 - .../Ast/General/Statement.cs | 62 - .../Ast/General/TypeParameterDeclaration.cs | 44 + ICSharpCode.NRefactory.VB/Ast/Generated.cs | 10017 ++++++++-------- .../Ast/GlobalScope/DelegateDeclaration.cs | 52 + .../Ast/GlobalScope/EnumDeclaration.cs | 44 + .../Ast/GlobalScope/EnumMemberDeclaration.cs | 39 + .../Ast/GlobalScope/ImportsClause.cs | 113 + .../Ast/GlobalScope/ImportsStatement.cs | 36 + .../Ast/GlobalScope/NamespaceDeclaration.cs | 78 + .../Ast/GlobalScope/OptionStatement.cs | 60 + .../Ast/GlobalScope/TypeDeclaration.cs | 58 + ICSharpCode.NRefactory.VB/Ast/INode.cs | 51 - ICSharpCode.NRefactory.VB/Ast/Identifier.cs | 91 + .../Ast/Statements/BlockStatement.cs | 125 + .../Ast/Statements/Statement.cs | 132 + .../Ast/TypeName/AstType.cs | 145 + .../Ast/TypeName/ComposedType.cs | 119 + .../Ast/TypeName/PrimitiveType.cs | 57 + .../Ast/TypeName/QualifiedType.cs | 66 + .../Ast/TypeName/SimpleType.cs | 87 + .../Ast/TypeReference.cs | 427 - .../Ast/VBModifierToken.cs | 125 + ICSharpCode.NRefactory.VB/Ast/VBTokenNode.cs | 87 + .../AstBuilder/ExpressionBuilder.cs | 8 +- .../AstBuilder/StatementBuilder.cs | 84 +- .../EnvironmentInformationProvider.cs | 22 - ICSharpCode.NRefactory.VB/IAstVisitor.cs | 280 +- .../ICSharpCode.NRefactory.VB.csproj | 64 +- ICSharpCode.NRefactory.VB/Lexer/Block.cs | 4 +- .../Lexer/ExpressionFinder.atg | 8 + .../Lexer/ExpressionFinder.cs | 2 +- ICSharpCode.NRefactory.VB/Lexer/Parser.cs | 2656 ++-- .../Lexer/SavepointEventArgs.cs | 4 +- .../Lexer/Special/BlankLine.cs | 22 +- .../Lexer/Special/Comment.cs | 102 +- .../Lexer/Special/CommentType.cs | 12 +- .../Lexer/Special/ISpecial.cs | 88 +- .../Lexer/Special/PreProcessingDirective.cs | 294 +- .../Lexer/Special/SpecialTracker.cs | 122 +- .../Lexer/Special/TagComment.cs | 36 +- ICSharpCode.NRefactory.VB/Lexer/Token.cs | 36 +- ICSharpCode.NRefactory.VB/Lexer/VBLexer.cs | 158 +- ICSharpCode.NRefactory.VB/Location.cs | 121 - .../OperatorPrecedence.cs | 84 - .../OutputVisitor/IOutputFormatter.cs | 39 + .../OutputVisitor/OutputVisitor.cs | 222 + .../TextWriterOutputFormatter.cs | 83 + .../OutputVisitor/VBFormattingOptions.cs | 17 + .../Parser/ModifierList.cs | 69 - .../Parser/ParamModifierList.cs | 49 - ICSharpCode.NRefactory.VB/Parser/Parser.cs | 5127 +------- ICSharpCode.NRefactory.VB/Parser/VBParser.cs | 213 +- ICSharpCode.NRefactory.VB/Parser/vb.atg | 3587 +----- ICSharpCode.NRefactory.VB/ParserFactory.cs | 45 - .../PrettyPrinter/AbstractOutputFormatter.cs | 26 +- .../PrettyPrinter/IOutputAstVisitor.cs | 44 +- .../PrettyPrinter/SpecialNodesInserter.cs | 264 +- .../VBNet/VBNetOutputFormatter.cs | 60 +- .../PrettyPrinter/VBNet/VBNetOutputVisitor.cs | 6000 ++++----- ICSharpCode.NRefactory.VB/SnippetParser.cs | 130 - ICSharpCode.NRefactory.VB/VBParser.cs | 55 + .../Visitors/AbstractAstTransformer.cs | 4111 ++++--- .../Visitors/AbstractAstVisitor.cs | 2276 ++-- .../Visitors/CodeDOMOutputVisitor.cs | 1534 --- .../Visitors/CodeDOMVerboseOutputGenerator.cs | 356 - .../Visitors/LookupTableVisitor.cs | 273 - .../Visitors/NodeTrackingAstVisitor.cs | 2480 ++-- .../Visitors/NotImplementedAstVisitor.cs | 469 - .../Visitors/PrefixFieldsVisitor.cs | 143 - .../Visitors/RenameIdentifierVisitor.cs | 61 - .../Visitors/SetParentVisitor.cs | 33 - .../Visitors/SetRegionInclusionVisitor.cs | 73 - .../CSharp/Ast/Identifier.cs | 11 +- ICSharpCode.NRefactory/CSharp/Ast/Role.cs | 8 +- .../CSharp/OutputVisitor/OutputVisitor.cs | 2 + .../CSharp/Parser/CSharpParser.cs | 1117 +- .../CSharp/Parser/ParsedFile.cs | 6 + .../CSharp/Parser/TypeSystemConvertVisitor.cs | 288 +- .../CSharp/Parser/mcs/anonymous.cs | 2 +- .../CSharp/Parser/mcs/argument.cs | 5 +- .../CSharp/Parser/mcs/assembly.cs | 2 +- .../CSharp/Parser/mcs/assign.cs | 2 +- .../CSharp/Parser/mcs/attribute.cs | 27 +- .../CSharp/Parser/mcs/cfold.cs | 34 +- .../CSharp/Parser/mcs/class.cs | 299 +- .../CSharp/Parser/mcs/codegen.cs | 3 - .../CSharp/Parser/mcs/const.cs | 4 +- .../CSharp/Parser/mcs/constant.cs | 6 +- .../CSharp/Parser/mcs/context.cs | 18 +- .../CSharp/Parser/mcs/convert.cs | 396 +- .../CSharp/Parser/mcs/cs-parser.cs | 8330 ++++++------- .../CSharp/Parser/mcs/cs-parser.jay | 18 +- .../CSharp/Parser/mcs/cs-tokenizer.cs | 21 +- .../CSharp/Parser/mcs/decl.cs | 9 +- .../CSharp/Parser/mcs/delegate.cs | 22 +- .../CSharp/Parser/mcs/doc.cs | 11 +- .../CSharp/Parser/mcs/driver.cs | 2 +- .../CSharp/Parser/mcs/dynamic.cs | 32 +- .../CSharp/Parser/mcs/ecore.cs | 137 +- .../CSharp/Parser/mcs/enum.cs | 16 +- .../CSharp/Parser/mcs/eval.cs | 22 +- .../CSharp/Parser/mcs/expression.cs | 344 +- .../CSharp/Parser/mcs/field.cs | 11 +- .../CSharp/Parser/mcs/generic.cs | 364 +- .../CSharp/Parser/mcs/import.cs | 80 +- .../CSharp/Parser/mcs/iterators.cs | 32 +- .../CSharp/Parser/mcs/literal.cs | 2 +- .../CSharp/Parser/mcs/membercache.cs | 40 +- .../CSharp/Parser/mcs/method.cs | 121 +- .../CSharp/Parser/mcs/namespace.cs | 121 +- .../CSharp/Parser/mcs/nullable.cs | 64 +- .../CSharp/Parser/mcs/parameter.cs | 24 +- .../CSharp/Parser/mcs/pending.cs | 198 +- .../CSharp/Parser/mcs/property.cs | 47 +- .../CSharp/Parser/mcs/reflection.cs | 9 +- .../CSharp/Parser/mcs/report.cs | 4 +- .../CSharp/Parser/mcs/roottypes.cs | 12 +- .../CSharp/Parser/mcs/statement.cs | 64 +- .../CSharp/Parser/mcs/typemanager.cs | 23 +- .../CSharp/Parser/mcs/typespec.cs | 48 +- .../CSharp/Resolver/CSharpAttribute.cs | 140 + .../CSharp/Resolver/CSharpResolver.cs | 68 +- .../CSharp/Resolver/ConstantValues.cs | 582 + .../CSharp/Resolver/MapTypeIntoNewContext.cs | 49 + .../MemberTypeOrNamespaceReference.cs | 11 + .../CSharp/Resolver/ResolveVisitor.cs | 9 +- .../SimpleTypeOrNamespaceReference.cs | 11 + .../ICSharpCode.NRefactory.csproj | 7 +- .../PatternMatching/INode.cs | 4 +- .../PatternMatching/OptionalNode.cs | 2 +- .../PatternMatching/Pattern.cs | 6 +- .../PatternMatching/Repeat.cs | 2 +- .../TypeSystem/ArrayType.cs | 2 +- .../TypeSystem/IAttribute.cs | 30 +- .../TypeSystem/ITypeDefinition.cs | 4 + .../TypeSystem/ITypeParameter.cs | 10 +- .../Implementation/DefaultAttribute.cs | 10 + .../Implementation/DefaultTypeParameter.cs | 6 +- NRefactory.sln | 32 +- VBAstGenerator/.gitignore | 3 - VBAstGenerator/AssemblyInfo.cs | 29 - VBAstGenerator/Ast/Expressions.cs | 372 - VBAstGenerator/Ast/GlobalLevel.cs | 107 - VBAstGenerator/Ast/Node.cs | 68 - VBAstGenerator/Ast/Statements.cs | 262 - VBAstGenerator/Ast/TypeLevel.cs | 227 - VBAstGenerator/Attributes.cs | 176 - VBAstGenerator/EasyCodeDom.cs | 382 - VBAstGenerator/KeywordGenerator.cs | 380 - VBAstGenerator/Main.cs | 591 - VBAstGenerator/VBAstGenerator.csproj | 64 - 217 files changed, 27762 insertions(+), 37865 deletions(-) create mode 100644 ICSharpCode.NRefactory.Demo/CSDemo.Designer.cs create mode 100644 ICSharpCode.NRefactory.Demo/CSDemo.cs create mode 100644 ICSharpCode.NRefactory.Demo/CSDemo.resx create mode 100644 ICSharpCode.NRefactory.Tests/CSharp/Resolver/ConditionalOperatorTests.cs create mode 100644 ICSharpCode.NRefactory.Tests/TypeSystem/StructureTests.cs delete mode 100644 ICSharpCode.NRefactory.VB.Tests/Parser/CheckParentVisitor.cs delete mode 100644 ICSharpCode.NRefactory.VB.Tests/Parser/GlobalScope/DelegateDeclarationTests.cs create mode 100644 ICSharpCode.NRefactory.VB.Tests/Parser/GlobalScope/ImportsStatementTests.cs delete mode 100644 ICSharpCode.NRefactory.VB.Tests/Parser/GlobalScope/OptionDeclarationTests.cs create mode 100644 ICSharpCode.NRefactory.VB.Tests/Parser/GlobalScope/OptionStatementTests.cs delete mode 100644 ICSharpCode.NRefactory.VB.Tests/Parser/GlobalScope/UsingDeclarationTests.cs delete mode 100644 ICSharpCode.NRefactory.VB.Tests/Parser/LocationAssignmentCheckVisitor.cs delete mode 100644 ICSharpCode.NRefactory.VB/Ast/AbstractNode.cs create mode 100644 ICSharpCode.NRefactory.VB/Ast/AstLocation.cs create mode 100644 ICSharpCode.NRefactory.VB/Ast/AstNode.cs create mode 100644 ICSharpCode.NRefactory.VB/Ast/AstNodeCollection.cs create mode 100644 ICSharpCode.NRefactory.VB/Ast/Expressions/Expression.cs create mode 100644 ICSharpCode.NRefactory.VB/Ast/Expressions/PrimitiveExpression.cs create mode 100644 ICSharpCode.NRefactory.VB/Ast/Expressions/SimpleNameExpression.cs create mode 100644 ICSharpCode.NRefactory.VB/Ast/Expressions/XmlIdentifier.cs create mode 100644 ICSharpCode.NRefactory.VB/Ast/Expressions/XmlLiteralString.cs create mode 100644 ICSharpCode.NRefactory.VB/Ast/General/Attribute.cs create mode 100644 ICSharpCode.NRefactory.VB/Ast/General/AttributeBlock.cs create mode 100644 ICSharpCode.NRefactory.VB/Ast/General/AttributedNode.cs delete mode 100644 ICSharpCode.NRefactory.VB/Ast/General/BlockStatement.cs delete mode 100644 ICSharpCode.NRefactory.VB/Ast/General/Expression.cs delete mode 100644 ICSharpCode.NRefactory.VB/Ast/General/LocalVariableDeclaration.cs create mode 100644 ICSharpCode.NRefactory.VB/Ast/General/ParameterDeclaration.cs delete mode 100644 ICSharpCode.NRefactory.VB/Ast/General/PrimitiveExpression.cs delete mode 100644 ICSharpCode.NRefactory.VB/Ast/General/Statement.cs create mode 100644 ICSharpCode.NRefactory.VB/Ast/General/TypeParameterDeclaration.cs create mode 100644 ICSharpCode.NRefactory.VB/Ast/GlobalScope/DelegateDeclaration.cs create mode 100644 ICSharpCode.NRefactory.VB/Ast/GlobalScope/EnumDeclaration.cs create mode 100644 ICSharpCode.NRefactory.VB/Ast/GlobalScope/EnumMemberDeclaration.cs create mode 100644 ICSharpCode.NRefactory.VB/Ast/GlobalScope/ImportsClause.cs create mode 100644 ICSharpCode.NRefactory.VB/Ast/GlobalScope/ImportsStatement.cs create mode 100644 ICSharpCode.NRefactory.VB/Ast/GlobalScope/NamespaceDeclaration.cs create mode 100644 ICSharpCode.NRefactory.VB/Ast/GlobalScope/OptionStatement.cs create mode 100644 ICSharpCode.NRefactory.VB/Ast/GlobalScope/TypeDeclaration.cs delete mode 100644 ICSharpCode.NRefactory.VB/Ast/INode.cs create mode 100644 ICSharpCode.NRefactory.VB/Ast/Identifier.cs create mode 100644 ICSharpCode.NRefactory.VB/Ast/Statements/BlockStatement.cs create mode 100644 ICSharpCode.NRefactory.VB/Ast/Statements/Statement.cs create mode 100644 ICSharpCode.NRefactory.VB/Ast/TypeName/AstType.cs create mode 100644 ICSharpCode.NRefactory.VB/Ast/TypeName/ComposedType.cs create mode 100644 ICSharpCode.NRefactory.VB/Ast/TypeName/PrimitiveType.cs create mode 100644 ICSharpCode.NRefactory.VB/Ast/TypeName/QualifiedType.cs create mode 100644 ICSharpCode.NRefactory.VB/Ast/TypeName/SimpleType.cs delete mode 100644 ICSharpCode.NRefactory.VB/Ast/TypeReference.cs create mode 100644 ICSharpCode.NRefactory.VB/Ast/VBModifierToken.cs create mode 100644 ICSharpCode.NRefactory.VB/Ast/VBTokenNode.cs delete mode 100644 ICSharpCode.NRefactory.VB/EnvironmentInformationProvider.cs delete mode 100644 ICSharpCode.NRefactory.VB/Location.cs delete mode 100644 ICSharpCode.NRefactory.VB/OperatorPrecedence.cs create mode 100644 ICSharpCode.NRefactory.VB/OutputVisitor/IOutputFormatter.cs create mode 100644 ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs create mode 100644 ICSharpCode.NRefactory.VB/OutputVisitor/TextWriterOutputFormatter.cs create mode 100644 ICSharpCode.NRefactory.VB/OutputVisitor/VBFormattingOptions.cs delete mode 100644 ICSharpCode.NRefactory.VB/Parser/ModifierList.cs delete mode 100644 ICSharpCode.NRefactory.VB/Parser/ParamModifierList.cs delete mode 100644 ICSharpCode.NRefactory.VB/ParserFactory.cs delete mode 100644 ICSharpCode.NRefactory.VB/SnippetParser.cs create mode 100644 ICSharpCode.NRefactory.VB/VBParser.cs delete mode 100644 ICSharpCode.NRefactory.VB/Visitors/CodeDOMOutputVisitor.cs delete mode 100644 ICSharpCode.NRefactory.VB/Visitors/CodeDOMVerboseOutputGenerator.cs delete mode 100644 ICSharpCode.NRefactory.VB/Visitors/LookupTableVisitor.cs delete mode 100644 ICSharpCode.NRefactory.VB/Visitors/NotImplementedAstVisitor.cs delete mode 100644 ICSharpCode.NRefactory.VB/Visitors/PrefixFieldsVisitor.cs delete mode 100644 ICSharpCode.NRefactory.VB/Visitors/RenameIdentifierVisitor.cs delete mode 100644 ICSharpCode.NRefactory.VB/Visitors/SetParentVisitor.cs delete mode 100644 ICSharpCode.NRefactory.VB/Visitors/SetRegionInclusionVisitor.cs create mode 100644 ICSharpCode.NRefactory/CSharp/Resolver/CSharpAttribute.cs create mode 100644 ICSharpCode.NRefactory/CSharp/Resolver/ConstantValues.cs create mode 100644 ICSharpCode.NRefactory/CSharp/Resolver/MapTypeIntoNewContext.cs delete mode 100644 VBAstGenerator/.gitignore delete mode 100644 VBAstGenerator/AssemblyInfo.cs delete mode 100644 VBAstGenerator/Ast/Expressions.cs delete mode 100644 VBAstGenerator/Ast/GlobalLevel.cs delete mode 100644 VBAstGenerator/Ast/Node.cs delete mode 100644 VBAstGenerator/Ast/Statements.cs delete mode 100644 VBAstGenerator/Ast/TypeLevel.cs delete mode 100644 VBAstGenerator/Attributes.cs delete mode 100644 VBAstGenerator/EasyCodeDom.cs delete mode 100644 VBAstGenerator/KeywordGenerator.cs delete mode 100644 VBAstGenerator/Main.cs delete mode 100644 VBAstGenerator/VBAstGenerator.csproj diff --git a/ICSharpCode.NRefactory.Demo/CSDemo.Designer.cs b/ICSharpCode.NRefactory.Demo/CSDemo.Designer.cs new file mode 100644 index 000000000..998cee6fe --- /dev/null +++ b/ICSharpCode.NRefactory.Demo/CSDemo.Designer.cs @@ -0,0 +1,151 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +namespace ICSharpCode.NRefactory.Demo +{ + partial class CSDemo + { + /// + /// Designer variable used to keep track of non-visual components. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Disposes resources used by the control. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing) { + if (components != null) { + components.Dispose(); + } + } + base.Dispose(disposing); + } + + /// + /// This method is required for Windows Forms designer support. + /// Do not change the method contents inside the source code editor. The Forms designer might + /// not be able to load this method if it was changed manually. + /// + private void InitializeComponent() + { + this.splitContainer1 = new System.Windows.Forms.SplitContainer(); + this.csharpCodeTextBox = new System.Windows.Forms.TextBox(); + this.resolveButton = new System.Windows.Forms.Button(); + this.csharpTreeView = new System.Windows.Forms.TreeView(); + this.csharpGenerateCodeButton = new System.Windows.Forms.Button(); + this.csharpParseButton = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); + this.splitContainer1.Panel1.SuspendLayout(); + this.splitContainer1.Panel2.SuspendLayout(); + this.splitContainer1.SuspendLayout(); + this.SuspendLayout(); + // + // splitContainer1 + // + this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill; + this.splitContainer1.Location = new System.Drawing.Point(0, 0); + this.splitContainer1.Name = "splitContainer1"; + this.splitContainer1.Orientation = System.Windows.Forms.Orientation.Horizontal; + // + // splitContainer1.Panel1 + // + this.splitContainer1.Panel1.Controls.Add(this.csharpCodeTextBox); + // + // splitContainer1.Panel2 + // + this.splitContainer1.Panel2.Controls.Add(this.resolveButton); + this.splitContainer1.Panel2.Controls.Add(this.csharpTreeView); + this.splitContainer1.Panel2.Controls.Add(this.csharpGenerateCodeButton); + this.splitContainer1.Panel2.Controls.Add(this.csharpParseButton); + this.splitContainer1.Size = new System.Drawing.Size(475, 406); + this.splitContainer1.SplitterDistance = 178; + this.splitContainer1.TabIndex = 1; + // + // csharpCodeTextBox + // + this.csharpCodeTextBox.AcceptsReturn = true; + this.csharpCodeTextBox.AcceptsTab = true; + this.csharpCodeTextBox.Dock = System.Windows.Forms.DockStyle.Fill; + this.csharpCodeTextBox.Font = new System.Drawing.Font("Courier New", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.csharpCodeTextBox.HideSelection = false; + this.csharpCodeTextBox.Location = new System.Drawing.Point(0, 0); + this.csharpCodeTextBox.Multiline = true; + this.csharpCodeTextBox.Name = "csharpCodeTextBox"; + this.csharpCodeTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Both; + this.csharpCodeTextBox.Size = new System.Drawing.Size(475, 178); + this.csharpCodeTextBox.TabIndex = 0; + this.csharpCodeTextBox.Text = "using System;\r\nclass Test\r\n{\r\n public void Main(string[] args)\r\n {\r\n " + + " Console.WriteLine(\"Hello, World\");\r\n }\r\n}"; + this.csharpCodeTextBox.WordWrap = false; + this.csharpCodeTextBox.TextChanged += new System.EventHandler(this.CsharpCodeTextBoxTextChanged); + // + // resolveButton + // + this.resolveButton.Anchor = System.Windows.Forms.AnchorStyles.Top; + this.resolveButton.Location = new System.Drawing.Point(187, 3); + this.resolveButton.Name = "resolveButton"; + this.resolveButton.Size = new System.Drawing.Size(100, 23); + this.resolveButton.TabIndex = 3; + this.resolveButton.Text = "Resolve"; + this.resolveButton.UseVisualStyleBackColor = true; + this.resolveButton.Click += new System.EventHandler(this.ResolveButtonClick); + // + // csharpTreeView + // + this.csharpTreeView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.csharpTreeView.HideSelection = false; + this.csharpTreeView.Location = new System.Drawing.Point(3, 32); + this.csharpTreeView.Name = "csharpTreeView"; + this.csharpTreeView.Size = new System.Drawing.Size(467, 189); + this.csharpTreeView.TabIndex = 2; + this.csharpTreeView.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.CSharpTreeViewAfterSelect); + // + // csharpGenerateCodeButton + // + this.csharpGenerateCodeButton.Anchor = System.Windows.Forms.AnchorStyles.Top; + this.csharpGenerateCodeButton.Location = new System.Drawing.Point(293, 2); + this.csharpGenerateCodeButton.Name = "csharpGenerateCodeButton"; + this.csharpGenerateCodeButton.Size = new System.Drawing.Size(100, 23); + this.csharpGenerateCodeButton.TabIndex = 1; + this.csharpGenerateCodeButton.Text = "Generate"; + this.csharpGenerateCodeButton.UseVisualStyleBackColor = true; + this.csharpGenerateCodeButton.Click += new System.EventHandler(this.CSharpGenerateCodeButtonClick); + // + // csharpParseButton + // + this.csharpParseButton.Anchor = System.Windows.Forms.AnchorStyles.Top; + this.csharpParseButton.Location = new System.Drawing.Point(81, 3); + this.csharpParseButton.Name = "csharpParseButton"; + this.csharpParseButton.Size = new System.Drawing.Size(100, 23); + this.csharpParseButton.TabIndex = 0; + this.csharpParseButton.Text = "Parse"; + this.csharpParseButton.UseVisualStyleBackColor = true; + this.csharpParseButton.Click += new System.EventHandler(this.CSharpParseButtonClick); + // + // CSDemo + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.splitContainer1); + this.Name = "CSDemo"; + this.Size = new System.Drawing.Size(475, 406); + this.splitContainer1.Panel1.ResumeLayout(false); + this.splitContainer1.Panel1.PerformLayout(); + this.splitContainer1.Panel2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit(); + this.splitContainer1.ResumeLayout(false); + this.ResumeLayout(false); + } + private System.Windows.Forms.Button csharpParseButton; + private System.Windows.Forms.Button csharpGenerateCodeButton; + private System.Windows.Forms.TreeView csharpTreeView; + private System.Windows.Forms.Button resolveButton; + private System.Windows.Forms.TextBox csharpCodeTextBox; + private System.Windows.Forms.SplitContainer splitContainer1; + } +} diff --git a/ICSharpCode.NRefactory.Demo/CSDemo.cs b/ICSharpCode.NRefactory.Demo/CSDemo.cs new file mode 100644 index 000000000..d667596de --- /dev/null +++ b/ICSharpCode.NRefactory.Demo/CSDemo.cs @@ -0,0 +1,232 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics; +using System.Drawing; +using System.IO; +using System.Reflection; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using System.Windows.Forms; + +using ICSharpCode.NRefactory.CSharp; +using ICSharpCode.NRefactory.CSharp.Resolver; +using ICSharpCode.NRefactory.TypeSystem; +using ICSharpCode.NRefactory.TypeSystem.Implementation; + +namespace ICSharpCode.NRefactory.Demo +{ + /// + /// Description of CSDemo. + /// + public partial class CSDemo : UserControl + { + public CSDemo() + { + // + // The InitializeComponent() call is required for Windows Forms designer support. + // + InitializeComponent(); + + if (LicenseManager.UsageMode != LicenseUsageMode.Designtime) { + csharpCodeTextBox.SelectAll(); + CSharpParseButtonClick(null, null); + resolveButton.UseWaitCursor = true; + ThreadPool.QueueUserWorkItem( + delegate { + builtInLibs.Value.ToString(); + BeginInvoke(new Action(delegate { resolveButton.UseWaitCursor = false; })); + }); + } + } + + CompilationUnit compilationUnit; + + void CSharpParseButtonClick(object sender, EventArgs e) + { + CSharpParser parser = new CSharpParser(); + compilationUnit = parser.Parse(new StringReader(csharpCodeTextBox.Text)); + csharpTreeView.Nodes.Clear(); + foreach (var element in compilationUnit.Children) { + csharpTreeView.Nodes.Add(MakeTreeNode(element)); + } + SelectCurrentNode(csharpTreeView.Nodes); + resolveButton.Enabled = true; + } + + TreeNode MakeTreeNode(AstNode node) + { + TreeNode t = new TreeNode(GetNodeTitle(node)); + t.Tag = node; + foreach (AstNode child in node.Children) { + t.Nodes.Add(MakeTreeNode(child)); + } + return t; + } + + string GetNodeTitle(AstNode node) + { + StringBuilder b = new StringBuilder(); + b.Append(node.Role.ToString()); + b.Append(": "); + b.Append(node.GetType().Name); + bool hasProperties = false; + foreach (PropertyInfo p in node.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance)) { + if (p.Name == "NodeType" || p.Name == "IsNull") + continue; + if (p.PropertyType == typeof(string) || p.PropertyType.IsEnum || p.PropertyType == typeof(bool)) { + if (!hasProperties) { + hasProperties = true; + b.Append(" ("); + } else { + b.Append(", "); + } + b.Append(p.Name); + b.Append(" = "); + try { + object val = p.GetValue(node, null); + b.Append(val != null ? val.ToString() : "**null**"); + } catch (TargetInvocationException ex) { + b.Append("**" + ex.InnerException.GetType().Name + "**"); + } + } + } + if (hasProperties) + b.Append(")"); + return b.ToString(); + } + + bool SelectCurrentNode(TreeNodeCollection c) + { + int selectionStart = csharpCodeTextBox.SelectionStart; + int selectionEnd = selectionStart + csharpCodeTextBox.SelectionLength; + foreach (TreeNode t in c) { + AstNode node = t.Tag as AstNode; + if (node != null + && selectionStart >= GetOffset(csharpCodeTextBox, node.StartLocation) + && selectionEnd <= GetOffset(csharpCodeTextBox, node.EndLocation)) + { + if (selectionStart == selectionEnd + && (selectionStart == GetOffset(csharpCodeTextBox, node.StartLocation) + || selectionStart == GetOffset(csharpCodeTextBox, node.EndLocation))) + { + // caret is on border of this node; don't expand + csharpTreeView.SelectedNode = t; + } else { + t.Expand(); + if (!SelectCurrentNode(t.Nodes)) + csharpTreeView.SelectedNode = t; + } + return true; + } + } + return false; + } + + void CSharpGenerateCodeButtonClick(object sender, EventArgs e) + { + StringWriter w = new StringWriter(); + OutputVisitor output = new OutputVisitor(w, new CSharpFormattingOptions()); + compilationUnit.AcceptVisitor(output, null); + csharpCodeTextBox.Text = w.ToString(); + } + + int GetOffset(TextBox textBox, AstLocation location) + { + return textBox.GetFirstCharIndexFromLine(location.Line - 1) + location.Column - 1; + } + + void CSharpTreeViewAfterSelect(object sender, TreeViewEventArgs e) + { + AstNode node = e.Node.Tag as AstNode; + if (node != null) { + int startOffset = GetOffset(csharpCodeTextBox, node.StartLocation); + int endOffset = GetOffset(csharpCodeTextBox, node.EndLocation); + csharpCodeTextBox.Select(startOffset, endOffset - startOffset); + } + } + + Lazy> builtInLibs = new Lazy>( + delegate { + Assembly[] assemblies = { + typeof(object).Assembly, // mscorlib + typeof(Uri).Assembly, // System.dll + typeof(System.Linq.Enumerable).Assembly, // System.Core.dll +// typeof(System.Xml.XmlDocument).Assembly, // System.Xml.dll +// typeof(System.Drawing.Bitmap).Assembly, // System.Drawing.dll +// typeof(Form).Assembly, // System.Windows.Forms.dll + typeof(ICSharpCode.NRefactory.TypeSystem.IProjectContent).Assembly, + }; + IProjectContent[] projectContents = new IProjectContent[assemblies.Length]; + Stopwatch total = Stopwatch.StartNew(); + Parallel.For( + 0, assemblies.Length, + delegate (int i) { + Stopwatch w = Stopwatch.StartNew(); + CecilLoader loader = new CecilLoader(); + projectContents[i] = loader.LoadAssemblyFile(assemblies[i].Location); + Debug.WriteLine(Path.GetFileName(assemblies[i].Location) + ": " + w.Elapsed); + }); + Debug.WriteLine("Total: " + total.Elapsed); + return projectContents; + }); + + void ResolveButtonClick(object sender, EventArgs e) + { + SimpleProjectContent project = new SimpleProjectContent(); + TypeSystemConvertVisitor convertVisitor = new TypeSystemConvertVisitor(project, "dummy.cs"); + compilationUnit.AcceptVisitor(convertVisitor, null); + project.UpdateProjectContent(null, convertVisitor.ParsedFile.TopLevelTypeDefinitions, null, null); + + List projects = new List(); + projects.Add(project); + projects.AddRange(builtInLibs.Value); + + using (var context = new CompositeTypeResolveContext(projects).Synchronize()) { + CSharpResolver resolver = new CSharpResolver(context); + + IResolveVisitorNavigator navigator = null; + if (csharpTreeView.SelectedNode != null) { + navigator = new NodeListResolveVisitorNavigator(new[] { (AstNode)csharpTreeView.SelectedNode.Tag }); + } + ResolveVisitor visitor = new ResolveVisitor(resolver, convertVisitor.ParsedFile, navigator); + visitor.Scan(compilationUnit); + csharpTreeView.BeginUpdate(); + ShowResolveResultsInTree(csharpTreeView.Nodes, visitor); + csharpTreeView.EndUpdate(); + } + } + + void ShowResolveResultsInTree(TreeNodeCollection c, ResolveVisitor v) + { + foreach (TreeNode t in c) { + AstNode node = t.Tag as AstNode; + if (node != null) { + ResolveResult rr = v.GetResolveResult(node); + if (rr != null) + t.Text = GetNodeTitle(node) + " " + rr.ToString(); + else + t.Text = GetNodeTitle(node); + } + ShowResolveResultsInTree(t.Nodes, v); + } + } + + void CSharpCodeTextBoxKeyDown(object sender, KeyEventArgs e) + { + if (e.Control && e.KeyCode == Keys.A) { + e.Handled = true; + csharpCodeTextBox.SelectAll(); + } + } + + void CsharpCodeTextBoxTextChanged(object sender, EventArgs e) + { + resolveButton.Enabled = false; + } + } +} diff --git a/ICSharpCode.NRefactory.Demo/CSDemo.resx b/ICSharpCode.NRefactory.Demo/CSDemo.resx new file mode 100644 index 000000000..1af7de150 --- /dev/null +++ b/ICSharpCode.NRefactory.Demo/CSDemo.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ICSharpCode.NRefactory.Demo/ICSharpCode.NRefactory.Demo.csproj b/ICSharpCode.NRefactory.Demo/ICSharpCode.NRefactory.Demo.csproj index 169dd2a0d..841474f59 100644 --- a/ICSharpCode.NRefactory.Demo/ICSharpCode.NRefactory.Demo.csproj +++ b/ICSharpCode.NRefactory.Demo/ICSharpCode.NRefactory.Demo.csproj @@ -40,17 +40,9 @@ - - Form - - - VBEditDialog.cs - - - UserControl - - - VBAstView.cs + + + CSDemo.cs Form @@ -60,9 +52,7 @@ - - UserControl - + VBDemo.cs @@ -78,11 +68,8 @@ - - VBEditDialog.cs - - - VBAstView.cs + + CSDemo.cs MainForm.cs diff --git a/ICSharpCode.NRefactory.Demo/MainForm.Designer.cs b/ICSharpCode.NRefactory.Demo/MainForm.Designer.cs index c24f304ab..12c38ffb6 100644 --- a/ICSharpCode.NRefactory.Demo/MainForm.Designer.cs +++ b/ICSharpCode.NRefactory.Demo/MainForm.Designer.cs @@ -30,40 +30,32 @@ namespace ICSharpCode.NRefactory.Demo /// private void InitializeComponent() { - this.tabPage2 = new System.Windows.Forms.TabPage(); + this.miniToolStrip = new System.Windows.Forms.ToolStrip(); this.tabPage1 = new System.Windows.Forms.TabPage(); - this.splitContainer1 = new System.Windows.Forms.SplitContainer(); - this.csharpCodeTextBox = new System.Windows.Forms.TextBox(); - this.resolveButton = new System.Windows.Forms.Button(); - this.csharpTreeView = new System.Windows.Forms.TreeView(); - this.csharpGenerateCodeButton = new System.Windows.Forms.Button(); - this.csharpParseButton = new System.Windows.Forms.Button(); + this.csDemo1 = new ICSharpCode.NRefactory.Demo.CSDemo(); this.tabControl1 = new System.Windows.Forms.TabControl(); - this.miniToolStrip = new System.Windows.Forms.ToolStrip(); + this.tabPage2 = new System.Windows.Forms.TabPage(); this.vbDemo1 = new ICSharpCode.NRefactory.Demo.VBDemo(); - this.tabPage2.SuspendLayout(); this.tabPage1.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); - this.splitContainer1.Panel1.SuspendLayout(); - this.splitContainer1.Panel2.SuspendLayout(); - this.splitContainer1.SuspendLayout(); this.tabControl1.SuspendLayout(); + this.tabPage2.SuspendLayout(); this.SuspendLayout(); // - // tabPage2 + // miniToolStrip // - this.tabPage2.Controls.Add(this.vbDemo1); - this.tabPage2.Location = new System.Drawing.Point(4, 22); - this.tabPage2.Name = "tabPage2"; - this.tabPage2.Padding = new System.Windows.Forms.Padding(3); - this.tabPage2.Size = new System.Drawing.Size(507, 458); - this.tabPage2.TabIndex = 1; - this.tabPage2.Text = "VB"; - this.tabPage2.UseVisualStyleBackColor = true; + this.miniToolStrip.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.miniToolStrip.AutoSize = false; + this.miniToolStrip.CanOverflow = false; + this.miniToolStrip.Dock = System.Windows.Forms.DockStyle.None; + this.miniToolStrip.GripStyle = System.Windows.Forms.ToolStripGripStyle.Hidden; + this.miniToolStrip.Location = new System.Drawing.Point(13, 3); + this.miniToolStrip.Name = "miniToolStrip"; + this.miniToolStrip.Size = new System.Drawing.Size(16, 25); + this.miniToolStrip.TabIndex = 3; // // tabPage1 // - this.tabPage1.Controls.Add(this.splitContainer1); + this.tabPage1.Controls.Add(this.csDemo1); this.tabPage1.Location = new System.Drawing.Point(4, 22); this.tabPage1.Name = "tabPage1"; this.tabPage1.Padding = new System.Windows.Forms.Padding(3); @@ -72,90 +64,13 @@ namespace ICSharpCode.NRefactory.Demo this.tabPage1.Text = "C#"; this.tabPage1.UseVisualStyleBackColor = true; // - // splitContainer1 - // - this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill; - this.splitContainer1.Location = new System.Drawing.Point(3, 3); - this.splitContainer1.Name = "splitContainer1"; - this.splitContainer1.Orientation = System.Windows.Forms.Orientation.Horizontal; - // - // splitContainer1.Panel1 - // - this.splitContainer1.Panel1.Controls.Add(this.csharpCodeTextBox); - // - // splitContainer1.Panel2 - // - this.splitContainer1.Panel2.Controls.Add(this.resolveButton); - this.splitContainer1.Panel2.Controls.Add(this.csharpTreeView); - this.splitContainer1.Panel2.Controls.Add(this.csharpGenerateCodeButton); - this.splitContainer1.Panel2.Controls.Add(this.csharpParseButton); - this.splitContainer1.Size = new System.Drawing.Size(501, 452); - this.splitContainer1.SplitterDistance = 201; - this.splitContainer1.TabIndex = 0; - // - // csharpCodeTextBox + // csDemo1 // - this.csharpCodeTextBox.AcceptsReturn = true; - this.csharpCodeTextBox.AcceptsTab = true; - this.csharpCodeTextBox.Dock = System.Windows.Forms.DockStyle.Fill; - this.csharpCodeTextBox.Font = new System.Drawing.Font("Courier New", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.csharpCodeTextBox.HideSelection = false; - this.csharpCodeTextBox.Location = new System.Drawing.Point(0, 0); - this.csharpCodeTextBox.Multiline = true; - this.csharpCodeTextBox.Name = "csharpCodeTextBox"; - this.csharpCodeTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Both; - this.csharpCodeTextBox.Size = new System.Drawing.Size(501, 201); - this.csharpCodeTextBox.TabIndex = 0; - this.csharpCodeTextBox.Text = "using System;\r\nclass Test\r\n{\r\n public void Main(string[] args)\r\n {\r\n " + - " Console.WriteLine(\"Hello, World\");\r\n }\r\n}"; - this.csharpCodeTextBox.WordWrap = false; - this.csharpCodeTextBox.TextChanged += new System.EventHandler(this.CsharpCodeTextBoxTextChanged); - this.csharpCodeTextBox.KeyDown += new System.Windows.Forms.KeyEventHandler(this.CSharpCodeTextBoxKeyDown); - // - // resolveButton - // - this.resolveButton.Anchor = System.Windows.Forms.AnchorStyles.Top; - this.resolveButton.Location = new System.Drawing.Point(200, 3); - this.resolveButton.Name = "resolveButton"; - this.resolveButton.Size = new System.Drawing.Size(100, 23); - this.resolveButton.TabIndex = 3; - this.resolveButton.Text = "Resolve"; - this.resolveButton.UseVisualStyleBackColor = true; - this.resolveButton.Click += new System.EventHandler(this.ResolveButtonClick); - // - // csharpTreeView - // - this.csharpTreeView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.csharpTreeView.HideSelection = false; - this.csharpTreeView.Location = new System.Drawing.Point(3, 32); - this.csharpTreeView.Name = "csharpTreeView"; - this.csharpTreeView.Size = new System.Drawing.Size(493, 212); - this.csharpTreeView.TabIndex = 2; - this.csharpTreeView.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.CSharpTreeViewAfterSelect); - // - // csharpGenerateCodeButton - // - this.csharpGenerateCodeButton.Anchor = System.Windows.Forms.AnchorStyles.Top; - this.csharpGenerateCodeButton.Location = new System.Drawing.Point(306, 2); - this.csharpGenerateCodeButton.Name = "csharpGenerateCodeButton"; - this.csharpGenerateCodeButton.Size = new System.Drawing.Size(100, 23); - this.csharpGenerateCodeButton.TabIndex = 1; - this.csharpGenerateCodeButton.Text = "Generate"; - this.csharpGenerateCodeButton.UseVisualStyleBackColor = true; - this.csharpGenerateCodeButton.Click += new System.EventHandler(this.CSharpGenerateCodeButtonClick); - // - // csharpParseButton - // - this.csharpParseButton.Anchor = System.Windows.Forms.AnchorStyles.Top; - this.csharpParseButton.Location = new System.Drawing.Point(94, 3); - this.csharpParseButton.Name = "csharpParseButton"; - this.csharpParseButton.Size = new System.Drawing.Size(100, 23); - this.csharpParseButton.TabIndex = 0; - this.csharpParseButton.Text = "Parse"; - this.csharpParseButton.UseVisualStyleBackColor = true; - this.csharpParseButton.Click += new System.EventHandler(this.CSharpParseButtonClick); + this.csDemo1.Dock = System.Windows.Forms.DockStyle.Fill; + this.csDemo1.Location = new System.Drawing.Point(3, 3); + this.csDemo1.Name = "csDemo1"; + this.csDemo1.Size = new System.Drawing.Size(501, 452); + this.csDemo1.TabIndex = 0; // // tabControl1 // @@ -168,17 +83,16 @@ namespace ICSharpCode.NRefactory.Demo this.tabControl1.Size = new System.Drawing.Size(515, 484); this.tabControl1.TabIndex = 0; // - // miniToolStrip + // tabPage2 // - this.miniToolStrip.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.miniToolStrip.AutoSize = false; - this.miniToolStrip.CanOverflow = false; - this.miniToolStrip.Dock = System.Windows.Forms.DockStyle.None; - this.miniToolStrip.GripStyle = System.Windows.Forms.ToolStripGripStyle.Hidden; - this.miniToolStrip.Location = new System.Drawing.Point(13, 3); - this.miniToolStrip.Name = "miniToolStrip"; - this.miniToolStrip.Size = new System.Drawing.Size(16, 25); - this.miniToolStrip.TabIndex = 3; + this.tabPage2.Controls.Add(this.vbDemo1); + this.tabPage2.Location = new System.Drawing.Point(4, 22); + this.tabPage2.Name = "tabPage2"; + this.tabPage2.Padding = new System.Windows.Forms.Padding(3); + this.tabPage2.Size = new System.Drawing.Size(507, 458); + this.tabPage2.TabIndex = 1; + this.tabPage2.Text = "VB"; + this.tabPage2.UseVisualStyleBackColor = true; // // vbDemo1 // @@ -196,25 +110,15 @@ namespace ICSharpCode.NRefactory.Demo this.Controls.Add(this.tabControl1); this.Name = "MainForm"; this.Text = "NRefactory Demo"; - this.tabPage2.ResumeLayout(false); this.tabPage1.ResumeLayout(false); - this.splitContainer1.Panel1.ResumeLayout(false); - this.splitContainer1.Panel1.PerformLayout(); - this.splitContainer1.Panel2.ResumeLayout(false); - ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit(); - this.splitContainer1.ResumeLayout(false); this.tabControl1.ResumeLayout(false); + this.tabPage2.ResumeLayout(false); this.ResumeLayout(false); } private ICSharpCode.NRefactory.Demo.VBDemo vbDemo1; - private System.Windows.Forms.Button resolveButton; - private System.Windows.Forms.ToolStrip miniToolStrip; - private System.Windows.Forms.TreeView csharpTreeView; - private System.Windows.Forms.Button csharpParseButton; - private System.Windows.Forms.Button csharpGenerateCodeButton; - private System.Windows.Forms.TextBox csharpCodeTextBox; - private System.Windows.Forms.SplitContainer splitContainer1; private System.Windows.Forms.TabPage tabPage2; + private ICSharpCode.NRefactory.Demo.CSDemo csDemo1; + private System.Windows.Forms.ToolStrip miniToolStrip; private System.Windows.Forms.TabPage tabPage1; private System.Windows.Forms.TabControl tabControl1; } diff --git a/ICSharpCode.NRefactory.Demo/MainForm.cs b/ICSharpCode.NRefactory.Demo/MainForm.cs index 285428d8f..9633a00f1 100644 --- a/ICSharpCode.NRefactory.Demo/MainForm.cs +++ b/ICSharpCode.NRefactory.Demo/MainForm.cs @@ -29,200 +29,6 @@ namespace ICSharpCode.NRefactory.Demo // The InitializeComponent() call is required for Windows Forms designer support. // InitializeComponent(); - - csharpCodeTextBox.SelectAll(); - CSharpParseButtonClick(null, null); - resolveButton.UseWaitCursor = true; - ThreadPool.QueueUserWorkItem( - delegate { - builtInLibs.Value.ToString(); - BeginInvoke(new Action(delegate { resolveButton.UseWaitCursor = false; })); - }); - } - - CompilationUnit compilationUnit; - - void CSharpParseButtonClick(object sender, EventArgs e) - { - CSharpParser parser = new CSharpParser(); - compilationUnit = parser.Parse(new StringReader(csharpCodeTextBox.Text)); - csharpTreeView.Nodes.Clear(); - foreach (var element in compilationUnit.Children) { - csharpTreeView.Nodes.Add(MakeTreeNode(element)); - } - SelectCurrentNode(csharpTreeView.Nodes); - resolveButton.Enabled = true; - } - - TreeNode MakeTreeNode(AstNode node) - { - TreeNode t = new TreeNode(GetNodeTitle(node)); - t.Tag = node; - foreach (AstNode child in node.Children) { - t.Nodes.Add(MakeTreeNode(child)); - } - return t; - } - - string GetNodeTitle(AstNode node) - { - StringBuilder b = new StringBuilder(); - b.Append(node.Role.ToString()); - b.Append(": "); - b.Append(node.GetType().Name); - bool hasProperties = false; - foreach (PropertyInfo p in node.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance)) { - if (p.Name == "NodeType" || p.Name == "IsNull") - continue; - if (p.PropertyType == typeof(string) || p.PropertyType.IsEnum || p.PropertyType == typeof(bool)) { - if (!hasProperties) { - hasProperties = true; - b.Append(" ("); - } else { - b.Append(", "); - } - b.Append(p.Name); - b.Append(" = "); - try { - object val = p.GetValue(node, null); - b.Append(val != null ? val.ToString() : "**null**"); - } catch (TargetInvocationException ex) { - b.Append("**" + ex.InnerException.GetType().Name + "**"); - } - } - } - if (hasProperties) - b.Append(")"); - return b.ToString(); - } - - bool SelectCurrentNode(TreeNodeCollection c) - { - int selectionStart = csharpCodeTextBox.SelectionStart; - int selectionEnd = selectionStart + csharpCodeTextBox.SelectionLength; - foreach (TreeNode t in c) { - AstNode node = t.Tag as AstNode; - if (node != null - && selectionStart >= GetOffset(csharpCodeTextBox, node.StartLocation) - && selectionEnd <= GetOffset(csharpCodeTextBox, node.EndLocation)) - { - if (selectionStart == selectionEnd - && (selectionStart == GetOffset(csharpCodeTextBox, node.StartLocation) - || selectionStart == GetOffset(csharpCodeTextBox, node.EndLocation))) - { - // caret is on border of this node; don't expand - csharpTreeView.SelectedNode = t; - } else { - t.Expand(); - if (!SelectCurrentNode(t.Nodes)) - csharpTreeView.SelectedNode = t; - } - return true; - } - } - return false; - } - - void CSharpGenerateCodeButtonClick(object sender, EventArgs e) - { - StringWriter w = new StringWriter(); - OutputVisitor output = new OutputVisitor(w, new CSharpFormattingOptions()); - compilationUnit.AcceptVisitor(output, null); - csharpCodeTextBox.Text = w.ToString(); - } - - int GetOffset(TextBox textBox, AstLocation location) - { - return textBox.GetFirstCharIndexFromLine(location.Line - 1) + location.Column - 1; - } - - void CSharpTreeViewAfterSelect(object sender, TreeViewEventArgs e) - { - AstNode node = e.Node.Tag as AstNode; - if (node != null) { - int startOffset = GetOffset(csharpCodeTextBox, node.StartLocation); - int endOffset = GetOffset(csharpCodeTextBox, node.EndLocation); - csharpCodeTextBox.Select(startOffset, endOffset - startOffset); - } - } - - Lazy> builtInLibs = new Lazy>( - delegate { - Assembly[] assemblies = { - typeof(object).Assembly, // mscorlib - typeof(Uri).Assembly, // System.dll - typeof(System.Linq.Enumerable).Assembly, // System.Core.dll -// typeof(System.Xml.XmlDocument).Assembly, // System.Xml.dll -// typeof(System.Drawing.Bitmap).Assembly, // System.Drawing.dll -// typeof(Form).Assembly, // System.Windows.Forms.dll - typeof(ICSharpCode.NRefactory.TypeSystem.IProjectContent).Assembly, - }; - IProjectContent[] projectContents = new IProjectContent[assemblies.Length]; - Stopwatch total = Stopwatch.StartNew(); - Parallel.For( - 0, assemblies.Length, - delegate (int i) { - Stopwatch w = Stopwatch.StartNew(); - CecilLoader loader = new CecilLoader(); - projectContents[i] = loader.LoadAssemblyFile(assemblies[i].Location); - Debug.WriteLine(Path.GetFileName(assemblies[i].Location) + ": " + w.Elapsed); - }); - Debug.WriteLine("Total: " + total.Elapsed); - return projectContents; - }); - - void ResolveButtonClick(object sender, EventArgs e) - { - SimpleProjectContent project = new SimpleProjectContent(); - TypeSystemConvertVisitor convertVisitor = new TypeSystemConvertVisitor(project, "dummy.cs"); - compilationUnit.AcceptVisitor(convertVisitor, null); - project.UpdateProjectContent(null, convertVisitor.ParsedFile.TopLevelTypeDefinitions, null, null); - - List projects = new List(); - projects.Add(project); - projects.AddRange(builtInLibs.Value); - - using (var context = new CompositeTypeResolveContext(projects).Synchronize()) { - CSharpResolver resolver = new CSharpResolver(context); - - IResolveVisitorNavigator navigator = null; - if (csharpTreeView.SelectedNode != null) { - navigator = new NodeListResolveVisitorNavigator(new[] { (AstNode)csharpTreeView.SelectedNode.Tag }); - } - ResolveVisitor visitor = new ResolveVisitor(resolver, convertVisitor.ParsedFile, navigator); - visitor.Scan(compilationUnit); - csharpTreeView.BeginUpdate(); - ShowResolveResultsInTree(csharpTreeView.Nodes, visitor); - csharpTreeView.EndUpdate(); - } - } - - void ShowResolveResultsInTree(TreeNodeCollection c, ResolveVisitor v) - { - foreach (TreeNode t in c) { - AstNode node = t.Tag as AstNode; - if (node != null) { - ResolveResult rr = v.GetResolveResult(node); - if (rr != null) - t.Text = GetNodeTitle(node) + " " + rr.ToString(); - else - t.Text = GetNodeTitle(node); - } - ShowResolveResultsInTree(t.Nodes, v); - } - } - - void CSharpCodeTextBoxKeyDown(object sender, KeyEventArgs e) - { - if (e.Control && e.KeyCode == Keys.A) { - e.Handled = true; - csharpCodeTextBox.SelectAll(); - } - } - - void CsharpCodeTextBoxTextChanged(object sender, EventArgs e) - { - resolveButton.Enabled = false; } } } diff --git a/ICSharpCode.NRefactory.Demo/VBAstView.cs b/ICSharpCode.NRefactory.Demo/VBAstView.cs index 42be32e73..a6e6f58aa 100644 --- a/ICSharpCode.NRefactory.Demo/VBAstView.cs +++ b/ICSharpCode.NRefactory.Demo/VBAstView.cs @@ -39,89 +39,89 @@ namespace ICSharpCode.NRefactory.Demo InitializeComponent(); } - public void DeleteSelectedNode() - { - if (tree.SelectedNode is ElementNode) { - INode element = (tree.SelectedNode as ElementNode).element; - if (tree.SelectedNode.Parent is CollectionNode) { - if (MessageBox.Show("Remove selected node from parent collection?", "Remove node", MessageBoxButtons.YesNo, MessageBoxIcon.Question) - == DialogResult.Yes) - { - IList col = (tree.SelectedNode.Parent as CollectionNode).collection; - col.Remove(element); - (tree.SelectedNode.Parent as CollectionNode).Update(); - } - } else if (tree.SelectedNode.Parent is ElementNode) { - if (MessageBox.Show("Set selected property to null?", "Remove node", MessageBoxButtons.YesNo, MessageBoxIcon.Question) - == DialogResult.Yes) - { - // get parent element - element = (tree.SelectedNode.Parent as ElementNode).element; - string propertyName = (string)tree.SelectedNode.Tag; - element.GetType().GetProperty(propertyName).SetValue(element, null, null); - (tree.SelectedNode.Parent as ElementNode).Update(); - } - } - } else if (tree.SelectedNode is CollectionNode) { - if (MessageBox.Show("Remove all elements from selected collection?", "Clear collection", MessageBoxButtons.YesNo, MessageBoxIcon.Question) - == DialogResult.Yes) - { - IList col = (tree.SelectedNode as CollectionNode).collection; - col.Clear(); - (tree.SelectedNode as CollectionNode).Update(); - } - } - } - - public void EditSelectedNode() - { - TreeNode node = tree.SelectedNode; - while (!(node is ElementNode)) { - if (node == null) { - return; - } - node = node.Parent; - } - INode element = ((ElementNode)node).element; - using (VBEditDialog dlg = new VBEditDialog(element)) { - dlg.ShowDialog(); - } - ((ElementNode)node).Update(); - } - - public void ApplyTransformation(IAstVisitor visitor) - { - if (tree.SelectedNode == tree.Nodes[0]) { - unit.AcceptVisitor(visitor, null); - UpdateTree(); - } else { - string name = visitor.GetType().Name; - ElementNode elementNode = tree.SelectedNode as ElementNode; - CollectionNode collectionNode = tree.SelectedNode as CollectionNode; - if (elementNode != null) { - if (MessageBox.Show(("Apply " + name + " to selected element '" + elementNode.Text + "'?"), - "Apply transformation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) - == DialogResult.Yes) - { - elementNode.element.AcceptVisitor(visitor, null); - elementNode.Update(); - } - } else if (collectionNode != null) { - if (MessageBox.Show(("Apply " + name + " to all elements in selected collection '" + collectionNode.Text + "'?"), - "Apply transformation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) - == DialogResult.Yes) - { - foreach (TreeNode subNode in collectionNode.Nodes) { - if (subNode is ElementNode) { - (subNode as ElementNode).element.AcceptVisitor(visitor, null); - } - } - collectionNode.Update(); - } - } - } - } - +// public void DeleteSelectedNode() +// { +// if (tree.SelectedNode is ElementNode) { +// INode element = (tree.SelectedNode as ElementNode).element; +// if (tree.SelectedNode.Parent is CollectionNode) { +// if (MessageBox.Show("Remove selected node from parent collection?", "Remove node", MessageBoxButtons.YesNo, MessageBoxIcon.Question) +// == DialogResult.Yes) +// { +// IList col = (tree.SelectedNode.Parent as CollectionNode).collection; +// col.Remove(element); +// (tree.SelectedNode.Parent as CollectionNode).Update(); +// } +// } else if (tree.SelectedNode.Parent is ElementNode) { +// if (MessageBox.Show("Set selected property to null?", "Remove node", MessageBoxButtons.YesNo, MessageBoxIcon.Question) +// == DialogResult.Yes) +// { +// // get parent element +// element = (tree.SelectedNode.Parent as ElementNode).element; +// string propertyName = (string)tree.SelectedNode.Tag; +// element.GetType().GetProperty(propertyName).SetValue(element, null, null); +// (tree.SelectedNode.Parent as ElementNode).Update(); +// } +// } +// } else if (tree.SelectedNode is CollectionNode) { +// if (MessageBox.Show("Remove all elements from selected collection?", "Clear collection", MessageBoxButtons.YesNo, MessageBoxIcon.Question) +// == DialogResult.Yes) +// { +// IList col = (tree.SelectedNode as CollectionNode).collection; +// col.Clear(); +// (tree.SelectedNode as CollectionNode).Update(); +// } +// } +// } +// +// public void EditSelectedNode() +// { +// TreeNode node = tree.SelectedNode; +// while (!(node is ElementNode)) { +// if (node == null) { +// return; +// } +// node = node.Parent; +// } +// INode element = ((ElementNode)node).element; +// using (VBEditDialog dlg = new VBEditDialog(element)) { +// dlg.ShowDialog(); +// } +// ((ElementNode)node).Update(); +// } +// +// public void ApplyTransformation(IAstVisitor visitor) +// { +// if (tree.SelectedNode == tree.Nodes[0]) { +// unit.AcceptVisitor(visitor, null); +// UpdateTree(); +// } else { +// string name = visitor.GetType().Name; +// ElementNode elementNode = tree.SelectedNode as ElementNode; +// CollectionNode collectionNode = tree.SelectedNode as CollectionNode; +// if (elementNode != null) { +// if (MessageBox.Show(("Apply " + name + " to selected element '" + elementNode.Text + "'?"), +// "Apply transformation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) +// == DialogResult.Yes) +// { +// elementNode.element.AcceptVisitor(visitor, null); +// elementNode.Update(); +// } +// } else if (collectionNode != null) { +// if (MessageBox.Show(("Apply " + name + " to all elements in selected collection '" + collectionNode.Text + "'?"), +// "Apply transformation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) +// == DialogResult.Yes) +// { +// foreach (TreeNode subNode in collectionNode.Nodes) { +// if (subNode is ElementNode) { +// (subNode as ElementNode).element.AcceptVisitor(visitor, null); +// } +// } +// collectionNode.Update(); +// } +// } +// } +// } +// static TreeNode CreateNode(object child) { if (child == null) { @@ -164,9 +164,9 @@ namespace ICSharpCode.NRefactory.Demo class ElementNode : TreeNode { - internal INode element; + internal AstNode element; - public ElementNode(INode node) + public ElementNode(AstNode node) { this.element = node; Update(); @@ -188,7 +188,7 @@ namespace ICSharpCode.NRefactory.Demo } } - void AddProperties(Type type, INode node) + void AddProperties(Type type, AstNode node) { if (type == typeof(AbstractNode)) return; diff --git a/ICSharpCode.NRefactory.Demo/VBDemo.Designer.cs b/ICSharpCode.NRefactory.Demo/VBDemo.Designer.cs index f4cba1760..48641c669 100644 --- a/ICSharpCode.NRefactory.Demo/VBDemo.Designer.cs +++ b/ICSharpCode.NRefactory.Demo/VBDemo.Designer.cs @@ -33,11 +33,9 @@ namespace ICSharpCode.NRefactory.Demo { this.splitContainer1 = new System.Windows.Forms.SplitContainer(); this.codeView = new System.Windows.Forms.TextBox(); - this.editNodeButton = new System.Windows.Forms.Button(); - this.clearSpecialsButton = new System.Windows.Forms.Button(); - this.syntaxTree = new ICSharpCode.NRefactory.Demo.VBAstView(); this.generateCodeButton = new System.Windows.Forms.Button(); this.parseButton = new System.Windows.Forms.Button(); + this.treeView = new System.Windows.Forms.TreeView(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); this.splitContainer1.Panel1.SuspendLayout(); this.splitContainer1.Panel2.SuspendLayout(); @@ -57,11 +55,9 @@ namespace ICSharpCode.NRefactory.Demo // // splitContainer1.Panel2 // - this.splitContainer1.Panel2.Controls.Add(this.editNodeButton); - this.splitContainer1.Panel2.Controls.Add(this.clearSpecialsButton); - this.splitContainer1.Panel2.Controls.Add(this.syntaxTree); this.splitContainer1.Panel2.Controls.Add(this.generateCodeButton); this.splitContainer1.Panel2.Controls.Add(this.parseButton); + this.splitContainer1.Panel2.Controls.Add(this.treeView); this.splitContainer1.Size = new System.Drawing.Size(462, 391); this.splitContainer1.SplitterDistance = 173; this.splitContainer1.TabIndex = 1; @@ -79,64 +75,41 @@ namespace ICSharpCode.NRefactory.Demo this.codeView.ScrollBars = System.Windows.Forms.ScrollBars.Both; this.codeView.Size = new System.Drawing.Size(462, 173); this.codeView.TabIndex = 0; - this.codeView.Text = "Imports System\r\nClass Test\r\n Public Sub Main(ByVal args As String())\r\n " + - " Console.WriteLine(\"Hello, World\")\r\n End Sub\r\nEnd Class"; + this.codeView.Text = "Option Explicit"; this.codeView.WordWrap = false; // - // editNodeButton - // - this.editNodeButton.Anchor = System.Windows.Forms.AnchorStyles.Top; - this.editNodeButton.Location = new System.Drawing.Point(331, 2); - this.editNodeButton.Name = "editNodeButton"; - this.editNodeButton.Size = new System.Drawing.Size(100, 23); - this.editNodeButton.TabIndex = 4; - this.editNodeButton.Text = "Edit node"; - this.editNodeButton.UseVisualStyleBackColor = true; - this.editNodeButton.Click += new System.EventHandler(this.EditNodeButtonClick); - // - // clearSpecialsButton - // - this.clearSpecialsButton.Anchor = System.Windows.Forms.AnchorStyles.Top; - this.clearSpecialsButton.Location = new System.Drawing.Point(225, 2); - this.clearSpecialsButton.Name = "clearSpecialsButton"; - this.clearSpecialsButton.Size = new System.Drawing.Size(100, 23); - this.clearSpecialsButton.TabIndex = 3; - this.clearSpecialsButton.Text = "Clear 0 specials"; - this.clearSpecialsButton.UseVisualStyleBackColor = true; - this.clearSpecialsButton.Click += new System.EventHandler(this.ClearSpecialsButtonClick); - // - // syntaxTree - // - this.syntaxTree.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.syntaxTree.Location = new System.Drawing.Point(3, 32); - this.syntaxTree.Name = "syntaxTree"; - this.syntaxTree.Size = new System.Drawing.Size(459, 182); - this.syntaxTree.TabIndex = 2; - this.syntaxTree.Unit = null; - // // generateCodeButton // this.generateCodeButton.Anchor = System.Windows.Forms.AnchorStyles.Top; - this.generateCodeButton.Location = new System.Drawing.Point(119, 2); + this.generateCodeButton.Location = new System.Drawing.Point(225, 2); this.generateCodeButton.Name = "generateCodeButton"; this.generateCodeButton.Size = new System.Drawing.Size(100, 23); this.generateCodeButton.TabIndex = 1; this.generateCodeButton.Text = "Generate"; this.generateCodeButton.UseVisualStyleBackColor = true; - this.generateCodeButton.Click += new System.EventHandler(this.GenerateCodeButtonClick); + this.generateCodeButton.Click += new System.EventHandler(this.CSharpGenerateCodeButtonClick); // // parseButton // this.parseButton.Anchor = System.Windows.Forms.AnchorStyles.Top; - this.parseButton.Location = new System.Drawing.Point(13, 2); + this.parseButton.Location = new System.Drawing.Point(119, 2); this.parseButton.Name = "parseButton"; this.parseButton.Size = new System.Drawing.Size(100, 23); this.parseButton.TabIndex = 0; this.parseButton.Text = "Parse"; this.parseButton.UseVisualStyleBackColor = true; - this.parseButton.Click += new System.EventHandler(this.ParseButtonClick); + this.parseButton.Click += new System.EventHandler(this.CSharpParseButtonClick); + // + // treeView + // + this.treeView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.treeView.Location = new System.Drawing.Point(3, 31); + this.treeView.Name = "treeView"; + this.treeView.Size = new System.Drawing.Size(459, 180); + this.treeView.TabIndex = 0; + this.treeView.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.CSharpTreeViewAfterSelect); // // VBDemo // @@ -152,10 +125,8 @@ namespace ICSharpCode.NRefactory.Demo this.splitContainer1.ResumeLayout(false); this.ResumeLayout(false); } - private System.Windows.Forms.Button clearSpecialsButton; - private System.Windows.Forms.Button editNodeButton; - private ICSharpCode.NRefactory.Demo.VBAstView syntaxTree; private System.Windows.Forms.TextBox codeView; + private System.Windows.Forms.TreeView treeView; private System.Windows.Forms.Button generateCodeButton; private System.Windows.Forms.Button parseButton; private System.Windows.Forms.SplitContainer splitContainer1; diff --git a/ICSharpCode.NRefactory.Demo/VBDemo.cs b/ICSharpCode.NRefactory.Demo/VBDemo.cs index 387921259..beb3308c1 100644 --- a/ICSharpCode.NRefactory.Demo/VBDemo.cs +++ b/ICSharpCode.NRefactory.Demo/VBDemo.cs @@ -7,10 +7,13 @@ using System.ComponentModel; using System.Drawing; using System.IO; using System.Linq; +using System.Reflection; +using System.Text; using System.Windows.Forms; + using ICSharpCode.NRefactory.VB; +using ICSharpCode.NRefactory.VB.Ast; using ICSharpCode.NRefactory.VB.Parser; -using ICSharpCode.NRefactory.VB.PrettyPrinter; namespace ICSharpCode.NRefactory.Demo { @@ -25,54 +28,113 @@ namespace ICSharpCode.NRefactory.Demo // The InitializeComponent() call is required for Windows Forms designer support. // InitializeComponent(); - ParseButtonClick(null, null); } - IList savedSpecials; + CompilationUnit compilationUnit; + + void CSharpParseButtonClick(object sender, EventArgs e) + { + var parser = new VBParser(); + compilationUnit = parser.Parse(new StringReader(codeView.Text)); + if (parser.HasErrors) + MessageBox.Show(parser.Errors.ErrorOutput); + treeView.Nodes.Clear(); + foreach (var element in compilationUnit.Children) { + treeView.Nodes.Add(MakeTreeNode(element)); + } + SelectCurrentNode(treeView.Nodes); + } + + TreeNode MakeTreeNode(AstNode node) + { + TreeNode t = new TreeNode(GetNodeTitle(node)); + t.Tag = node; + foreach (AstNode child in node.Children) { + t.Nodes.Add(MakeTreeNode(child)); + } + return t; + } - void ParseButtonClick(object sender, EventArgs e) + string GetNodeTitle(AstNode node) { - using (VBParser parser = new VBParser(new VBLexer(new StringReader(codeView.Text)))) { - parser.Parse(); - // this allows retrieving comments, preprocessor directives, etc. (stuff that isn't part of the syntax) - SetSpecials(parser.Lexer.SpecialTracker.RetrieveSpecials()); - // this retrieves the root node of the result DOM - if (parser.Errors.Count > 0) { - MessageBox.Show(parser.Errors.ErrorOutput); + StringBuilder b = new StringBuilder(); + b.Append(node.Role.ToString()); + b.Append(": "); + b.Append(node.GetType().Name); + bool hasProperties = false; + foreach (PropertyInfo p in node.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance)) { + if (p.Name == "NodeType" || p.Name == "IsNull") + continue; + if (p.PropertyType == typeof(string) || p.PropertyType.IsEnum || p.PropertyType == typeof(bool)) { + if (!hasProperties) { + hasProperties = true; + b.Append(" ("); + } else { + b.Append(", "); + } + b.Append(p.Name); + b.Append(" = "); + try { + object val = p.GetValue(node, null); + b.Append(val != null ? val.ToString() : "**null**"); + } catch (TargetInvocationException ex) { + b.Append("**" + ex.InnerException.GetType().Name + "**"); + } } - syntaxTree.Unit = parser.CompilationUnit; } + if (hasProperties) + b.Append(")"); + return b.ToString(); } - void GenerateCodeButtonClick(object sender, EventArgs e) + bool SelectCurrentNode(TreeNodeCollection c) { - if (syntaxTree.Unit != null) { - VBNetOutputVisitor visitor = new VBNetOutputVisitor(); - // re-insert the comments we saved from the parser into the output - using (SpecialNodesInserter.Install(savedSpecials, visitor)) { - syntaxTree.Unit.AcceptVisitor(visitor, null); + int selectionStart = codeView.SelectionStart; + int selectionEnd = selectionStart + codeView.SelectionLength; + foreach (TreeNode t in c) { + AstNode node = t.Tag as AstNode; + if (node != null + && selectionStart >= GetOffset(codeView, node.StartLocation) + && selectionEnd <= GetOffset(codeView, node.EndLocation)) + { + if (selectionStart == selectionEnd + && (selectionStart == GetOffset(codeView, node.StartLocation) + || selectionStart == GetOffset(codeView, node.EndLocation))) + { + // caret is on border of this node; don't expand + treeView.SelectedNode = t; + } else { + t.Expand(); + if (!SelectCurrentNode(t.Nodes)) + treeView.SelectedNode = t; + } + return true; } - codeView.Text = visitor.Text.Replace("\t", " "); } + return false; } - void ClearSpecialsButtonClick(object sender, EventArgs e) + void CSharpGenerateCodeButtonClick(object sender, EventArgs e) { - SetSpecials(new ISpecial[0]); + StringWriter w = new StringWriter(); + OutputVisitor output = new OutputVisitor(w, new VBFormattingOptions()); + compilationUnit.AcceptVisitor(output, null); + codeView.Text = w.ToString(); } - void EditNodeButtonClick(object sender, EventArgs e) + int GetOffset(TextBox textBox, AstLocation location) { - syntaxTree.EditSelectedNode(); + return textBox.GetFirstCharIndexFromLine(location.Line - 1) + location.Column - 1; } - void SetSpecials(IList specials) + void CSharpTreeViewAfterSelect(object sender, TreeViewEventArgs e) { - savedSpecials = specials; - if (specials.Count == 1) - clearSpecialsButton.Text = "Clear 1 special"; - else - clearSpecialsButton.Text = "Clear " + specials.Count + " specials"; + AstNode node = e.Node.Tag as AstNode; + if (node != null) { + int startOffset = GetOffset(codeView, node.StartLocation); + int endOffset = GetOffset(codeView, node.EndLocation); + codeView.Select(startOffset, endOffset - startOffset); + } } } } diff --git a/ICSharpCode.NRefactory.Tests/CSharp/Resolver/ConditionalOperatorTests.cs b/ICSharpCode.NRefactory.Tests/CSharp/Resolver/ConditionalOperatorTests.cs new file mode 100644 index 000000000..d1178757e --- /dev/null +++ b/ICSharpCode.NRefactory.Tests/CSharp/Resolver/ConditionalOperatorTests.cs @@ -0,0 +1,85 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) + +using System; +using System.Collections.Generic; +using NUnit.Framework; + +namespace ICSharpCode.NRefactory.CSharp.Resolver +{ + // assign short name to the fake reflection type + using dynamic = ICSharpCode.NRefactory.TypeSystem.ReflectionHelper.Dynamic; + + [TestFixture] + public class ConditionalOperatorTests : ResolverTestBase + { + [Test] + public void PickMoreGeneralOfTheTypes() + { + AssertType(typeof(object), resolver.ResolveConditional( + MakeResult(typeof(bool)), MakeResult(typeof(string)), MakeResult(typeof(object)))); + AssertType(typeof(long), resolver.ResolveConditional( + MakeResult(typeof(bool)), MakeResult(typeof(int)), MakeResult(typeof(long)))); + } + + [Test] + public void Null() + { + AssertType(typeof(string), resolver.ResolveConditional( + MakeResult(typeof(bool)), MakeResult(typeof(string)), MakeConstant(null))); + AssertType(typeof(string), resolver.ResolveConditional( + MakeResult(typeof(bool)), MakeConstant(null), MakeResult(typeof(string)))); + } + + [Test] + public void DynamicInArguments() + { + AssertType(typeof(dynamic), resolver.ResolveConditional( + MakeResult(typeof(bool)), MakeResult(typeof(dynamic)), MakeResult(typeof(double)))); + + AssertType(typeof(dynamic), resolver.ResolveConditional( + MakeResult(typeof(bool)), MakeResult(typeof(double)), MakeResult(typeof(dynamic)))); + } + + [Test] + public void DynamicInCondition() + { + AssertType(typeof(double), resolver.ResolveConditional( + MakeResult(typeof(dynamic)), MakeResult(typeof(float)), MakeResult(typeof(double)))); + } + + [Test] + public void AllDynamic() + { + AssertType(typeof(dynamic), resolver.ResolveConditional( + MakeResult(typeof(dynamic)), MakeResult(typeof(dynamic)), MakeResult(typeof(dynamic)))); + } + + [Test] + public void ListOfDynamicAndListOfObject() + { + AssertError(typeof(List), resolver.ResolveConditional( + MakeResult(typeof(bool)), MakeResult(typeof(List)), MakeResult(typeof(List)))); + + AssertError(typeof(List), resolver.ResolveConditional( + MakeResult(typeof(bool)), MakeResult(typeof(List)), MakeResult(typeof(List)))); + } + + [Test] + public void Constant() + { + AssertConstant(1L, resolver.ResolveConditional( + MakeConstant(true), MakeConstant(1), MakeConstant(2L))); + + AssertConstant(2L, resolver.ResolveConditional( + MakeConstant(false), MakeConstant(1), MakeConstant(2L))); + } + + [Test] + public void NotConstantIfFalsePortionNotConstant() + { + AssertType(typeof(long), resolver.ResolveConditional( + MakeConstant(true), MakeConstant(1), MakeResult(typeof(long)))); + } + } +} diff --git a/ICSharpCode.NRefactory.Tests/ICSharpCode.NRefactory.Tests.csproj b/ICSharpCode.NRefactory.Tests/ICSharpCode.NRefactory.Tests.csproj index 3c1e05fb0..cebee2aa5 100644 --- a/ICSharpCode.NRefactory.Tests/ICSharpCode.NRefactory.Tests.csproj +++ b/ICSharpCode.NRefactory.Tests/ICSharpCode.NRefactory.Tests.csproj @@ -1,4 +1,4 @@ - + {63D3B27A-D966-4902-90B3-30290E1692F1} @@ -120,6 +120,7 @@ + @@ -143,6 +144,7 @@ + diff --git a/ICSharpCode.NRefactory.Tests/TypeSystem/StructureTests.cs b/ICSharpCode.NRefactory.Tests/TypeSystem/StructureTests.cs new file mode 100644 index 000000000..f4931bc33 --- /dev/null +++ b/ICSharpCode.NRefactory.Tests/TypeSystem/StructureTests.cs @@ -0,0 +1,22 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) + +using System; +using NUnit.Framework; + +namespace ICSharpCode.NRefactory.TypeSystem +{ + [TestFixture] + public class StructureTests + { + [Test] + public void ClasesThatSupportInterningAreSealed() + { + foreach (Type type in typeof(ISupportsInterning).Assembly.GetTypes()) { + if (typeof(ISupportsInterning).IsAssignableFrom(type) && !type.IsInterface) { + Assert.IsTrue(type.IsSealed, type.FullName); + } + } + } + } +} diff --git a/ICSharpCode.NRefactory.Tests/TypeSystem/TestInterningProvider.cs b/ICSharpCode.NRefactory.Tests/TypeSystem/TestInterningProvider.cs index 8df59cf46..e3ebea8fc 100644 --- a/ICSharpCode.NRefactory.Tests/TypeSystem/TestInterningProvider.cs +++ b/ICSharpCode.NRefactory.Tests/TypeSystem/TestInterningProvider.cs @@ -15,7 +15,7 @@ using NUnit.Framework; namespace ICSharpCode.NRefactory.TypeSystem { - //* Not a real unit test + /* Not a real unit test [TestFixture] public class TestInterningProvider { diff --git a/ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.cs b/ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.cs index 6432046df..bd2a786a1 100644 --- a/ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.cs +++ b/ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.cs @@ -114,16 +114,17 @@ namespace ICSharpCode.NRefactory.TypeSystem { var attributes = testCasePC.AssemblyAttributes; var typeTest = attributes.First(a => a.AttributeType.Resolve(ctx).FullName == typeof(TypeTestAttribute).FullName); - Assert.AreEqual(3, typeTest.PositionalArguments.Count); + var posArgs = typeTest.GetPositionalArguments(ctx); + Assert.AreEqual(3, posArgs.Count); // first argument is (int)42 - Assert.AreEqual(42, (int)typeTest.PositionalArguments[0].GetValue(ctx)); + Assert.AreEqual(42, (int)posArgs[0].GetValue(ctx)); // second argument is typeof(System.Action<>) - IType rt = (IType)typeTest.PositionalArguments[1].GetValue(ctx); + IType rt = (IType)posArgs[1].GetValue(ctx); Assert.IsFalse(rt is ParameterizedType); // rt must not be constructed - it's just an unbound type Assert.AreEqual("System.Action", rt.FullName); Assert.AreEqual(1, rt.TypeParameterCount); // third argument is typeof(IDictionary>) - ParameterizedType crt = (ParameterizedType)typeTest.PositionalArguments[2].GetValue(ctx); + ParameterizedType crt = (ParameterizedType)posArgs[2].GetValue(ctx); Assert.AreEqual("System.Collections.Generic.IDictionary", crt.FullName); Assert.AreEqual("System.String", crt.TypeArguments[0].FullName); // ? for NUnit.TestAttribute (because that assembly isn't in ctx) @@ -282,16 +283,17 @@ namespace ICSharpCode.NRefactory.TypeSystem { IAttribute attr = ctx.GetClass(typeof(ExplicitFieldLayoutStruct)).Attributes.Single(); Assert.AreEqual("System.Runtime.InteropServices.StructLayoutAttribute", attr.AttributeType.Resolve(ctx).FullName); - IConstantValue arg1 = attr.PositionalArguments.Single(); + IConstantValue arg1 = attr.GetPositionalArguments(ctx).Single(); Assert.AreEqual("System.Runtime.InteropServices.LayoutKind", arg1.GetValueType(ctx).FullName); Assert.AreEqual((int)LayoutKind.Explicit, arg1.GetValue(ctx)); - var arg2 = attr.NamedArguments[0]; + var namedArgs = attr.GetNamedArguments(ctx); + var arg2 = namedArgs[0]; Assert.AreEqual("CharSet", arg2.Key); Assert.AreEqual("System.Runtime.InteropServices.CharSet", arg2.Value.GetValueType(ctx).FullName); Assert.AreEqual((int)CharSet.Unicode, arg2.Value.GetValue(ctx)); - var arg3 = attr.NamedArguments[1]; + var arg3 = namedArgs[1]; Assert.AreEqual("Pack", arg3.Key); Assert.AreEqual("System.Int32", arg3.Value.GetValueType(ctx).FullName); Assert.AreEqual(8, arg3.Value.GetValue(ctx)); @@ -302,13 +304,13 @@ namespace ICSharpCode.NRefactory.TypeSystem { IField field = ctx.GetClass(typeof(ExplicitFieldLayoutStruct)).Fields.Single(f => f.Name == "Field0"); Assert.AreEqual("System.Runtime.InteropServices.FieldOffsetAttribute", field.Attributes.Single().AttributeType.Resolve(ctx).FullName); - IConstantValue arg = field.Attributes.Single().PositionalArguments.Single(); + IConstantValue arg = field.Attributes.Single().GetPositionalArguments(ctx).Single(); Assert.AreEqual("System.Int32", arg.GetValueType(ctx).FullName); Assert.AreEqual(0, arg.GetValue(ctx)); field = ctx.GetClass(typeof(ExplicitFieldLayoutStruct)).Fields.Single(f => f.Name == "Field100"); Assert.AreEqual("System.Runtime.InteropServices.FieldOffsetAttribute", field.Attributes.Single().AttributeType.Resolve(ctx).FullName); - arg = field.Attributes.Single().PositionalArguments.Single(); + arg = field.Attributes.Single().GetPositionalArguments(ctx).Single(); Assert.AreEqual("System.Int32", arg.GetValueType(ctx).FullName); Assert.AreEqual(100, arg.GetValue(ctx)); } @@ -319,8 +321,8 @@ namespace ICSharpCode.NRefactory.TypeSystem IMethod method = ctx.GetClass(typeof(NonCustomAttributes)).Methods.Single(m => m.Name == "DllMethod"); IAttribute dllImport = method.Attributes.Single(); Assert.AreEqual("System.Runtime.InteropServices.DllImportAttribute", dllImport.AttributeType.Resolve(ctx).FullName); - Assert.AreEqual("unmanaged.dll", dllImport.PositionalArguments[0].GetValue(ctx)); - Assert.AreEqual((int)CharSet.Unicode, dllImport.NamedArguments.Single().Value.GetValue(ctx)); + Assert.AreEqual("unmanaged.dll", dllImport.GetPositionalArguments(ctx)[0].GetValue(ctx)); + Assert.AreEqual((int)CharSet.Unicode, dllImport.GetNamedArguments(ctx).Single().Value.GetValue(ctx)); } [Test] @@ -339,7 +341,7 @@ namespace ICSharpCode.NRefactory.TypeSystem { IMethod method = ctx.GetClass(typeof(NonCustomAttributes)).Methods.Single(m => m.Name == "DllMethod"); IAttribute marshalAs = method.ReturnTypeAttributes.Single(); - Assert.AreEqual((int)UnmanagedType.Bool, marshalAs.PositionalArguments.Single().GetValue(ctx)); + Assert.AreEqual((int)UnmanagedType.Bool, marshalAs.GetPositionalArguments(ctx).Single().GetValue(ctx)); } [Test] diff --git a/ICSharpCode.NRefactory.VB.Tests/General/UnitTest.cs b/ICSharpCode.NRefactory.VB.Tests/General/UnitTest.cs index 2db6aa293..def7d7d0f 100644 --- a/ICSharpCode.NRefactory.VB.Tests/General/UnitTest.cs +++ b/ICSharpCode.NRefactory.VB.Tests/General/UnitTest.cs @@ -6,44 +6,43 @@ using System.Reflection; using NUnit.Framework; using ICSharpCode.NRefactory.VB.Ast; using ICSharpCode.NRefactory.VB.Parser; -using ICSharpCode.NRefactory.VB.Visitors; namespace ICSharpCode.NRefactory.VB.Tests { [TestFixture] public class StructuralTest { - [Test] - public void TestToStringMethods() - { - Type[] allTypes = typeof(INode).Assembly.GetTypes(); - - foreach (Type type in allTypes) { - if (type.IsClass && !type.IsAbstract && !type.IsNested && type.GetInterface(typeof(INode).FullName) != null) { - MethodInfo methodInfo = type.GetMethod("ToString", BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public); - Assert.IsNotNull(methodInfo, "ToString() not found in " + type.FullName); - } - } - } - - [Test] - public void TestUnitTests() - { - Type[] allTypes = typeof(StructuralTest).Assembly.GetTypes(); - - foreach (Type type in allTypes) { - if (type.GetCustomAttributes(typeof(TestFixtureAttribute), true).Length > 0) { - foreach (MethodInfo m in type.GetMethods()) { - if (m.IsPublic && m.ReturnType == typeof(void) && m.GetParameters().Length == 0) { - if (m.GetCustomAttributes(typeof(TestAttribute), true).Length == 0) { - Assert.Fail(type.Name + "." + m.Name + " should have the [Test] attribute!"); - } - } - } - } - } - } - +// [Test] +// public void TestToStringMethods() +// { +// Type[] allTypes = typeof(INode).Assembly.GetTypes(); +// +// foreach (Type type in allTypes) { +// if (type.IsClass && !type.IsAbstract && !type.IsNested && type.GetInterface(typeof(INode).FullName) != null) { +// MethodInfo methodInfo = type.GetMethod("ToString", BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public); +// Assert.IsNotNull(methodInfo, "ToString() not found in " + type.FullName); +// } +// } +// } +// +// [Test] +// public void TestUnitTests() +// { +// Type[] allTypes = typeof(StructuralTest).Assembly.GetTypes(); +// +// foreach (Type type in allTypes) { +// if (type.GetCustomAttributes(typeof(TestFixtureAttribute), true).Length > 0) { +// foreach (MethodInfo m in type.GetMethods()) { +// if (m.IsPublic && m.ReturnType == typeof(void) && m.GetParameters().Length == 0) { +// if (m.GetCustomAttributes(typeof(TestAttribute), true).Length == 0) { +// Assert.Fail(type.Name + "." + m.Name + " should have the [Test] attribute!"); +// } +// } +// } +// } +// } +// } +// // [Test] // public void TestAcceptVisitorMethods() // { @@ -56,48 +55,48 @@ namespace ICSharpCode.NRefactory.VB.Tests // } // } // } - - [Test] - public void TestIAstVisitor() - { - Type[] allTypes = typeof(AbstractNode).Assembly.GetTypes(); - Type visitor = typeof(IAstVisitor); - - foreach (Type type in allTypes) { - if (type.IsClass && !type.IsAbstract && !type.IsNested && type.GetInterface(typeof(INode).FullName) != null && !type.Name.StartsWith("Null")) { - MethodInfo methodInfo = visitor.GetMethod("Visit" + type.Name, BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.ExactBinding, null, new Type[] {type, typeof(object)}, null); - Assert.IsNotNull(methodInfo, "Visit with parameter " + type.FullName + " not found"); - Assert.AreEqual(2, methodInfo.GetParameters().Length); - ParameterInfo first = methodInfo.GetParameters()[0]; - Assert.AreEqual(Char.ToLower(first.ParameterType.Name[0]) + first.ParameterType.Name.Substring(1), first.Name); - - ParameterInfo second = methodInfo.GetParameters()[1]; - Assert.AreEqual(typeof(System.Object), second.ParameterType); - Assert.AreEqual("data", second.Name); - } - } - } - - [Test] - public void TestAbstractAstVisitorVisitor() - { - Type[] allTypes = typeof(AbstractNode).Assembly.GetTypes(); - Type visitor = typeof(AbstractAstVisitor); - - foreach (Type type in allTypes) { - if (type.IsClass && !type.IsAbstract && !type.IsNested && type.GetInterface(typeof(INode).FullName) != null && !type.Name.StartsWith("Null")) { - MethodInfo methodInfo = visitor.GetMethod("Visit" + type.Name, BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.ExactBinding, null, new Type[] {type, typeof(object)}, null); - Assert.IsNotNull(methodInfo, "Visit with parameter " + type.FullName + " not found"); - - Assert.AreEqual(2, methodInfo.GetParameters().Length); - ParameterInfo first = methodInfo.GetParameters()[0]; - Assert.AreEqual(Char.ToLower(first.ParameterType.Name[0]) + first.ParameterType.Name.Substring(1), first.Name); - - ParameterInfo second = methodInfo.GetParameters()[1]; - Assert.AreEqual(typeof(System.Object), second.ParameterType); - Assert.AreEqual("data", second.Name); - } - } - } +// +// [Test] +// public void TestIAstVisitor() +// { +// Type[] allTypes = typeof(AbstractNode).Assembly.GetTypes(); +// Type visitor = typeof(IAstVisitor); +// +// foreach (Type type in allTypes) { +// if (type.IsClass && !type.IsAbstract && !type.IsNested && type.GetInterface(typeof(INode).FullName) != null && !type.Name.StartsWith("Null")) { +// MethodInfo methodInfo = visitor.GetMethod("Visit" + type.Name, BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.ExactBinding, null, new Type[] {type, typeof(object)}, null); +// Assert.IsNotNull(methodInfo, "Visit with parameter " + type.FullName + " not found"); +// Assert.AreEqual(2, methodInfo.GetParameters().Length); +// ParameterInfo first = methodInfo.GetParameters()[0]; +// Assert.AreEqual(Char.ToLower(first.ParameterType.Name[0]) + first.ParameterType.Name.Substring(1), first.Name); +// +// ParameterInfo second = methodInfo.GetParameters()[1]; +// Assert.AreEqual(typeof(System.Object), second.ParameterType); +// Assert.AreEqual("data", second.Name); +// } +// } +// } +// +// [Test] +// public void TestAbstractAstVisitorVisitor() +// { +// Type[] allTypes = typeof(AbstractNode).Assembly.GetTypes(); +// Type visitor = typeof(AbstractAstVisitor); +// +// foreach (Type type in allTypes) { +// if (type.IsClass && !type.IsAbstract && !type.IsNested && type.GetInterface(typeof(INode).FullName) != null && !type.Name.StartsWith("Null")) { +// MethodInfo methodInfo = visitor.GetMethod("Visit" + type.Name, BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.ExactBinding, null, new Type[] {type, typeof(object)}, null); +// Assert.IsNotNull(methodInfo, "Visit with parameter " + type.FullName + " not found"); +// +// Assert.AreEqual(2, methodInfo.GetParameters().Length); +// ParameterInfo first = methodInfo.GetParameters()[0]; +// Assert.AreEqual(Char.ToLower(first.ParameterType.Name[0]) + first.ParameterType.Name.Substring(1), first.Name); +// +// ParameterInfo second = methodInfo.GetParameters()[1]; +// Assert.AreEqual(typeof(System.Object), second.ParameterType); +// Assert.AreEqual("data", second.Name); +// } +// } +// } } } diff --git a/ICSharpCode.NRefactory.VB.Tests/ICSharpCode.NRefactory.VB.Tests.csproj b/ICSharpCode.NRefactory.VB.Tests/ICSharpCode.NRefactory.VB.Tests.csproj index fef832cb3..f0da0835c 100644 --- a/ICSharpCode.NRefactory.VB.Tests/ICSharpCode.NRefactory.VB.Tests.csproj +++ b/ICSharpCode.NRefactory.VB.Tests/ICSharpCode.NRefactory.VB.Tests.csproj @@ -66,90 +66,23 @@ - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + {7B82B671-419F-45F4-B778-D9286F996EFA} ICSharpCode.NRefactory.VB + + {3B2A5653-EC97-4001-BB9B-D90F1AF2C371} + ICSharpCode.NRefactory + \ No newline at end of file diff --git a/ICSharpCode.NRefactory.VB.Tests/Lexer/CustomLexerTests.cs b/ICSharpCode.NRefactory.VB.Tests/Lexer/CustomLexerTests.cs index ce697d143..c37cf1b02 100644 --- a/ICSharpCode.NRefactory.VB.Tests/Lexer/CustomLexerTests.cs +++ b/ICSharpCode.NRefactory.VB.Tests/Lexer/CustomLexerTests.cs @@ -13,7 +13,7 @@ namespace ICSharpCode.NRefactory.VB.Tests.Lexer { VBLexer GenerateLexer(StringReader sr) { - return ParserFactory.CreateLexer(sr); + return new VBLexer(sr); } [Test] diff --git a/ICSharpCode.NRefactory.VB.Tests/Lexer/ImplicitLineContinuationTests.cs b/ICSharpCode.NRefactory.VB.Tests/Lexer/ImplicitLineContinuationTests.cs index 0c24c847f..8e5bcdb71 100644 --- a/ICSharpCode.NRefactory.VB.Tests/Lexer/ImplicitLineContinuationTests.cs +++ b/ICSharpCode.NRefactory.VB.Tests/Lexer/ImplicitLineContinuationTests.cs @@ -213,7 +213,7 @@ End Class"; #region Helpers VBLexer GenerateLexer(StringReader sr) { - return ParserFactory.CreateLexer(sr); + return new VBLexer(sr); } void CheckTokens(VBLexer lexer, params int[] tokens) diff --git a/ICSharpCode.NRefactory.VB.Tests/Lexer/LexerContextTests.cs b/ICSharpCode.NRefactory.VB.Tests/Lexer/LexerContextTests.cs index 174a96343..f04ab8469 100644 --- a/ICSharpCode.NRefactory.VB.Tests/Lexer/LexerContextTests.cs +++ b/ICSharpCode.NRefactory.VB.Tests/Lexer/LexerContextTests.cs @@ -556,7 +556,7 @@ exit Global void RunTest(string code, string expectedOutput) { ExpressionFinder p = new ExpressionFinder(); - VBLexer lexer = ParserFactory.CreateLexer(new StringReader(code)); + VBLexer lexer = new VBLexer(new StringReader(code)); Token t; do { diff --git a/ICSharpCode.NRefactory.VB.Tests/Lexer/LexerPositionTests.cs b/ICSharpCode.NRefactory.VB.Tests/Lexer/LexerPositionTests.cs index f227c5c8a..553ba27a6 100644 --- a/ICSharpCode.NRefactory.VB.Tests/Lexer/LexerPositionTests.cs +++ b/ICSharpCode.NRefactory.VB.Tests/Lexer/LexerPositionTests.cs @@ -13,7 +13,7 @@ namespace ICSharpCode.NRefactory.VB.Tests.Lexer { VBLexer GenerateLexer(string s) { - return ParserFactory.CreateLexer(new StringReader(s)); + return new VBLexer(new StringReader(s)); } [Test] @@ -22,16 +22,16 @@ namespace ICSharpCode.NRefactory.VB.Tests.Lexer VBLexer l = GenerateLexer("public\nstatic"); Token t = l.NextToken(); Assert.AreEqual(Tokens.Public, t.Kind); - Assert.AreEqual(new Location(1, 1), t.Location); - Assert.AreEqual(new Location(7, 1), t.EndLocation); + Assert.AreEqual(new AstLocation(1, 1), t.Location); + Assert.AreEqual(new AstLocation(7, 1), t.EndLocation); t = l.NextToken(); Assert.AreEqual(Tokens.EOL, t.Kind); - Assert.AreEqual(new Location(7, 1), t.Location); - Assert.AreEqual(new Location(1, 2), t.EndLocation); + Assert.AreEqual(new AstLocation(7, 1), t.Location); + Assert.AreEqual(new AstLocation(1, 2), t.EndLocation); t = l.NextToken(); Assert.AreEqual(Tokens.Static, t.Kind); - Assert.AreEqual(new Location(1, 2), t.Location); - Assert.AreEqual(new Location(7, 2), t.EndLocation); + Assert.AreEqual(new AstLocation(1, 2), t.Location); + Assert.AreEqual(new AstLocation(7, 2), t.EndLocation); } [Test] @@ -40,16 +40,16 @@ namespace ICSharpCode.NRefactory.VB.Tests.Lexer VBLexer l = GenerateLexer("public\r\nstatic"); Token t = l.NextToken(); Assert.AreEqual(Tokens.Public, t.Kind); - Assert.AreEqual(new Location(1, 1), t.Location); - Assert.AreEqual(new Location(7, 1), t.EndLocation); + Assert.AreEqual(new AstLocation(1, 1), t.Location); + Assert.AreEqual(new AstLocation(7, 1), t.EndLocation); t = l.NextToken(); Assert.AreEqual(Tokens.EOL, t.Kind); - Assert.AreEqual(new Location(7, 1), t.Location); - Assert.AreEqual(new Location(1, 2), t.EndLocation); + Assert.AreEqual(new AstLocation(7, 1), t.Location); + Assert.AreEqual(new AstLocation(1, 2), t.EndLocation); t = l.NextToken(); Assert.AreEqual(Tokens.Static, t.Kind); - Assert.AreEqual(new Location(1, 2), t.Location); - Assert.AreEqual(new Location(7, 2), t.EndLocation); + Assert.AreEqual(new AstLocation(1, 2), t.Location); + Assert.AreEqual(new AstLocation(7, 2), t.EndLocation); } [Test] @@ -59,13 +59,13 @@ namespace ICSharpCode.NRefactory.VB.Tests.Lexer l.NextToken(); // public Token t = l.NextToken(); Assert.AreEqual(Tokens.EOL, t.Kind); - Assert.AreEqual(new Location(7, 1), t.Location); - Assert.AreEqual(new Location(7, 1), t.EndLocation); + Assert.AreEqual(new AstLocation(7, 1), t.Location); + Assert.AreEqual(new AstLocation(7, 1), t.EndLocation); t = l.NextToken(); Assert.AreEqual(Tokens.EOF, t.Kind); - Assert.AreEqual(new Location(7, 1), t.Location); - Assert.AreEqual(new Location(7, 1), t.EndLocation); + Assert.AreEqual(new AstLocation(7, 1), t.Location); + Assert.AreEqual(new AstLocation(7, 1), t.EndLocation); } [Test] @@ -75,13 +75,13 @@ namespace ICSharpCode.NRefactory.VB.Tests.Lexer l.NextToken(); // public Token t = l.NextToken(); Assert.AreEqual(Tokens.EOL, t.Kind); - Assert.AreEqual(new Location(2, 2), t.Location); - Assert.AreEqual(new Location(2, 2), t.EndLocation); + Assert.AreEqual(new AstLocation(2, 2), t.Location); + Assert.AreEqual(new AstLocation(2, 2), t.EndLocation); t = l.NextToken(); Assert.AreEqual(Tokens.EOF, t.Kind); - Assert.AreEqual(new Location(2, 2), t.Location); - Assert.AreEqual(new Location(2, 2), t.EndLocation); + Assert.AreEqual(new AstLocation(2, 2), t.Location); + Assert.AreEqual(new AstLocation(2, 2), t.EndLocation); } } } diff --git a/ICSharpCode.NRefactory.VB.Tests/Lexer/LexerTests.cs b/ICSharpCode.NRefactory.VB.Tests/Lexer/LexerTests.cs index b181f4851..9b2ec8386 100644 --- a/ICSharpCode.NRefactory.VB.Tests/Lexer/LexerTests.cs +++ b/ICSharpCode.NRefactory.VB.Tests/Lexer/LexerTests.cs @@ -13,7 +13,7 @@ namespace ICSharpCode.NRefactory.VB.Tests.Lexer { VBLexer GenerateLexer(StringReader sr) { - return ParserFactory.CreateLexer(sr); + return new VBLexer(sr); } [Test] diff --git a/ICSharpCode.NRefactory.VB.Tests/Lexer/LiteralsTests.cs b/ICSharpCode.NRefactory.VB.Tests/Lexer/LiteralsTests.cs index c1f32fbaf..7572b916c 100644 --- a/ICSharpCode.NRefactory.VB.Tests/Lexer/LiteralsTests.cs +++ b/ICSharpCode.NRefactory.VB.Tests/Lexer/LiteralsTests.cs @@ -13,7 +13,7 @@ namespace ICSharpCode.NRefactory.VB.Tests.Lexer { VBLexer GenerateLexer(StringReader sr) { - return ParserFactory.CreateLexer(sr); + return new VBLexer(sr); } Token GetSingleToken(string text) diff --git a/ICSharpCode.NRefactory.VB.Tests/Lexer/XmlModeLexerTests.cs b/ICSharpCode.NRefactory.VB.Tests/Lexer/XmlModeLexerTests.cs index e582bd2a1..e55c4f9b5 100644 --- a/ICSharpCode.NRefactory.VB.Tests/Lexer/XmlModeLexerTests.cs +++ b/ICSharpCode.NRefactory.VB.Tests/Lexer/XmlModeLexerTests.cs @@ -948,12 +948,12 @@ End Using"; #region Helpers VBLexer GenerateLexer(StringReader sr) { - return ParserFactory.CreateLexer(sr); + return new VBLexer(sr); } VBLexer GenerateLexerForSnippet(StringReader sr, SnippetType type) { - var lexer = ParserFactory.CreateLexer(sr); + var lexer = new VBLexer(sr); lexer.SetInitialContext(type); return lexer; } diff --git a/ICSharpCode.NRefactory.VB.Tests/Output/CodeDOM/InvocationExpressionTest.cs b/ICSharpCode.NRefactory.VB.Tests/Output/CodeDOM/InvocationExpressionTest.cs index 94f52b45e..443dcfe3c 100644 --- a/ICSharpCode.NRefactory.VB.Tests/Output/CodeDOM/InvocationExpressionTest.cs +++ b/ICSharpCode.NRefactory.VB.Tests/Output/CodeDOM/InvocationExpressionTest.cs @@ -18,7 +18,7 @@ namespace ICSharpCode.NRefactory.VB.Tests.Output.CodeDom.Tests public void IdentifierOnlyInvocation() { // InitializeComponents(); - IdentifierExpression identifier = new IdentifierExpression("InitializeComponents"); + SimpleNameExpression identifier = new SimpleNameExpression("InitializeComponents"); InvocationExpression invocation = new InvocationExpression(identifier, new List()); object output = invocation.AcceptVisitor(new CodeDomVisitor(), null); Assert.IsTrue(output is CodeMethodInvokeExpression); @@ -44,7 +44,7 @@ namespace ICSharpCode.NRefactory.VB.Tests.Output.CodeDom.Tests public void InvocationOfStaticMethod() { // System.Drawing.Color.FromArgb(); - MemberReferenceExpression field = new MemberReferenceExpression(new IdentifierExpression("System"), "Drawing"); + MemberReferenceExpression field = new MemberReferenceExpression(new SimpleNameExpression("System"), "Drawing"); field = new MemberReferenceExpression(field, "Color"); field = new MemberReferenceExpression(field, "FromArgb"); InvocationExpression invocation = new InvocationExpression(field, new List()); diff --git a/ICSharpCode.NRefactory.VB.Tests/Output/SpecialOutputVisitorTest.cs b/ICSharpCode.NRefactory.VB.Tests/Output/SpecialOutputVisitorTest.cs index 7e8961e63..5c0328ec2 100644 --- a/ICSharpCode.NRefactory.VB.Tests/Output/SpecialOutputVisitorTest.cs +++ b/ICSharpCode.NRefactory.VB.Tests/Output/SpecialOutputVisitorTest.cs @@ -8,7 +8,7 @@ using System.IO; using ICSharpCode.NRefactory.VB.Ast; using ICSharpCode.NRefactory.VB.Parser; using ICSharpCode.NRefactory.VB.PrettyPrinter; -using ICSharpCode.NRefactory.VB.Visitors; + using NUnit.Framework; namespace ICSharpCode.NRefactory.VB.Tests.PrettyPrinter diff --git a/ICSharpCode.NRefactory.VB.Tests/Parser/CheckParentVisitor.cs b/ICSharpCode.NRefactory.VB.Tests/Parser/CheckParentVisitor.cs deleted file mode 100644 index 8c7a4f27e..000000000 --- a/ICSharpCode.NRefactory.VB.Tests/Parser/CheckParentVisitor.cs +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using NUnit.Framework; -using System; -using System.Collections.Generic; -using ICSharpCode.NRefactory.VB.Ast; -using ICSharpCode.NRefactory.VB.Visitors; - -namespace ICSharpCode.NRefactory.VB.Tests.Ast -{ - /// - /// Ensures that all nodes have the Parent property correctly set. - /// - public class CheckParentVisitor : NodeTrackingAstVisitor - { - Stack nodeStack = new Stack(); - - public CheckParentVisitor() - { - nodeStack.Push(null); - } - - protected override void BeginVisit(INode node) - { - nodeStack.Push(node); - } - - protected override void EndVisit(INode node) - { - Assert.AreSame(node, nodeStack.Pop(), "nodeStack was corrupted!"); - Assert.AreSame(nodeStack.Peek(), node.Parent, "node " + node + " is missing parent: " + nodeStack.Peek()); - } - } -} diff --git a/ICSharpCode.NRefactory.VB.Tests/Parser/Expressions/BinaryOperatorExpressionTests.cs b/ICSharpCode.NRefactory.VB.Tests/Parser/Expressions/BinaryOperatorExpressionTests.cs index 030d17132..256144aae 100644 --- a/ICSharpCode.NRefactory.VB.Tests/Parser/Expressions/BinaryOperatorExpressionTests.cs +++ b/ICSharpCode.NRefactory.VB.Tests/Parser/Expressions/BinaryOperatorExpressionTests.cs @@ -20,20 +20,20 @@ namespace ICSharpCode.NRefactory.VB.Tests.Ast BinaryOperatorExpression boe; boe = ParseUtil.ParseExpression(program); Assert.AreEqual(weakOperatorType, boe.Op); - Assert.IsTrue(boe.Left is IdentifierExpression); + Assert.IsTrue(boe.Left is SimpleNameExpression); boe = (BinaryOperatorExpression)boe.Right; Assert.AreEqual(strongOperatorType, boe.Op); - Assert.IsTrue(boe.Left is IdentifierExpression); - Assert.IsTrue(boe.Right is IdentifierExpression); + Assert.IsTrue(boe.Left is SimpleNameExpression); + Assert.IsTrue(boe.Right is SimpleNameExpression); program = "a " + strongOperator + " b " + weakOperator + " c"; boe = ParseUtil.ParseExpression(program); Assert.AreEqual(weakOperatorType, boe.Op); - Assert.IsTrue(boe.Right is IdentifierExpression); + Assert.IsTrue(boe.Right is SimpleNameExpression); boe = (BinaryOperatorExpression)boe.Left; Assert.AreEqual(strongOperatorType, boe.Op); - Assert.IsTrue(boe.Left is IdentifierExpression); - Assert.IsTrue(boe.Right is IdentifierExpression); + Assert.IsTrue(boe.Left is SimpleNameExpression); + Assert.IsTrue(boe.Right is SimpleNameExpression); } void SameOperatorPrecedenceTest(string firstOperator, BinaryOperatorType firstOperatorType, @@ -43,20 +43,20 @@ namespace ICSharpCode.NRefactory.VB.Tests.Ast BinaryOperatorExpression boe; boe = ParseUtil.ParseExpression(program); Assert.AreEqual(firstOperatorType, boe.Op); - Assert.IsTrue(boe.Right is IdentifierExpression); + Assert.IsTrue(boe.Right is SimpleNameExpression); boe = (BinaryOperatorExpression)boe.Left; Assert.AreEqual(secondOperatorType, boe.Op); - Assert.IsTrue(boe.Left is IdentifierExpression); - Assert.IsTrue(boe.Right is IdentifierExpression); + Assert.IsTrue(boe.Left is SimpleNameExpression); + Assert.IsTrue(boe.Right is SimpleNameExpression); program = "a " + firstOperator + " b " + secondOperator + " c"; boe = ParseUtil.ParseExpression(program); Assert.AreEqual(secondOperatorType, boe.Op); - Assert.IsTrue(boe.Right is IdentifierExpression); + Assert.IsTrue(boe.Right is SimpleNameExpression); boe = (BinaryOperatorExpression)boe.Left; Assert.AreEqual(firstOperatorType, boe.Op); - Assert.IsTrue(boe.Left is IdentifierExpression); - Assert.IsTrue(boe.Right is IdentifierExpression); + Assert.IsTrue(boe.Left is SimpleNameExpression); + Assert.IsTrue(boe.Right is SimpleNameExpression); } #region VB.NET @@ -65,8 +65,8 @@ namespace ICSharpCode.NRefactory.VB.Tests.Ast BinaryOperatorExpression boe = ParseUtil.ParseExpression(program); Assert.AreEqual(op, boe.Op); - Assert.IsTrue(boe.Left is IdentifierExpression); - Assert.IsTrue(boe.Right is IdentifierExpression); + Assert.IsTrue(boe.Left is SimpleNameExpression); + Assert.IsTrue(boe.Right is SimpleNameExpression); } [Test] @@ -251,7 +251,7 @@ namespace ICSharpCode.NRefactory.VB.Tests.Ast { BinaryOperatorExpression boe = ParseUtil.ParseExpression("a!b"); Assert.AreEqual(BinaryOperatorType.DictionaryAccess, boe.Op); - Assert.IsTrue(boe.Left is IdentifierExpression); + Assert.IsTrue(boe.Left is SimpleNameExpression); Assert.IsTrue(boe.Right is PrimitiveExpression); } @@ -264,47 +264,5 @@ namespace ICSharpCode.NRefactory.VB.Tests.Ast Assert.IsTrue(boe.Right is PrimitiveExpression); } #endregion - - #region AddIntegerTests - string AddIntegerToBoe(string input, int number) - { - return AddInteger(input, number); - } - - string AddInteger(string input, int number) where T : Expression - { - Expression e = ParseUtil.ParseExpression(input); - e = Expression.AddInteger(e, number); - VBNetOutputVisitor v = new VBNetOutputVisitor(); - e.AcceptVisitor(v, null); - return v.Text; - } - - [Test] - public void AddInteger() - { - Assert.AreEqual("a + 2", AddIntegerToBoe("a + 1", 1)); - Assert.AreEqual("a + 2", AddIntegerToBoe("a + 3", -1)); - Assert.AreEqual("a + b + c + 2", AddIntegerToBoe("a + b + c + 1", 1)); - Assert.AreEqual("a", AddIntegerToBoe("a + 1", -1)); - Assert.AreEqual("2", AddInteger("1", 1)); - Assert.AreEqual("-1", AddInteger("1", -2)); - Assert.AreEqual("0", AddInteger("1", -1)); - Assert.AreEqual("a + 1", AddInteger("a", 1)); - } - - [Test] - public void AddIntegerWithNegativeResult() - { - Assert.AreEqual("a - 1", AddIntegerToBoe("a + 1", -2)); - Assert.AreEqual("a - 2", AddIntegerToBoe("a - 1", -1)); - Assert.AreEqual("a + b + c - 2", AddIntegerToBoe("a + b + c + 2", -4)); - Assert.AreEqual("a + b + c - 6", AddIntegerToBoe("a + b + c - 2", -4)); - Assert.AreEqual("a + b + c", AddIntegerToBoe("a + b + c + 2", -2)); - Assert.AreEqual("a", AddIntegerToBoe("a - 1", 1)); - Assert.AreEqual("a + 1", AddIntegerToBoe("a - 2", 3)); - Assert.AreEqual("a - 1", AddInteger("a", -1)); - } - #endregion } } diff --git a/ICSharpCode.NRefactory.VB.Tests/Parser/Expressions/CastExpressionTests.cs b/ICSharpCode.NRefactory.VB.Tests/Parser/Expressions/CastExpressionTests.cs index b4ec88756..d93aa709d 100644 --- a/ICSharpCode.NRefactory.VB.Tests/Parser/Expressions/CastExpressionTests.cs +++ b/ICSharpCode.NRefactory.VB.Tests/Parser/Expressions/CastExpressionTests.cs @@ -17,7 +17,7 @@ namespace ICSharpCode.NRefactory.VB.Tests.Ast { CastExpression ce = ParseUtil.ParseExpression(castExpression); Assert.AreEqual(castType.FullName, ce.CastTo.Type); - Assert.IsTrue(ce.Expression is IdentifierExpression); + Assert.IsTrue(ce.Expression is SimpleNameExpression); Assert.AreEqual(CastType.PrimitiveConversion, ce.CastType); } @@ -27,7 +27,7 @@ namespace ICSharpCode.NRefactory.VB.Tests.Ast { CastExpression ce = ParseUtil.ParseExpression("CType(o, MyObject)"); Assert.AreEqual("MyObject", ce.CastTo.Type); - Assert.IsTrue(ce.Expression is IdentifierExpression); + Assert.IsTrue(ce.Expression is SimpleNameExpression); Assert.AreEqual(CastType.Conversion, ce.CastType); } @@ -37,7 +37,7 @@ namespace ICSharpCode.NRefactory.VB.Tests.Ast CastExpression ce = ParseUtil.ParseExpression("CType(o, List(of T))"); Assert.AreEqual("List", ce.CastTo.Type); Assert.AreEqual("T", ce.CastTo.GenericTypes[0].Type); - Assert.IsTrue(ce.Expression is IdentifierExpression); + Assert.IsTrue(ce.Expression is SimpleNameExpression); Assert.AreEqual(CastType.Conversion, ce.CastType); } @@ -46,7 +46,7 @@ namespace ICSharpCode.NRefactory.VB.Tests.Ast { CastExpression ce = ParseUtil.ParseExpression("DirectCast(o, MyObject)"); Assert.AreEqual("MyObject", ce.CastTo.Type); - Assert.IsTrue(ce.Expression is IdentifierExpression); + Assert.IsTrue(ce.Expression is SimpleNameExpression); Assert.AreEqual(CastType.Cast, ce.CastType); } @@ -56,7 +56,7 @@ namespace ICSharpCode.NRefactory.VB.Tests.Ast CastExpression ce = ParseUtil.ParseExpression("DirectCast(o, List(of T))"); Assert.AreEqual("List", ce.CastTo.Type); Assert.AreEqual("T", ce.CastTo.GenericTypes[0].Type); - Assert.IsTrue(ce.Expression is IdentifierExpression); + Assert.IsTrue(ce.Expression is SimpleNameExpression); Assert.AreEqual(CastType.Cast, ce.CastType); } @@ -65,7 +65,7 @@ namespace ICSharpCode.NRefactory.VB.Tests.Ast { CastExpression ce = ParseUtil.ParseExpression("TryCast(o, MyObject)"); Assert.AreEqual("MyObject", ce.CastTo.Type); - Assert.IsTrue(ce.Expression is IdentifierExpression); + Assert.IsTrue(ce.Expression is SimpleNameExpression); Assert.AreEqual(CastType.TryCast, ce.CastType); } @@ -75,7 +75,7 @@ namespace ICSharpCode.NRefactory.VB.Tests.Ast CastExpression ce = ParseUtil.ParseExpression("TryCast(o, List(of T))"); Assert.AreEqual("List", ce.CastTo.Type); Assert.AreEqual("T", ce.CastTo.GenericTypes[0].Type); - Assert.IsTrue(ce.Expression is IdentifierExpression); + Assert.IsTrue(ce.Expression is SimpleNameExpression); Assert.AreEqual(CastType.TryCast, ce.CastType); } diff --git a/ICSharpCode.NRefactory.VB.Tests/Parser/Expressions/InvocationExpressionTests.cs b/ICSharpCode.NRefactory.VB.Tests/Parser/Expressions/InvocationExpressionTests.cs index 8fbe1c289..dcc4e731c 100644 --- a/ICSharpCode.NRefactory.VB.Tests/Parser/Expressions/InvocationExpressionTests.cs +++ b/ICSharpCode.NRefactory.VB.Tests/Parser/Expressions/InvocationExpressionTests.cs @@ -15,15 +15,15 @@ namespace ICSharpCode.NRefactory.VB.Tests.Ast void CheckSimpleInvoke(InvocationExpression ie) { Assert.AreEqual(0, ie.Arguments.Count); - Assert.IsTrue(ie.TargetObject is IdentifierExpression); - Assert.AreEqual("myMethod", ((IdentifierExpression)ie.TargetObject).Identifier); + Assert.IsTrue(ie.TargetObject is SimpleNameExpression); + Assert.AreEqual("myMethod", ((SimpleNameExpression)ie.TargetObject).Identifier); } void CheckGenericInvoke(InvocationExpression expr) { Assert.AreEqual(1, expr.Arguments.Count); - Assert.IsTrue(expr.TargetObject is IdentifierExpression); - IdentifierExpression ident = (IdentifierExpression)expr.TargetObject; + Assert.IsTrue(expr.TargetObject is SimpleNameExpression); + SimpleNameExpression ident = (SimpleNameExpression)expr.TargetObject; Assert.AreEqual("myMethod", ident.Identifier); Assert.AreEqual(1, ident.TypeArguments.Count); Assert.AreEqual("System.Char", ident.TypeArguments[0].Type); @@ -32,8 +32,8 @@ namespace ICSharpCode.NRefactory.VB.Tests.Ast void CheckGenericInvoke2(InvocationExpression expr) { Assert.AreEqual(0, expr.Arguments.Count); - Assert.IsTrue(expr.TargetObject is IdentifierExpression); - IdentifierExpression ident = (IdentifierExpression)expr.TargetObject; + Assert.IsTrue(expr.TargetObject is SimpleNameExpression); + SimpleNameExpression ident = (SimpleNameExpression)expr.TargetObject; Assert.AreEqual("myMethod", ident.Identifier); Assert.AreEqual(2, ident.TypeArguments.Count); Assert.AreEqual("T", ident.TypeArguments[0].Type); @@ -74,7 +74,7 @@ namespace ICSharpCode.NRefactory.VB.Tests.Ast InvocationExpression expr = ParseUtil.ParseExpression("A(Of T).Foo()"); MemberReferenceExpression mre = (MemberReferenceExpression)expr.TargetObject; Assert.AreEqual("Foo", mre.MemberName); - IdentifierExpression tre = (IdentifierExpression)mre.TargetObject; + SimpleNameExpression tre = (SimpleNameExpression)mre.TargetObject; Assert.AreEqual("A", tre.Identifier); Assert.AreEqual("T", tre.TypeArguments[0].Type); } @@ -87,7 +87,7 @@ namespace ICSharpCode.NRefactory.VB.Tests.Ast Assert.AreEqual("Foo", mre.MemberName); MemberReferenceExpression mre2 = (MemberReferenceExpression)mre.TargetObject; Assert.AreEqual("B", mre2.MemberName); - IdentifierExpression tre = (IdentifierExpression)mre2.TargetObject; + SimpleNameExpression tre = (SimpleNameExpression)mre2.TargetObject; Assert.AreEqual("A", tre.Identifier); Assert.AreEqual("T", tre.TypeArguments[0].Type); } @@ -106,7 +106,7 @@ namespace ICSharpCode.NRefactory.VB.Tests.Ast MemberReferenceExpression mre3 = (MemberReferenceExpression)mre2.TargetObject; Assert.AreEqual("B", mre3.MemberName); - IdentifierExpression tre = (IdentifierExpression)mre3.TargetObject; + SimpleNameExpression tre = (SimpleNameExpression)mre3.TargetObject; Assert.AreEqual("A", tre.Identifier); Assert.AreEqual("T", tre.TypeArguments[0].Type); } diff --git a/ICSharpCode.NRefactory.VB.Tests/Parser/Expressions/MemberReferenceExpressionTests.cs b/ICSharpCode.NRefactory.VB.Tests/Parser/Expressions/MemberReferenceExpressionTests.cs index bdf73af4b..94efda65b 100644 --- a/ICSharpCode.NRefactory.VB.Tests/Parser/Expressions/MemberReferenceExpressionTests.cs +++ b/ICSharpCode.NRefactory.VB.Tests/Parser/Expressions/MemberReferenceExpressionTests.cs @@ -18,8 +18,8 @@ namespace ICSharpCode.NRefactory.VB.Tests.Ast { MemberReferenceExpression fre = ParseUtil.ParseExpression("myTargetObject.myField"); Assert.AreEqual("myField", fre.MemberName); - Assert.IsTrue(fre.TargetObject is IdentifierExpression); - Assert.AreEqual("myTargetObject", ((IdentifierExpression)fre.TargetObject).Identifier); + Assert.IsTrue(fre.TargetObject is SimpleNameExpression); + Assert.AreEqual("myTargetObject", ((SimpleNameExpression)fre.TargetObject).Identifier); } [Test] @@ -35,8 +35,8 @@ namespace ICSharpCode.NRefactory.VB.Tests.Ast { MemberReferenceExpression fre = ParseUtil.ParseExpression("SomeClass(of string).myField"); Assert.AreEqual("myField", fre.MemberName); - Assert.IsInstanceOf(typeof(IdentifierExpression), fre.TargetObject); - TypeReference tr = ((IdentifierExpression)fre.TargetObject).TypeArguments[0]; + Assert.IsInstanceOf(typeof(SimpleNameExpression), fre.TargetObject); + TypeReference tr = ((SimpleNameExpression)fre.TargetObject).TypeArguments[0]; Assert.AreEqual("System.String", tr.Type); } diff --git a/ICSharpCode.NRefactory.VB.Tests/Parser/Expressions/ObjectCreateExpressionTests.cs b/ICSharpCode.NRefactory.VB.Tests/Parser/Expressions/ObjectCreateExpressionTests.cs index 478dcf330..2b6a8f886 100644 --- a/ICSharpCode.NRefactory.VB.Tests/Parser/Expressions/ObjectCreateExpressionTests.cs +++ b/ICSharpCode.NRefactory.VB.Tests/Parser/Expressions/ObjectCreateExpressionTests.cs @@ -53,8 +53,8 @@ namespace ICSharpCode.NRefactory.VB.Tests.Ast Assert.AreEqual(0, oce.Parameters.Count); Assert.AreEqual(1, oce.ObjectInitializer.CreateExpressions.Count); - Assert.IsInstanceOf(typeof(IdentifierExpression), oce.ObjectInitializer.CreateExpressions[0]); - Assert.AreEqual("c", (oce.ObjectInitializer.CreateExpressions[0] as IdentifierExpression).Identifier); + Assert.IsInstanceOf(typeof(SimpleNameExpression), oce.ObjectInitializer.CreateExpressions[0]); + Assert.AreEqual("c", (oce.ObjectInitializer.CreateExpressions[0] as SimpleNameExpression).Identifier); } [Test] @@ -69,8 +69,8 @@ namespace ICSharpCode.NRefactory.VB.Tests.Ast // this test was written because this bug caused the AbstractDomVisitor to crash InvocationExpression expr = ParseUtil.ParseExpression("WriteLine(New SomeGenericType(Of Integer, )())", true); - Assert.IsTrue(expr.TargetObject is IdentifierExpression); - Assert.AreEqual("WriteLine", ((IdentifierExpression)expr.TargetObject).Identifier); + Assert.IsTrue(expr.TargetObject is SimpleNameExpression); + Assert.AreEqual("WriteLine", ((SimpleNameExpression)expr.TargetObject).Identifier); Assert.AreEqual(1, expr.Arguments.Count); // here a second null parameter was added incorrectly Assert.IsTrue(expr.Arguments[0] is ObjectCreateExpression); diff --git a/ICSharpCode.NRefactory.VB.Tests/Parser/Expressions/QueryExpressionTests.cs b/ICSharpCode.NRefactory.VB.Tests/Parser/Expressions/QueryExpressionTests.cs index dad3349c4..8d46f278e 100644 --- a/ICSharpCode.NRefactory.VB.Tests/Parser/Expressions/QueryExpressionTests.cs +++ b/ICSharpCode.NRefactory.VB.Tests/Parser/Expressions/QueryExpressionTests.cs @@ -225,7 +225,7 @@ namespace ICSharpCode.NRefactory.VB.Tests.Ast Action constraint = expr => { var fromClause = expr.Clauses[0] as QueryExpressionFromClause; var groupClause = expr.Clauses[1] as QueryExpressionGroupVBClause; - var letClause = expr.Clauses[2] as QueryExpressionLetVBClause; + var letClause = expr.Clauses[2] as QueryExpressionLetClause; var selectClause = expr.Clauses[3] as QueryExpressionSelectVBClause; // From @@ -276,7 +276,7 @@ namespace ICSharpCode.NRefactory.VB.Tests.Ast Group p By p.Category Into Group _ Let minPrice = Group.Min(Function(p) p.UnitPrice) _ Select Category, CheapestProducts = Group.Where(Function(p) p.UnitPrice = minPrice)", 4, constraint, - typeof(QueryExpressionFromClause), typeof(QueryExpressionGroupVBClause), typeof(QueryExpressionLetVBClause), typeof(QueryExpressionSelectVBClause)); + typeof(QueryExpressionFromClause), typeof(QueryExpressionGroupVBClause), typeof(QueryExpressionLetClause), typeof(QueryExpressionSelectVBClause)); } [Test] diff --git a/ICSharpCode.NRefactory.VB.Tests/Parser/Expressions/TypeOfIsExpressionTests.cs b/ICSharpCode.NRefactory.VB.Tests/Parser/Expressions/TypeOfIsExpressionTests.cs index 9d7da043d..46f7e959e 100644 --- a/ICSharpCode.NRefactory.VB.Tests/Parser/Expressions/TypeOfIsExpressionTests.cs +++ b/ICSharpCode.NRefactory.VB.Tests/Parser/Expressions/TypeOfIsExpressionTests.cs @@ -18,7 +18,7 @@ namespace ICSharpCode.NRefactory.VB.Tests.Ast { TypeOfIsExpression ce = ParseUtil.ParseExpression("TypeOf o Is MyObject"); Assert.AreEqual("MyObject", ce.TypeReference.Type); - Assert.IsTrue(ce.Expression is IdentifierExpression); + Assert.IsTrue(ce.Expression is SimpleNameExpression); } [Test] @@ -27,7 +27,7 @@ namespace ICSharpCode.NRefactory.VB.Tests.Ast TypeOfIsExpression ce = ParseUtil.ParseExpression("TypeOf o Is List(of T)"); Assert.AreEqual("List", ce.TypeReference.Type); Assert.AreEqual("T", ce.TypeReference.GenericTypes[0].Type); - Assert.IsTrue(ce.Expression is IdentifierExpression); + Assert.IsTrue(ce.Expression is SimpleNameExpression); } #endregion } diff --git a/ICSharpCode.NRefactory.VB.Tests/Parser/Expressions/UnaryOperatorExpressionTests.cs b/ICSharpCode.NRefactory.VB.Tests/Parser/Expressions/UnaryOperatorExpressionTests.cs index 5bbaa66f1..b5100b2cd 100644 --- a/ICSharpCode.NRefactory.VB.Tests/Parser/Expressions/UnaryOperatorExpressionTests.cs +++ b/ICSharpCode.NRefactory.VB.Tests/Parser/Expressions/UnaryOperatorExpressionTests.cs @@ -18,7 +18,7 @@ namespace ICSharpCode.NRefactory.VB.Tests.Ast UnaryOperatorExpression uoe = ParseUtil.ParseExpression(program); Assert.AreEqual(op, uoe.Op); - Assert.IsTrue(uoe.Expression is IdentifierExpression); + Assert.IsTrue(uoe.Expression is SimpleNameExpression); } [Test] diff --git a/ICSharpCode.NRefactory.VB.Tests/Parser/Expressions/XmlExpressionTests.cs b/ICSharpCode.NRefactory.VB.Tests/Parser/Expressions/XmlExpressionTests.cs index cc9012cc6..e36b43b0d 100644 --- a/ICSharpCode.NRefactory.VB.Tests/Parser/Expressions/XmlExpressionTests.cs +++ b/ICSharpCode.NRefactory.VB.Tests/Parser/Expressions/XmlExpressionTests.cs @@ -230,7 +230,7 @@ namespace ICSharpCode.NRefactory.VB.Tests.Ast } #endregion - void CheckElement(INode node, string name, Location start, Location end) + void CheckElement(AstNode node, string name, AstLocation start, AstLocation end) { Assert.IsTrue(node is XmlElementExpression); XmlElementExpression expr = node as XmlElementExpression; @@ -242,7 +242,7 @@ namespace ICSharpCode.NRefactory.VB.Tests.Ast Assert.AreEqual(end, expr.EndLocation); } - void CheckContent(INode node, string content, XmlContentType type, Location start, Location end) + void CheckContent(AstNode node, string content, XmlContentType type, AstLocation start, AstLocation end) { Assert.IsTrue(node is XmlContentExpression); XmlContentExpression expr = node as XmlContentExpression; diff --git a/ICSharpCode.NRefactory.VB.Tests/Parser/GlobalScope/AttributeSectionTests.cs b/ICSharpCode.NRefactory.VB.Tests/Parser/GlobalScope/AttributeSectionTests.cs index 8a877ed9e..997e2dc11 100644 --- a/ICSharpCode.NRefactory.VB.Tests/Parser/GlobalScope/AttributeSectionTests.cs +++ b/ICSharpCode.NRefactory.VB.Tests/Parser/GlobalScope/AttributeSectionTests.cs @@ -12,63 +12,63 @@ namespace ICSharpCode.NRefactory.VB.Tests.Ast [TestFixture] public class AttributeSectionTests { - [Test] - public void AttributeOnStructure() - { - string program = @" - _ -Public Structure MyUnion - - Public i As Integer - < FieldOffset( 0 )> Public d As Double - -End Structure 'MyUnion -"; - TypeDeclaration decl = ParseUtil.ParseGlobal(program); - Assert.AreEqual("StructLayout", decl.Attributes[0].Attributes[0].Name); - } - - [Test] - public void AttributeOnModule() - { - string program = @" - _ -Public Module MyExtra - - Public i As Integer - Public d As Double - -End Module -"; - TypeDeclaration decl = ParseUtil.ParseGlobal(program); - Assert.AreEqual("HideModule", decl.Attributes[0].Attributes[0].Name); - } - - [Test] - public void GlobalAttribute() - { - string program = @" _ -Public Class Form1 - -End Class"; - TypeDeclaration decl = ParseUtil.ParseGlobal(program); - Assert.AreEqual("Microsoft.VisualBasic.CompilerServices.DesignerGenerated", decl.Attributes[0].Attributes[0].Name); - } - - [Test] - public void AssemblyAttribute() - { - string program = @""; - AttributeSection decl = ParseUtil.ParseGlobal(program); - Assert.AreEqual(new Location(1, 1), decl.StartLocation); - Assert.AreEqual("assembly", decl.AttributeTarget); - } - - [Test] - public void ModuleAttributeTargetEscaped() - { - // check that this doesn't crash the parser: - ParseUtil.ParseGlobal("<[Module]: SuppressMessageAttribute>", true); - } +// [Test] +// public void AttributeOnStructure() +// { +// string program = @" +// _ +//Public Structure MyUnion +// +// Public i As Integer +// < FieldOffset( 0 )> Public d As Double +// +//End Structure 'MyUnion +//"; +// TypeDeclaration decl = ParseUtil.ParseGlobal(program); +// Assert.AreEqual("StructLayout", decl.Attributes[0].Attributes[0].Type); +// } +// +// [Test] +// public void AttributeOnModule() +// { +// string program = @" +// _ +//Public Module MyExtra +// +// Public i As Integer +// Public d As Double +// +//End Module +//"; +// TypeDeclaration decl = ParseUtil.ParseGlobal(program); +// Assert.AreEqual("HideModule", decl.Attributes[0].Attributes[0].Type); +// } +// +// [Test] +// public void GlobalAttribute() +// { +// string program = @" _ +//Public Class Form1 +// +//End Class"; +// TypeDeclaration decl = ParseUtil.ParseGlobal(program); +// Assert.AreEqual("Microsoft.VisualBasic.CompilerServices.DesignerGenerated", decl.Attributes[0].Attributes[0].Type); +// } +// +// [Test] +// public void AssemblyAttribute() +// { +// string program = @""; +// AttributeSection decl = ParseUtil.ParseGlobal(program); +// Assert.AreEqual(new Location(1, 1), decl.StartLocation); +// Assert.AreEqual("assembly", decl.AttributeTarget); +// } +// +// [Test] +// public void ModuleAttributeTargetEscaped() +// { +// // check that this doesn't crash the parser: +// ParseUtil.ParseGlobal("<[Module]: SuppressMessageAttribute>", true); +// } } } diff --git a/ICSharpCode.NRefactory.VB.Tests/Parser/GlobalScope/DelegateDeclarationTests.cs b/ICSharpCode.NRefactory.VB.Tests/Parser/GlobalScope/DelegateDeclarationTests.cs deleted file mode 100644 index 3328c8f2c..000000000 --- a/ICSharpCode.NRefactory.VB.Tests/Parser/GlobalScope/DelegateDeclarationTests.cs +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using System; -using ICSharpCode.NRefactory.VB.Ast; -using NUnit.Framework; - -namespace ICSharpCode.NRefactory.VB.Tests.Ast -{ - [TestFixture] - public class DelegateDeclarationTests - { - void TestDelegateDeclaration(DelegateDeclaration dd) - { - Assert.AreEqual("System.Void", dd.ReturnType.Type); - Assert.AreEqual("MyDelegate", dd.Name); - } - - void TestParameters(DelegateDeclaration dd) - { - Assert.AreEqual(3, dd.Parameters.Count); - - Assert.AreEqual("a", ((ParameterDeclarationExpression)dd.Parameters[0]).ParameterName); - Assert.AreEqual("System.Int32", ((ParameterDeclarationExpression)dd.Parameters[0]).TypeReference.Type); - - Assert.AreEqual("secondParam", ((ParameterDeclarationExpression)dd.Parameters[1]).ParameterName); - Assert.AreEqual("System.Int32", ((ParameterDeclarationExpression)dd.Parameters[1]).TypeReference.Type); - - Assert.AreEqual("lastParam", ((ParameterDeclarationExpression)dd.Parameters[2]).ParameterName); - Assert.AreEqual("MyObj", ((ParameterDeclarationExpression)dd.Parameters[2]).TypeReference.Type); - } - - #region VB.NET - [Test] - public void SimpleVBNetDelegateDeclarationTest() - { - string program = "Public Delegate Sub MyDelegate(ByVal a As Integer, ByVal secondParam As Integer, ByVal lastParam As MyObj)\n"; - TestDelegateDeclaration(ParseUtil.ParseGlobal(program)); - } - #endregion - } -} diff --git a/ICSharpCode.NRefactory.VB.Tests/Parser/GlobalScope/ImportsStatementTests.cs b/ICSharpCode.NRefactory.VB.Tests/Parser/GlobalScope/ImportsStatementTests.cs new file mode 100644 index 000000000..0e7546f9e --- /dev/null +++ b/ICSharpCode.NRefactory.VB.Tests/Parser/GlobalScope/ImportsStatementTests.cs @@ -0,0 +1,168 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; +using System.IO; +using ICSharpCode.NRefactory.VB.Parser; +using ICSharpCode.NRefactory.VB.Ast; +using NUnit.Framework; + +namespace ICSharpCode.NRefactory.VB.Tests.Ast +{ + [TestFixture] + public class ImportsStatementTests + { + [Test] + public void InvalidImportsStatement() + { + string program = "Imports\n"; + ParseUtil.ParseGlobal(program, true); + } + + [Test] + public void InvalidImportsStatement2() + { + string program = "Imports ,\n"; + ParseUtil.ParseGlobal(program, true); + } + + [Test] + public void SimpleImportsStatement() + { + string program = "Imports System\n"; + + var clause1 = new MemberImportsClause { + Member = new SimpleType("System") + }; + + var node = new ImportsStatement(); + node.AddChild(clause1, ImportsStatement.ImportsClauseRole); + + ParseUtil.AssertGlobal(program, node); + } + + [Test] + public void QualifiedTypeImportsStatement() + { + string program = "Imports My.Name.Space\n"; + + var clause2 = new MemberImportsClause { + Member = new QualifiedType(new QualifiedType(new SimpleType("My"), new Identifier("Name", AstLocation.Empty)), new Identifier("Space", AstLocation.Empty)) + }; + + var node = new ImportsStatement(); + node.AddChild(clause2, ImportsStatement.ImportsClauseRole); + + ParseUtil.AssertGlobal(program, node); + } +// +// [Test] +// public void VBNetUsingAliasDeclarationTest() +// { +// string program = "Imports TESTME=System\n" + +// "Imports myAlias=My.Name.Space\n" + +// "Imports StringCollection = System.Collections.Generic.List(Of string)\n"; +// VBParser parser = ParserFactory.CreateParser(new StringReader(program)); +// parser.Parse(); +// +// Assert.AreEqual("", parser.Errors.ErrorOutput); +// CheckAliases(parser.CompilationUnit); +// } +// +// [Test] +// public void VBNetComplexUsingAliasDeclarationTest() +// { +// string program = "Imports NS1, AL=NS2, NS3, AL2=NS4, NS5\n"; +// VBParser parser = ParserFactory.CreateParser(new StringReader(program)); +// parser.Parse(); +// +// Assert.AreEqual("", parser.Errors.ErrorOutput); +// // TODO : Extend test ... +// } +// +// [Test] +// public void VBNetXmlNamespaceUsingTest() +// { +// string program = "Imports "; +// VBParser parser = ParserFactory.CreateParser(new StringReader(program)); +// parser.Parse(); +// +// Assert.AreEqual("", parser.Errors.ErrorOutput); +// CompilationUnit unit = parser.CompilationUnit; +// +// Assert.AreEqual(1, unit.Children.Count); +// Assert.IsTrue(unit.Children[0] is ImportsStatement); +// ImportsStatement ud = (ImportsStatement)unit.Children[0]; +// Assert.AreEqual(1, ud.ImportsClauses.Count); +// Assert.IsFalse(ud.ImportsClauses[0].IsAlias); +// Assert.IsTrue(ud.ImportsClauses[0].IsXml); +// +// Assert.AreEqual("xmlns", ud.ImportsClauses[0].XmlPrefix); +// Assert.AreEqual("http://icsharpcode.net/sharpdevelop/avalonedit", ud.ImportsClauses[0].Name); +// } +// +// [Test] +// public void VBNetXmlNamespaceWithPrefixUsingTest() +// { +// string program = "Imports "; +// VBParser parser = ParserFactory.CreateParser(new StringReader(program)); +// parser.Parse(); +// +// Assert.AreEqual("", parser.Errors.ErrorOutput); +// CompilationUnit unit = parser.CompilationUnit; +// +// Assert.AreEqual(1, unit.Children.Count); +// Assert.IsTrue(unit.Children[0] is ImportsStatement); +// ImportsStatement ud = (ImportsStatement)unit.Children[0]; +// Assert.AreEqual(1, ud.ImportsClauses.Count); +// Assert.IsFalse(ud.ImportsClauses[0].IsAlias); +// Assert.IsTrue(ud.ImportsClauses[0].IsXml); +// +// Assert.AreEqual("xmlns:avalonedit", ud.ImportsClauses[0].XmlPrefix); +// Assert.AreEqual("http://icsharpcode.net/sharpdevelop/avalonedit", ud.ImportsClauses[0].Name); +// } +// +// [Test] +// public void VBNetXmlNamespaceSingleQuotedUsingTest() +// { +// string program = "Imports "; +// VBParser parser = ParserFactory.CreateParser(new StringReader(program)); +// parser.Parse(); +// +// Assert.AreEqual("", parser.Errors.ErrorOutput); +// CompilationUnit unit = parser.CompilationUnit; +// +// Assert.AreEqual(1, unit.Children.Count); +// Assert.IsTrue(unit.Children[0] is ImportsStatement); +// ImportsStatement ud = (ImportsStatement)unit.Children[0]; +// Assert.AreEqual(1, ud.ImportsClauses.Count); +// Assert.IsFalse(ud.ImportsClauses[0].IsAlias); +// Assert.IsTrue(ud.ImportsClauses[0].IsXml); +// +// Assert.AreEqual("xmlns", ud.ImportsClauses[0].XmlPrefix); +// Assert.AreEqual("http://icsharpcode.net/sharpdevelop/avalonedit", ud.ImportsClauses[0].Name); +// } +// +// [Test] +// public void VBNetXmlNamespaceSingleQuotedWithPrefixUsingTest() +// { +// string program = "Imports "; +// VBParser parser = ParserFactory.CreateParser(new StringReader(program)); +// parser.Parse(); +// +// Assert.AreEqual("", parser.Errors.ErrorOutput); +// CompilationUnit unit = parser.CompilationUnit; +// +// Assert.AreEqual(1, unit.Children.Count); +// Assert.IsTrue(unit.Children[0] is ImportsStatement); +// ImportsStatement ud = (ImportsStatement)unit.Children[0]; +// Assert.AreEqual(1, ud.ImportsClauses.Count); +// Assert.IsFalse(ud.ImportsClauses[0].IsAlias); +// Assert.IsTrue(ud.ImportsClauses[0].IsXml); +// +// Assert.AreEqual("xmlns:avalonedit", ud.ImportsClauses[0].XmlPrefix); +// Assert.AreEqual("http://icsharpcode.net/sharpdevelop/avalonedit", ud.ImportsClauses[0].Name); +// } +// #endregion + } +} diff --git a/ICSharpCode.NRefactory.VB.Tests/Parser/GlobalScope/NamespaceDeclarationTests.cs b/ICSharpCode.NRefactory.VB.Tests/Parser/GlobalScope/NamespaceDeclarationTests.cs index ca6dd92d7..33f994443 100644 --- a/ICSharpCode.NRefactory.VB.Tests/Parser/GlobalScope/NamespaceDeclarationTests.cs +++ b/ICSharpCode.NRefactory.VB.Tests/Parser/GlobalScope/NamespaceDeclarationTests.cs @@ -10,34 +10,34 @@ namespace ICSharpCode.NRefactory.VB.Tests.Ast [TestFixture] public class NamespaceDeclarationTests { - #region VB.NET - [Test] - public void VBNetSimpleNamespaceTest() - { - string program = "Namespace TestNamespace" + Environment.NewLine + - "End Namespace" +Environment.NewLine; - NamespaceDeclaration ns = ParseUtil.ParseGlobal(program); - Assert.AreEqual("TestNamespace", ns.Name); - } - - [Test] - public void VBNetJuggedNamespaceTest() - { - string program = "Namespace N1 'TestNamespace\n" + - " Namespace N2 ' Declares a namespace named N2 within N1.\n" + - " End Namespace\n" + - "End Namespace\n"; - - NamespaceDeclaration ns = ParseUtil.ParseGlobal(program); - - Assert.AreEqual("N1", ns.Name); - - Assert.IsTrue(ns.Children[0] is NamespaceDeclaration); - - ns = (NamespaceDeclaration)ns.Children[0]; - - Assert.AreEqual("N2", ns.Name); - } - #endregion +// #region VB.NET +// [Test] +// public void VBNetSimpleNamespaceTest() +// { +// string program = "Namespace TestNamespace" + Environment.NewLine + +// "End Namespace" +Environment.NewLine; +// NamespaceDeclaration ns = ParseUtil.ParseGlobal(program); +// Assert.AreEqual("TestNamespace", ns.Name); +// } +// +// [Test] +// public void VBNetJuggedNamespaceTest() +// { +// string program = "Namespace N1 'TestNamespace\n" + +// " Namespace N2 ' Declares a namespace named N2 within N1.\n" + +// " End Namespace\n" + +// "End Namespace\n"; +// +// NamespaceDeclaration ns = ParseUtil.ParseGlobal(program); +// +// Assert.AreEqual("N1", ns.Name); +// +// Assert.IsTrue(ns.Children[0] is NamespaceDeclaration); +// +// ns = (NamespaceDeclaration)ns.Children[0]; +// +// Assert.AreEqual("N2", ns.Name); +// } +// #endregion } } diff --git a/ICSharpCode.NRefactory.VB.Tests/Parser/GlobalScope/OptionDeclarationTests.cs b/ICSharpCode.NRefactory.VB.Tests/Parser/GlobalScope/OptionDeclarationTests.cs deleted file mode 100644 index cf1b9ba98..000000000 --- a/ICSharpCode.NRefactory.VB.Tests/Parser/GlobalScope/OptionDeclarationTests.cs +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using System; -using System.IO; -using ICSharpCode.NRefactory.VB.Parser; -using ICSharpCode.NRefactory.VB.Ast; -using NUnit.Framework; - -namespace ICSharpCode.NRefactory.VB.Tests.Ast -{ - [TestFixture] - public class OptionDeclarationTests - { - [Test] - public void VBNetStrictOptionDeclarationTest() - { - string program = "Option Strict On\n"; - OptionDeclaration opDec = ParseUtil.ParseGlobal(program); - Assert.AreEqual(OptionType.Strict, opDec.OptionType); - Assert.IsTrue(opDec.OptionValue); - } - - [Test] - public void VBNetExplicitOptionDeclarationTest() - { - string program = "Option Explicit Off\n"; - OptionDeclaration opDec = ParseUtil.ParseGlobal(program); - Assert.AreEqual(OptionType.Explicit, opDec.OptionType); - Assert.IsFalse(opDec.OptionValue, "Off option value excepted!"); - } - - [Test] - public void VBNetCompareBinaryOptionDeclarationTest() - { - string program = "Option Compare Binary\n"; - OptionDeclaration opDec = ParseUtil.ParseGlobal(program); - Assert.AreEqual(OptionType.CompareBinary, opDec.OptionType); - Assert.IsTrue(opDec.OptionValue); - } - - [Test] - public void VBNetCompareTextOptionDeclarationTest() - { - string program = "Option Compare Text\n"; - OptionDeclaration opDec = ParseUtil.ParseGlobal(program); - Assert.AreEqual(OptionType.CompareText, opDec.OptionType); - Assert.IsTrue(opDec.OptionValue); - } - - [Test] - public void VBNetInferOnOptionDeclarationTest() - { - string program = "Option Infer On\n"; - OptionDeclaration opDec = ParseUtil.ParseGlobal(program); - Assert.AreEqual(OptionType.Infer, opDec.OptionType); - Assert.IsTrue(opDec.OptionValue); - } - - [Test] - public void VBNetInferOffOptionDeclarationTest() - { - string program = "Option Infer\n"; - OptionDeclaration opDec = ParseUtil.ParseGlobal(program); - Assert.AreEqual(OptionType.Infer, opDec.OptionType); - Assert.IsTrue(opDec.OptionValue); - } - - [Test] - public void VBNetInferOptionDeclarationTest() - { - string program = "Option Infer\n"; - OptionDeclaration opDec = ParseUtil.ParseGlobal(program); - Assert.AreEqual(OptionType.Infer, opDec.OptionType); - Assert.IsTrue(opDec.OptionValue); - } - - [Test] - public void VBNetInvalidOptionDeclarationTest() - { - string program = "Option\n"; - VBParser parser = ParserFactory.CreateParser(new StringReader(program)); - parser.Parse(); - Assert.IsFalse(parser.Errors.ErrorOutput.Length == 0, "Expected errors, but operation completed successfully"); - } - } -} diff --git a/ICSharpCode.NRefactory.VB.Tests/Parser/GlobalScope/OptionStatementTests.cs b/ICSharpCode.NRefactory.VB.Tests/Parser/GlobalScope/OptionStatementTests.cs new file mode 100644 index 000000000..a3b28897a --- /dev/null +++ b/ICSharpCode.NRefactory.VB.Tests/Parser/GlobalScope/OptionStatementTests.cs @@ -0,0 +1,113 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; +using System.IO; +using ICSharpCode.NRefactory.VB.Parser; +using ICSharpCode.NRefactory.VB.Ast; +using NUnit.Framework; + +namespace ICSharpCode.NRefactory.VB.Tests.Ast +{ + [TestFixture] + public class OptionStatementTests + { + [Test] + public void InvalidOptionSyntax() + { + string program = "Option\n"; + ParseUtil.ParseGlobal(program, true); + } + + [Test] + public void StrictOption() + { + string program = "Option Strict On\n"; + + var node = new OptionStatement { + OptionType = OptionType.Strict, + OptionValue = OptionValue.On + }; + + ParseUtil.AssertGlobal(program, node); + } + + [Test] + public void ExplicitOption() + { + string program = "Option Explicit Off\n"; + + var node = new OptionStatement { + OptionType = OptionType.Explicit, + OptionValue = OptionValue.Off + }; + + ParseUtil.AssertGlobal(program, node); + } + + [Test] + public void CompareBinaryOption() + { + string program = "Option Compare Binary\n"; + + var node = new OptionStatement { + OptionType = OptionType.Compare, + OptionValue = OptionValue.Binary + }; + + ParseUtil.AssertGlobal(program, node); + } + + [Test] + public void CompareTextOption() + { + string program = "Option Compare Text\n"; + + var node = new OptionStatement { + OptionType = OptionType.Compare, + OptionValue = OptionValue.Text + }; + + ParseUtil.AssertGlobal(program, node); + } + + [Test] + public void InferOnOption() + { + string program = "Option Infer On\n"; + + var node = new OptionStatement { + OptionType = OptionType.Infer, + OptionValue = OptionValue.On + }; + + ParseUtil.AssertGlobal(program, node); + } + + [Test] + public void InferOffOption() + { + string program = "Option Infer Off\n"; + + var node = new OptionStatement { + OptionType = OptionType.Infer, + OptionValue = OptionValue.Off + }; + + ParseUtil.AssertGlobal(program, node); + } + + [Test] + public void InferOption() + { + string program = "Option Infer\n"; + + var node = new OptionStatement { + OptionType = OptionType.Infer, + OptionValue = OptionValue.On + }; + + ParseUtil.AssertGlobal(program, node); + } + } +} diff --git a/ICSharpCode.NRefactory.VB.Tests/Parser/GlobalScope/TypeDeclarationTests.cs b/ICSharpCode.NRefactory.VB.Tests/Parser/GlobalScope/TypeDeclarationTests.cs index 39e41144a..cc71f4c09 100644 --- a/ICSharpCode.NRefactory.VB.Tests/Parser/GlobalScope/TypeDeclarationTests.cs +++ b/ICSharpCode.NRefactory.VB.Tests/Parser/GlobalScope/TypeDeclarationTests.cs @@ -10,194 +10,194 @@ namespace ICSharpCode.NRefactory.VB.Tests.Ast [TestFixture] public class TypeDeclarationTests { - #region VB.NET - [Test] - public void VBNetSimpleClassTypeDeclarationTest() - { - string program = "Class TestClass\n" + - "End Class\n"; - TypeDeclaration td = ParseUtil.ParseGlobal(program); - - Assert.AreEqual("TestClass", td.Name); - Assert.AreEqual(ClassType.Class, td.Type); - Assert.AreEqual(1, td.StartLocation.Line, "start line"); - Assert.AreEqual(1, td.BodyStartLocation.Line, "bodystart line"); - Assert.AreEqual(16, td.BodyStartLocation.Column, "bodystart col"); - Assert.AreEqual(2, td.EndLocation.Line, "end line"); - Assert.AreEqual(10, td.EndLocation.Column, "end col"); - } - - [Test] - public void VBNetMissingBaseClassTest() - { - // SD2-1499: test that this invalid code doesn't crash - TypeDeclaration td = ParseUtil.ParseGlobal("public class test inherits", true); - Assert.AreEqual(0, td.BaseTypes.Count); - } - - [Test] - public void VBNetEnumWithBaseClassDeclarationTest() - { - string program = "Enum TestEnum As Byte\n" + - "End Enum\n"; - TypeDeclaration td = ParseUtil.ParseGlobal(program); - - Assert.AreEqual("TestEnum", td.Name); - Assert.AreEqual(ClassType.Enum, td.Type); - Assert.AreEqual("System.Byte", td.BaseTypes[0].Type); - Assert.AreEqual(0, td.Children.Count); - } - - [Test] - public void VBNetEnumOnSingleLine() - { - string program = "Enum TestEnum : A : B = 1 : C : End Enum"; - TypeDeclaration td = ParseUtil.ParseGlobal(program); - - Assert.AreEqual("TestEnum", td.Name); - Assert.AreEqual(ClassType.Enum, td.Type); - Assert.AreEqual(3, td.Children.Count); - } - - [Test] - public void VBNetEnumOnSingleLine2() - { - string program = "Enum TestEnum : A : : B = 1 :: C : End Enum"; - TypeDeclaration td = ParseUtil.ParseGlobal(program); - - Assert.AreEqual("TestEnum", td.Name); - Assert.AreEqual(ClassType.Enum, td.Type); - Assert.AreEqual(3, td.Children.Count); - } - - - [Test] - public void VBNetEnumWithSystemBaseClassDeclarationTest() - { - string program = "Enum TestEnum As System.UInt16\n" + - "End Enum\n"; - TypeDeclaration td = ParseUtil.ParseGlobal(program); - - Assert.AreEqual("TestEnum", td.Name); - Assert.AreEqual(ClassType.Enum, td.Type); - Assert.AreEqual("System.UInt16", td.BaseTypes[0].Type); - Assert.AreEqual(0, td.Children.Count); - } - - [Test] - public void VBNetSimpleClassTypeDeclarationWithoutLastNewLineTest() - { - string program = "Class TestClass\n" + - "End Class"; - TypeDeclaration td = ParseUtil.ParseGlobal(program); - - Assert.AreEqual("TestClass", td.Name); - Assert.AreEqual(ClassType.Class, td.Type); - Assert.AreEqual(1, td.StartLocation.Line, "start line"); - Assert.AreEqual(2, td.EndLocation.Line, "end line"); - } - - [Test] - public void VBNetSimpleClassTypeDeclarationWithColon() - { - string program = "Class TestClass\n" + - " : \n" + - "End Class"; - TypeDeclaration td = ParseUtil.ParseGlobal(program); - - Assert.AreEqual("TestClass", td.Name); - Assert.AreEqual(ClassType.Class, td.Type); - } - - [Test] - public void VBNetSimplePartialClassTypeDeclarationTest() - { - string program = "Partial Class TestClass\n" + - "End Class\n"; - TypeDeclaration td = ParseUtil.ParseGlobal(program); - - Assert.AreEqual("TestClass", td.Name); - Assert.AreEqual(ClassType.Class, td.Type); - Assert.AreEqual(Modifiers.Partial, td.Modifier); - } - - [Test] - public void VBNetPartialPublicClass() - { - string program = "Partial Public Class TestClass\nEnd Class\n"; - TypeDeclaration td = ParseUtil.ParseGlobal(program); - - Assert.AreEqual("TestClass", td.Name); - Assert.AreEqual(ClassType.Class, td.Type); - Assert.AreEqual(Modifiers.Partial | Modifiers.Public, td.Modifier); - } - - [Test] - public void VBNetGenericClassTypeDeclarationTest() - { - string declr = @" -Public Class Test(Of T) - -End Class -"; - TypeDeclaration td = ParseUtil.ParseGlobal(declr); - - Assert.AreEqual(ClassType.Class, td.Type); - Assert.AreEqual("Test", td.Name); - Assert.AreEqual(Modifiers.Public, td.Modifier); - Assert.AreEqual(0, td.BaseTypes.Count); - Assert.AreEqual(1, td.Templates.Count); - Assert.AreEqual("T", td.Templates[0].Name); - } - - [Test] - public void VBNetGenericClassWithConstraint() - { - string declr = @" -Public Class Test(Of T As IMyInterface) - -End Class -"; - TypeDeclaration td = ParseUtil.ParseGlobal(declr); - - Assert.AreEqual(ClassType.Class, td.Type); - Assert.AreEqual("Test", td.Name); - - Assert.AreEqual(1, td.Templates.Count); - Assert.AreEqual("T", td.Templates[0].Name); - Assert.AreEqual("IMyInterface", td.Templates[0].Bases[0].Type); - } - - [Test] - public void VBNetComplexGenericClassTypeDeclarationTest() - { - string declr = @" -Public Class Generic(Of T As MyNamespace.IMyInterface, S As {G(Of T()), IAnotherInterface}) - Implements System.IComparable - -End Class -"; - TypeDeclaration td = ParseUtil.ParseGlobal(declr); - - Assert.AreEqual(ClassType.Class, td.Type); - Assert.AreEqual("Generic", td.Name); - Assert.AreEqual(Modifiers.Public, td.Modifier); - Assert.AreEqual(1, td.BaseTypes.Count); - Assert.AreEqual("System.IComparable", td.BaseTypes[0].Type); - - Assert.AreEqual(2, td.Templates.Count); - Assert.AreEqual("T", td.Templates[0].Name); - Assert.AreEqual("MyNamespace.IMyInterface", td.Templates[0].Bases[0].Type); - - Assert.AreEqual("S", td.Templates[1].Name); - Assert.AreEqual(2, td.Templates[1].Bases.Count); - Assert.AreEqual("G", td.Templates[1].Bases[0].Type); - Assert.AreEqual(1, td.Templates[1].Bases[0].GenericTypes.Count); - Assert.IsTrue(td.Templates[1].Bases[0].GenericTypes[0].IsArrayType); - Assert.AreEqual("T", td.Templates[1].Bases[0].GenericTypes[0].Type); - Assert.AreEqual(new int[] {0}, td.Templates[1].Bases[0].GenericTypes[0].RankSpecifier); - Assert.AreEqual("IAnotherInterface", td.Templates[1].Bases[1].Type); - } - #endregion +// #region VB.NET +// [Test] +// public void VBNetSimpleClassTypeDeclarationTest() +// { +// string program = "Class TestClass\n" + +// "End Class\n"; +// TypeDeclaration td = ParseUtil.ParseGlobal(program); +// +// Assert.AreEqual("TestClass", td.Name); +// Assert.AreEqual(ClassType.Class, td.Type); +// Assert.AreEqual(1, td.StartLocation.Line, "start line"); +// Assert.AreEqual(1, td.BodyStartLocation.Line, "bodystart line"); +// Assert.AreEqual(16, td.BodyStartLocation.Column, "bodystart col"); +// Assert.AreEqual(2, td.EndLocation.Line, "end line"); +// Assert.AreEqual(10, td.EndLocation.Column, "end col"); +// } +// +// [Test] +// public void VBNetMissingBaseClassTest() +// { +// // SD2-1499: test that this invalid code doesn't crash +// TypeDeclaration td = ParseUtil.ParseGlobal("public class test inherits", true); +// Assert.AreEqual(0, td.BaseTypes.Count); +// } +// +// [Test] +// public void VBNetEnumWithBaseClassDeclarationTest() +// { +// string program = "Enum TestEnum As Byte\n" + +// "End Enum\n"; +// TypeDeclaration td = ParseUtil.ParseGlobal(program); +// +// Assert.AreEqual("TestEnum", td.Name); +// Assert.AreEqual(ClassType.Enum, td.Type); +// Assert.AreEqual("System.Byte", td.BaseTypes[0].Type); +// Assert.AreEqual(0, td.Children.Count); +// } +// +// [Test] +// public void VBNetEnumOnSingleLine() +// { +// string program = "Enum TestEnum : A : B = 1 : C : End Enum"; +// TypeDeclaration td = ParseUtil.ParseGlobal(program); +// +// Assert.AreEqual("TestEnum", td.Name); +// Assert.AreEqual(ClassType.Enum, td.Type); +// Assert.AreEqual(3, td.Children.Count); +// } +// +// [Test] +// public void VBNetEnumOnSingleLine2() +// { +// string program = "Enum TestEnum : A : : B = 1 :: C : End Enum"; +// TypeDeclaration td = ParseUtil.ParseGlobal(program); +// +// Assert.AreEqual("TestEnum", td.Name); +// Assert.AreEqual(ClassType.Enum, td.Type); +// Assert.AreEqual(3, td.Children.Count); +// } +// +// +// [Test] +// public void VBNetEnumWithSystemBaseClassDeclarationTest() +// { +// string program = "Enum TestEnum As System.UInt16\n" + +// "End Enum\n"; +// TypeDeclaration td = ParseUtil.ParseGlobal(program); +// +// Assert.AreEqual("TestEnum", td.Name); +// Assert.AreEqual(ClassType.Enum, td.Type); +// Assert.AreEqual("System.UInt16", td.BaseTypes[0].Type); +// Assert.AreEqual(0, td.Children.Count); +// } +// +// [Test] +// public void VBNetSimpleClassTypeDeclarationWithoutLastNewLineTest() +// { +// string program = "Class TestClass\n" + +// "End Class"; +// TypeDeclaration td = ParseUtil.ParseGlobal(program); +// +// Assert.AreEqual("TestClass", td.Name); +// Assert.AreEqual(ClassType.Class, td.Type); +// Assert.AreEqual(1, td.StartLocation.Line, "start line"); +// Assert.AreEqual(2, td.EndLocation.Line, "end line"); +// } +// +// [Test] +// public void VBNetSimpleClassTypeDeclarationWithColon() +// { +// string program = "Class TestClass\n" + +// " : \n" + +// "End Class"; +// TypeDeclaration td = ParseUtil.ParseGlobal(program); +// +// Assert.AreEqual("TestClass", td.Name); +// Assert.AreEqual(ClassType.Class, td.Type); +// } +// +// [Test] +// public void VBNetSimplePartialClassTypeDeclarationTest() +// { +// string program = "Partial Class TestClass\n" + +// "End Class\n"; +// TypeDeclaration td = ParseUtil.ParseGlobal(program); +// +// Assert.AreEqual("TestClass", td.Name); +// Assert.AreEqual(ClassType.Class, td.Type); +// Assert.AreEqual(Modifiers.Partial, td.Modifier); +// } +// +// [Test] +// public void VBNetPartialPublicClass() +// { +// string program = "Partial Public Class TestClass\nEnd Class\n"; +// TypeDeclaration td = ParseUtil.ParseGlobal(program); +// +// Assert.AreEqual("TestClass", td.Name); +// Assert.AreEqual(ClassType.Class, td.Type); +// Assert.AreEqual(Modifiers.Partial | Modifiers.Public, td.Modifier); +// } +// +// [Test] +// public void VBNetGenericClassTypeDeclarationTest() +// { +// string declr = @" +//Public Class Test(Of T) +// +//End Class +//"; +// TypeDeclaration td = ParseUtil.ParseGlobal(declr); +// +// Assert.AreEqual(ClassType.Class, td.Type); +// Assert.AreEqual("Test", td.Name); +// Assert.AreEqual(Modifiers.Public, td.Modifier); +// Assert.AreEqual(0, td.BaseTypes.Count); +// Assert.AreEqual(1, td.Templates.Count); +// Assert.AreEqual("T", td.Templates[0].Name); +// } +// +// [Test] +// public void VBNetGenericClassWithConstraint() +// { +// string declr = @" +//Public Class Test(Of T As IMyInterface) +// +//End Class +//"; +// TypeDeclaration td = ParseUtil.ParseGlobal(declr); +// +// Assert.AreEqual(ClassType.Class, td.Type); +// Assert.AreEqual("Test", td.Name); +// +// Assert.AreEqual(1, td.Templates.Count); +// Assert.AreEqual("T", td.Templates[0].Name); +// Assert.AreEqual("IMyInterface", td.Templates[0].Bases[0].Type); +// } +// +// [Test] +// public void VBNetComplexGenericClassTypeDeclarationTest() +// { +// string declr = @" +//Public Class Generic(Of T As MyNamespace.IMyInterface, S As {G(Of T()), IAnotherInterface}) +// Implements System.IComparable +// +//End Class +//"; +// TypeDeclaration td = ParseUtil.ParseGlobal(declr); +// +// Assert.AreEqual(ClassType.Class, td.Type); +// Assert.AreEqual("Generic", td.Name); +// Assert.AreEqual(Modifiers.Public, td.Modifier); +// Assert.AreEqual(1, td.BaseTypes.Count); +// Assert.AreEqual("System.IComparable", td.BaseTypes[0].Type); +// +// Assert.AreEqual(2, td.Templates.Count); +// Assert.AreEqual("T", td.Templates[0].Name); +// Assert.AreEqual("MyNamespace.IMyInterface", td.Templates[0].Bases[0].Type); +// +// Assert.AreEqual("S", td.Templates[1].Name); +// Assert.AreEqual(2, td.Templates[1].Bases.Count); +// Assert.AreEqual("G", td.Templates[1].Bases[0].Type); +// Assert.AreEqual(1, td.Templates[1].Bases[0].GenericTypes.Count); +// Assert.IsTrue(td.Templates[1].Bases[0].GenericTypes[0].IsArrayType); +// Assert.AreEqual("T", td.Templates[1].Bases[0].GenericTypes[0].Type); +// Assert.AreEqual(new int[] {0}, td.Templates[1].Bases[0].GenericTypes[0].RankSpecifier); +// Assert.AreEqual("IAnotherInterface", td.Templates[1].Bases[1].Type); +// } +// #endregion } } diff --git a/ICSharpCode.NRefactory.VB.Tests/Parser/GlobalScope/UsingDeclarationTests.cs b/ICSharpCode.NRefactory.VB.Tests/Parser/GlobalScope/UsingDeclarationTests.cs deleted file mode 100644 index 83681327c..000000000 --- a/ICSharpCode.NRefactory.VB.Tests/Parser/GlobalScope/UsingDeclarationTests.cs +++ /dev/null @@ -1,207 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using System; -using System.IO; -using ICSharpCode.NRefactory.VB.Parser; -using ICSharpCode.NRefactory.VB.Ast; -using NUnit.Framework; - -namespace ICSharpCode.NRefactory.VB.Tests.Ast -{ - [TestFixture] - public class UsingDeclarationTests - { - void CheckTwoSimpleUsings(CompilationUnit u) - { - Assert.AreEqual(2, u.Children.Count); - Assert.IsTrue(u.Children[0] is UsingDeclaration); - UsingDeclaration ud = (UsingDeclaration)u.Children[0]; - Assert.AreEqual(1, ud.Usings.Count); - Assert.IsTrue(!ud.Usings[0].IsAlias); - Assert.AreEqual("System", ud.Usings[0].Name); - - - Assert.IsTrue(u.Children[1] is UsingDeclaration); - ud = (UsingDeclaration)u.Children[1]; - Assert.AreEqual(1, ud.Usings.Count); - Assert.IsTrue(!ud.Usings[0].IsAlias); - Assert.AreEqual("My.Name.Space", ud.Usings[0].Name); - } - - void CheckAliases(CompilationUnit u) - { - Assert.AreEqual(3, u.Children.Count); - - Assert.IsTrue(u.Children[0] is UsingDeclaration); - UsingDeclaration ud = (UsingDeclaration)u.Children[0]; - Assert.AreEqual(1, ud.Usings.Count); - Assert.IsTrue(((Using)ud.Usings[0]).IsAlias); - Assert.AreEqual("TESTME", ud.Usings[0].Name); - Assert.AreEqual("System", ud.Usings[0].Alias.Type); - - Assert.IsTrue(u.Children[1] is UsingDeclaration); - ud = (UsingDeclaration)u.Children[1]; - Assert.AreEqual(1, ud.Usings.Count); - Assert.IsTrue(((Using)ud.Usings[0]).IsAlias); - Assert.AreEqual("myAlias", ud.Usings[0].Name); - Assert.AreEqual("My.Name.Space", ud.Usings[0].Alias.Type); - - Assert.IsTrue(u.Children[2] is UsingDeclaration); - ud = (UsingDeclaration)u.Children[2]; - Assert.AreEqual(1, ud.Usings.Count); - Assert.IsTrue(((Using)ud.Usings[0]).IsAlias); - Assert.AreEqual("StringCollection", ud.Usings[0].Name); - Assert.AreEqual("System.Collections.Generic.List", ud.Usings[0].Alias.Type); - Assert.AreEqual("System.String", ud.Usings[0].Alias.GenericTypes[0].Type); - } - - #region VB.NET - [Test] - public void VBNetWrongUsingTest() - { - string program = "Imports\n"; - VBParser parser = ParserFactory.CreateParser(new StringReader(program)); - parser.Parse(); - Assert.IsTrue(parser.Errors.Count > 0); - UsingDeclaration u = (UsingDeclaration)parser.CompilationUnit.Children[0]; - foreach (Using us in u.Usings) { - Assert.IsNotNull(us); - } - } - - [Test] - public void VBNetWrongUsing2Test() - { - string program = "Imports ,\n"; - VBParser parser = ParserFactory.CreateParser(new StringReader(program)); - parser.Parse(); - Assert.IsTrue(parser.Errors.Count > 0); - UsingDeclaration u = (UsingDeclaration)parser.CompilationUnit.Children[0]; - foreach (Using us in u.Usings) { - Assert.IsNotNull(us); - } - } - - [Test] - public void VBNetDeclarationTest() - { - string program = "Imports System\n" + - "Imports My.Name.Space\n"; - VBParser parser = ParserFactory.CreateParser(new StringReader(program)); - parser.Parse(); - - Assert.AreEqual("", parser.Errors.ErrorOutput); - CheckTwoSimpleUsings(parser.CompilationUnit); - } - - [Test] - public void VBNetUsingAliasDeclarationTest() - { - string program = "Imports TESTME=System\n" + - "Imports myAlias=My.Name.Space\n" + - "Imports StringCollection = System.Collections.Generic.List(Of string)\n"; - VBParser parser = ParserFactory.CreateParser(new StringReader(program)); - parser.Parse(); - - Assert.AreEqual("", parser.Errors.ErrorOutput); - CheckAliases(parser.CompilationUnit); - } - - [Test] - public void VBNetComplexUsingAliasDeclarationTest() - { - string program = "Imports NS1, AL=NS2, NS3, AL2=NS4, NS5\n"; - VBParser parser = ParserFactory.CreateParser(new StringReader(program)); - parser.Parse(); - - Assert.AreEqual("", parser.Errors.ErrorOutput); - // TODO : Extend test ... - } - - [Test] - public void VBNetXmlNamespaceUsingTest() - { - string program = "Imports "; - VBParser parser = ParserFactory.CreateParser(new StringReader(program)); - parser.Parse(); - - Assert.AreEqual("", parser.Errors.ErrorOutput); - CompilationUnit unit = parser.CompilationUnit; - - Assert.AreEqual(1, unit.Children.Count); - Assert.IsTrue(unit.Children[0] is UsingDeclaration); - UsingDeclaration ud = (UsingDeclaration)unit.Children[0]; - Assert.AreEqual(1, ud.Usings.Count); - Assert.IsFalse(ud.Usings[0].IsAlias); - Assert.IsTrue(ud.Usings[0].IsXml); - - Assert.AreEqual("xmlns", ud.Usings[0].XmlPrefix); - Assert.AreEqual("http://icsharpcode.net/sharpdevelop/avalonedit", ud.Usings[0].Name); - } - - [Test] - public void VBNetXmlNamespaceWithPrefixUsingTest() - { - string program = "Imports "; - VBParser parser = ParserFactory.CreateParser(new StringReader(program)); - parser.Parse(); - - Assert.AreEqual("", parser.Errors.ErrorOutput); - CompilationUnit unit = parser.CompilationUnit; - - Assert.AreEqual(1, unit.Children.Count); - Assert.IsTrue(unit.Children[0] is UsingDeclaration); - UsingDeclaration ud = (UsingDeclaration)unit.Children[0]; - Assert.AreEqual(1, ud.Usings.Count); - Assert.IsFalse(ud.Usings[0].IsAlias); - Assert.IsTrue(ud.Usings[0].IsXml); - - Assert.AreEqual("xmlns:avalonedit", ud.Usings[0].XmlPrefix); - Assert.AreEqual("http://icsharpcode.net/sharpdevelop/avalonedit", ud.Usings[0].Name); - } - - [Test] - public void VBNetXmlNamespaceSingleQuotedUsingTest() - { - string program = "Imports "; - VBParser parser = ParserFactory.CreateParser(new StringReader(program)); - parser.Parse(); - - Assert.AreEqual("", parser.Errors.ErrorOutput); - CompilationUnit unit = parser.CompilationUnit; - - Assert.AreEqual(1, unit.Children.Count); - Assert.IsTrue(unit.Children[0] is UsingDeclaration); - UsingDeclaration ud = (UsingDeclaration)unit.Children[0]; - Assert.AreEqual(1, ud.Usings.Count); - Assert.IsFalse(ud.Usings[0].IsAlias); - Assert.IsTrue(ud.Usings[0].IsXml); - - Assert.AreEqual("xmlns", ud.Usings[0].XmlPrefix); - Assert.AreEqual("http://icsharpcode.net/sharpdevelop/avalonedit", ud.Usings[0].Name); - } - - [Test] - public void VBNetXmlNamespaceSingleQuotedWithPrefixUsingTest() - { - string program = "Imports "; - VBParser parser = ParserFactory.CreateParser(new StringReader(program)); - parser.Parse(); - - Assert.AreEqual("", parser.Errors.ErrorOutput); - CompilationUnit unit = parser.CompilationUnit; - - Assert.AreEqual(1, unit.Children.Count); - Assert.IsTrue(unit.Children[0] is UsingDeclaration); - UsingDeclaration ud = (UsingDeclaration)unit.Children[0]; - Assert.AreEqual(1, ud.Usings.Count); - Assert.IsFalse(ud.Usings[0].IsAlias); - Assert.IsTrue(ud.Usings[0].IsXml); - - Assert.AreEqual("xmlns:avalonedit", ud.Usings[0].XmlPrefix); - Assert.AreEqual("http://icsharpcode.net/sharpdevelop/avalonedit", ud.Usings[0].Name); - } - #endregion - } -} diff --git a/ICSharpCode.NRefactory.VB.Tests/Parser/LocationAssignmentCheckVisitor.cs b/ICSharpCode.NRefactory.VB.Tests/Parser/LocationAssignmentCheckVisitor.cs deleted file mode 100644 index 50f72fd0d..000000000 --- a/ICSharpCode.NRefactory.VB.Tests/Parser/LocationAssignmentCheckVisitor.cs +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using System; -using ICSharpCode.NRefactory.VB.Ast; -using ICSharpCode.NRefactory.VB.Visitors; -using NUnit.Framework; - -namespace ICSharpCode.NRefactory.VB.Tests.Ast -{ - public class LocationAssignmentCheckVisitor : NodeTrackingAstVisitor - { - protected override void BeginVisit(INode node) - { - if (node is CompilationUnit) - return; - if (node is INullable && ((INullable)node).IsNull) - return; - if (node is TypeReference) - return; - - Assert.IsFalse(node.StartLocation.IsEmpty, "StartLocation of {0}", node); - Assert.IsFalse(node.EndLocation.IsEmpty, "EndLocation of {0}", node); - } - } -} diff --git a/ICSharpCode.NRefactory.VB.Tests/Parser/ParseUtil.cs b/ICSharpCode.NRefactory.VB.Tests/Parser/ParseUtil.cs index 4ed9d2197..5704c031e 100644 --- a/ICSharpCode.NRefactory.VB.Tests/Parser/ParseUtil.cs +++ b/ICSharpCode.NRefactory.VB.Tests/Parser/ParseUtil.cs @@ -3,90 +3,106 @@ using System; using System.IO; -using ICSharpCode.NRefactory.VB.Parser; +using System.Linq; + +using ICSharpCode.NRefactory.PatternMatching; using ICSharpCode.NRefactory.VB.Ast; +using ICSharpCode.NRefactory.VB.Parser; using NUnit.Framework; namespace ICSharpCode.NRefactory.VB.Tests.Ast { public class ParseUtil { - public static T ParseGlobal(string program) where T : INode - { - return ParseGlobal(program, false); - } - - public static T ParseGlobal(string program, bool expectErrors) where T : INode + public static T ParseGlobal(string code, bool expectErrors = false) where T : AstNode { - VBParser parser = ParserFactory.CreateParser(new StringReader(program)); - parser.Parse(); + VBParser parser = new VBParser(); + CompilationUnit cu = parser.Parse(new StringReader(code)); - if (expectErrors) - Assert.IsFalse(parser.Errors.ErrorOutput.Length == 0, "Expected errors, but operation completed successfully"); - else - Assert.AreEqual("", parser.Errors.ErrorOutput); - - Assert.IsNotNull(parser.CompilationUnit); - Assert.IsNotNull(parser.CompilationUnit.Children); - Assert.IsNotNull(parser.CompilationUnit.Children[0]); - Assert.AreEqual(1, parser.CompilationUnit.Children.Count); + Assert.AreEqual(expectErrors, parser.HasErrors, "HasErrors"); + AstNode node = cu.Children.Single(); Type type = typeof(T); - Assert.IsTrue(type.IsAssignableFrom(parser.CompilationUnit.Children[0].GetType()), String.Format("Parsed expression was {0} instead of {1} ({2})", parser.CompilationUnit.Children[0].GetType(), type, parser.CompilationUnit.Children[0])); - - parser.CompilationUnit.AcceptVisitor(new CheckParentVisitor(), null); - // TODO fix Locations -// parser.CompilationUnit.AcceptChildren(new LocationAssignmentCheckVisitor(), null); - - return (T)parser.CompilationUnit.Children[0]; + Assert.IsTrue(type.IsAssignableFrom(node.GetType()), String.Format("Parsed node was {0} instead of {1} ({2})", node.GetType(), type, node)); + return (T)node; } - public static T ParseTypeMember(string typeMember, bool expectErrors) where T : INode + public static void AssertGlobal(string code, AstNode expectedNode) { - TypeDeclaration td = ParseGlobal("Class TestClass\n " + typeMember + "\n End Class\n", expectErrors); - Assert.AreEqual(1, td.Children.Count); - Type type = typeof(T); - Assert.IsTrue(type.IsAssignableFrom(td.Children[0].GetType()), String.Format("Parsed expression was {0} instead of {1} ({2})", td.GetType(), type, td)); - return (T)td.Children[0]; + var node = ParseGlobal(code); + if (!expectedNode.IsMatch(node)) { + Assert.Fail("Expected '{0}' but was '{1}'", ToVB(expectedNode), ToVB(node)); + } } - public static T ParseTypeMember(string typeMember) where T : INode - { - return ParseTypeMember(typeMember, false); - } +// public static T ParseStatement(string stmt, bool expectErrors = false) where T : AstNode +// { +// VBParser parser = new VBParser(); +// var statements = parser.ParseStatements(new StringReader(stmt)); +// +// Assert.AreEqual(expectErrors, parser.HasErrors, "HasErrors"); +// +// AstNode statement = statements.Single(); +// Type type = typeof(T); +// Assert.IsTrue(type.IsAssignableFrom(statement.GetType()), String.Format("Parsed statement was {0} instead of {1} ({2})", statement.GetType(), type, statement)); +// return (T)statement; +// } +// +// public static void AssertStatement(string code, VB.Ast.Statement expectedStmt) +// { +// var stmt = ParseStatement(code); +// if (!expectedStmt.IsMatch(stmt)) { +// Assert.Fail("Expected '{0}' but was '{1}'", ToCSharp(expectedStmt), ToCSharp(stmt)); +// } +// } +// +// public static T ParseExpression(string expr, bool expectErrors = false) where T : AstNode +// { +// VBParser parser = new VBParser(); +// AstNode parsedExpression = parser.ParseExpression(new StringReader(expr)); +// +// Assert.AreEqual(expectErrors, parser.HasErrors, "HasErrors"); +// if (expectErrors && parsedExpression == null) +// return default (T); +// Type type = typeof(T); +// Assert.IsTrue(type.IsAssignableFrom(parsedExpression.GetType()), String.Format("Parsed expression was {0} instead of {1} ({2})", parsedExpression.GetType(), type, parsedExpression)); +// return (T)parsedExpression; +// } +// +// public static void AssertExpression(string code, VB.Ast.Expression expectedExpr) +// { +// var expr = ParseExpression(code); +// if (!expectedExpr.IsMatch(expr)) { +// Assert.Fail("Expected '{0}' but was '{1}'", ToCSharp(expectedExpr), ToCSharp(expr)); +// } +// } +// +// public static T ParseTypeMember(string expr, bool expectErrors = false) where T : AttributedNode +// { +// VBParser parser = new VBParser(); +// var members = parser.ParseTypeMembers(new StringReader(expr)); +// +// Assert.AreEqual(expectErrors, parser.HasErrors, "HasErrors"); +// +// AttributedNode m = members.Single(); +// Type type = typeof(T); +// Assert.IsTrue(type.IsAssignableFrom(m.GetType()), String.Format("Parsed member was {0} instead of {1} ({2})", m.GetType(), type, m)); +// return (T)m; +// } +// +// public static void AssertTypeMember(string code, VB.Ast.AttributedNode expectedMember) +// { +// var member = ParseTypeMember(code); +// if (!expectedMember.IsMatch(member)) { +// Assert.Fail("Expected '{0}' but was '{1}'", ToVB(expectedMember), ToVB(member)); +// } +// } - public static T ParseStatement(string statement, bool expectErrors) where T : INode + static string ToVB(AstNode node) { - MethodDeclaration md = ParseTypeMember("Sub A()\n " + statement + "\nEnd Sub\n", expectErrors); - Assert.AreEqual(1, md.Body.Children.Count); - Type type = typeof(T); - Assert.IsTrue(type.IsAssignableFrom(md.Body.Children[0].GetType()), String.Format("Parsed expression was {0} instead of {1} ({2})", md.GetType(), type, md)); - return (T)md.Body.Children[0]; - } - - public static T ParseStatement(string statement) where T : INode - { - return ParseStatement(statement, false); - } - - public static T ParseExpression(string expr) where T : INode - { - return ParseExpression(expr, false); - } - - public static T ParseExpression(string expr, bool expectErrors) where T : INode - { - VBParser parser = ParserFactory.CreateParser(new StringReader(expr)); - INode parsedExpression = parser.ParseExpression(); - if (expectErrors) - Assert.IsFalse(parser.Errors.ErrorOutput.Length == 0, "Expected errors, but operation completed successfully"); - else - Assert.AreEqual("", parser.Errors.ErrorOutput); - // TODO fix Locations -// parsedExpression.AcceptVisitor(new LocationAssignmentCheckVisitor(), null); - Type type = typeof(T); - Assert.IsTrue(type.IsAssignableFrom(parsedExpression.GetType()), String.Format("Parsed expression was {0} instead of {1} ({2})", parsedExpression.GetType(), type, parsedExpression)); - return (T)parsedExpression; + StringWriter w = new StringWriter(); + node.AcceptVisitor(new OutputVisitor(w, new VBFormattingOptions()), null); + return w.ToString(); } } } diff --git a/ICSharpCode.NRefactory.VB.Tests/Parser/SnippetParserTests.cs b/ICSharpCode.NRefactory.VB.Tests/Parser/SnippetParserTests.cs index 40da76cae..bf64c982b 100644 --- a/ICSharpCode.NRefactory.VB.Tests/Parser/SnippetParserTests.cs +++ b/ICSharpCode.NRefactory.VB.Tests/Parser/SnippetParserTests.cs @@ -10,13 +10,13 @@ namespace ICSharpCode.NRefactory.VB.Tests [TestFixture] public class SnippetParserTests { - [Test] - public void InvalidExpressionSyntax() - { - // SD2-1584: ensure we don't crash on this invalid VB code - SnippetParser parser = new SnippetParser(); - INode node = parser.Parse("i == 5"); - Assert.IsTrue(parser.Errors.Count > 0); - } +// [Test] +// public void InvalidExpressionSyntax() +// { +// // SD2-1584: ensure we don't crash on this invalid VB code +// SnippetParser parser = new SnippetParser(); +// INode node = parser.Parse("i == 5"); +// Assert.IsTrue(parser.Errors.Count > 0); +// } } } diff --git a/ICSharpCode.NRefactory.VB.Tests/Parser/Statements/SwitchStatementTests.cs b/ICSharpCode.NRefactory.VB.Tests/Parser/Statements/SwitchStatementTests.cs index c7dcb48fa..39f4a47a8 100644 --- a/ICSharpCode.NRefactory.VB.Tests/Parser/Statements/SwitchStatementTests.cs +++ b/ICSharpCode.NRefactory.VB.Tests/Parser/Statements/SwitchStatementTests.cs @@ -17,7 +17,7 @@ namespace ICSharpCode.NRefactory.VB.Tests.Ast public void VBSwitchStatementTest() { SwitchStatement switchStmt = ParseUtil.ParseStatement("Select Case a\n Case 4, 5\n Case 6\n Case Else\n End Select"); - Assert.AreEqual("a", ((IdentifierExpression)switchStmt.SwitchExpression).Identifier); + Assert.AreEqual("a", ((SimpleNameExpression)switchStmt.SwitchExpression).Identifier); // TODO: Extend test } @@ -25,7 +25,7 @@ namespace ICSharpCode.NRefactory.VB.Tests.Ast public void InvalidVBSwitchStatementTest() { SwitchStatement switchStmt = ParseUtil.ParseStatement("Select Case a\n Case \n End Select", true); - Assert.AreEqual("a", ((IdentifierExpression)switchStmt.SwitchExpression).Identifier); + Assert.AreEqual("a", ((SimpleNameExpression)switchStmt.SwitchExpression).Identifier); SwitchSection sec = switchStmt.SwitchSections[0]; Assert.AreEqual(0, sec.SwitchLabels.Count); } diff --git a/ICSharpCode.NRefactory.VB/Ast/AbstractNode.cs b/ICSharpCode.NRefactory.VB/Ast/AbstractNode.cs deleted file mode 100644 index 2347f4f05..000000000 --- a/ICSharpCode.NRefactory.VB/Ast/AbstractNode.cs +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using System; -using System.Collections; -using System.Collections.Generic; -using System.Diagnostics; -using System.Text; - -namespace ICSharpCode.NRefactory.VB.Ast -{ - public abstract class AbstractNode : INode - { - List children = new List(); - - public INode Parent { get; set; } - public Location StartLocation { get; set; } - public Location EndLocation { get; set; } - public object UserData { get; set; } - - public List Children { - get { - return children; - } - set { - Debug.Assert(value != null); - children = value; - } - } - - public virtual void AddChild(INode childNode) - { - Debug.Assert(childNode != null); - childNode.Parent = this; - children.Add(childNode); - } - - public abstract object AcceptVisitor(IAstVisitor visitor, object data); - - public virtual object AcceptChildren(IAstVisitor visitor, object data) - { - foreach (INode child in children) { - Debug.Assert(child != null); - child.AcceptVisitor(visitor, data); - } - return data; - } - - public static string GetCollectionString(ICollection collection) - { - StringBuilder output = new StringBuilder(); - output.Append('{'); - - if (collection != null) { - IEnumerator en = collection.GetEnumerator(); - bool isFirst = true; - while (en.MoveNext()) { - if (!isFirst) { - output.Append(", "); - } else { - isFirst = false; - } - output.Append(en.Current == null ? "" : en.Current.ToString()); - } - } else { - return "null"; - } - - output.Append('}'); - return output.ToString(); - } - } -} diff --git a/ICSharpCode.NRefactory.VB/Ast/AstLocation.cs b/ICSharpCode.NRefactory.VB/Ast/AstLocation.cs new file mode 100644 index 000000000..4a3a1bc68 --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/AstLocation.cs @@ -0,0 +1,137 @@ +// +// DomLocation.cs +// +// Author: +// Mike Krüger +// +// Copyright (C) 2008 Novell, Inc (http://www.novell.com) +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +using System; + +namespace ICSharpCode.NRefactory.VB +{ + [Serializable] + public struct AstLocation : IComparable, IEquatable + { + public static readonly AstLocation Empty = new AstLocation(0, 0); + + readonly int line, column; + + public AstLocation (int line, int column) + { + this.line = line; + this.column = column; + } + + public bool IsEmpty { + get { + return line <= 0; + } + } + + public int Line { + get { return line; } + } + + public int Column { + get { return column; } + } + + public override bool Equals (object obj) + { + if (!(obj is AstLocation)) + return false; + return (AstLocation)obj == this; + } + + public override int GetHashCode () + { + unchecked { + return line + column * 5000; + } + } + + public bool Equals (AstLocation other) + { + return other == this; + } + + public int CompareTo (AstLocation other) + { + if (this == other) + return 0; + if (this < other) + return -1; + return 1; + } + + public override string ToString () + { + return String.Format ("(Line {0}, Column {1})", Line, Column); + } + + public static AstLocation FromInvariantString (string invariantString) + { + if (string.Equals(invariantString, "EMPTY", StringComparison.OrdinalIgnoreCase)) + return AstLocation.Empty; + string[] splits = invariantString.Split (',', '/'); + if (splits.Length == 2) + return new AstLocation (Int32.Parse (splits[0]), Int32.Parse (splits[1])); + return AstLocation.Empty; + } + + public string ToInvariantString () + { + if (IsEmpty) + return "Empty"; + return String.Format ("{0}/{1}", line, column); + } + + public static bool operator==(AstLocation left, AstLocation right) + { + return left.line == right.line && left.column == right.column; + } + + public static bool operator!=(AstLocation left, AstLocation right) + { + return left.line != right.line || left.column != right.column; + } + + public static bool operator<(AstLocation left, AstLocation right) + { + return left.line < right.line || left.line == right.line && left.column < right.column; + } + public static bool operator>(AstLocation left, AstLocation right) + { + return left.line > right.line || left.line == right.line && left.column > right.column; + } + public static bool operator<=(AstLocation left, AstLocation right) + { + return !(left > right); + } + public static bool operator>=(AstLocation left, AstLocation right) + { + return !(left < right); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/AstNode.cs b/ICSharpCode.NRefactory.VB/Ast/AstNode.cs new file mode 100644 index 000000000..d66abad92 --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/AstNode.cs @@ -0,0 +1,730 @@ +// +// AstNode.cs +// +// Author: +// Mike Krüger +// +// Copyright (c) 2009 Novell, Inc (http://www.novell.com) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Threading; +using ICSharpCode.NRefactory.PatternMatching; +using ICSharpCode.NRefactory.VB.Ast; + +namespace ICSharpCode.NRefactory.VB +{ + public abstract class AstNode : PatternMatching.INode + { + #region Null + public static readonly AstNode Null = new NullAstNode (); + + sealed class NullAstNode : AstNode + { + public override bool IsNull { + get { + return true; + } + } + + public override S AcceptVisitor (IAstVisitor visitor, T data) + { + return default (S); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + return other == null || other.IsNull; + } + } + #endregion + + #region PatternPlaceholder + public static implicit operator AstNode(PatternMatching.Pattern pattern) + { + return pattern != null ? new PatternPlaceholder(pattern) : null; + } + + sealed class PatternPlaceholder : AstNode, PatternMatching.INode + { + readonly PatternMatching.Pattern child; + + public PatternPlaceholder(PatternMatching.Pattern child) + { + this.child = child; + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitPatternPlaceholder(this, child, data); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + return child.DoMatch(other, match); + } + + bool PatternMatching.INode.DoMatchCollection(Role role, PatternMatching.INode pos, PatternMatching.Match match, PatternMatching.BacktrackingInfo backtrackingInfo) + { + return child.DoMatchCollection(role, pos, match, backtrackingInfo); + } + } + #endregion + + AstNode parent; + AstNode prevSibling; + AstNode nextSibling; + AstNode firstChild; + AstNode lastChild; + Role role = RootRole; + + public virtual bool IsNull { + get { + return false; + } + } + + public virtual AstLocation StartLocation { + get { + var child = firstChild; + if (child == null) + return AstLocation.Empty; + return child.StartLocation; + } + } + + public virtual AstLocation EndLocation { + get { + var child = lastChild; + if (child == null) + return AstLocation.Empty; + return child.EndLocation; + } + } + + public AstNode Parent { + get { return parent; } + } + + public Role Role { + get { return role; } + } + + public AstNode NextSibling { + get { return nextSibling; } + } + + public AstNode PrevSibling { + get { return prevSibling; } + } + + public AstNode FirstChild { + get { return firstChild; } + } + + public AstNode LastChild { + get { return lastChild; } + } + + public IEnumerable Children { + get { + AstNode next; + for (AstNode cur = firstChild; cur != null; cur = next) { + Debug.Assert(cur.parent == this); + // Remember next before yielding cur. + // This allows removing/replacing nodes while iterating through the list. + next = cur.nextSibling; + yield return cur; + } + } + } + + /// + /// Gets the ancestors of this node (excluding this node itself) + /// + public IEnumerable Ancestors { + get { + for (AstNode cur = parent; cur != null; cur = cur.parent) { + yield return cur; + } + } + } + + /// + /// Gets all descendants of this node (excluding this node itself). + /// + public IEnumerable Descendants { + get { + return Utils.TreeTraversal.PreOrder(this.Children, n => n.Children); + } + } + + /// + /// Gets all descendants of this node (including this node itself). + /// + public IEnumerable DescendantsAndSelf { + get { + return Utils.TreeTraversal.PreOrder(this, n => n.Children); + } + } + + /// + /// Gets the first child with the specified role. + /// Returns the role's null object if the child is not found. + /// + public T GetChildByRole(Role role) where T : AstNode + { + if (role == null) + throw new ArgumentNullException("role"); + for (var cur = firstChild; cur != null; cur = cur.nextSibling) { + if (cur.role == role) + return (T)cur; + } + return role.NullObject; + } + + public AstNodeCollection GetChildrenByRole(Role role) where T : AstNode + { + return new AstNodeCollection(this, role); + } + + protected void SetChildByRole(Role role, T newChild) where T : AstNode + { + AstNode oldChild = GetChildByRole(role); + if (oldChild.IsNull) + AddChild(newChild, role); + else + oldChild.ReplaceWith(newChild); + } + + public void AddChild(T child, Role role) where T : AstNode + { + if (role == null) + throw new ArgumentNullException("role"); + if (child == null || child.IsNull) + return; + if (this.IsNull) + throw new InvalidOperationException("Cannot add children to null nodes"); + if (child.parent != null) + throw new ArgumentException ("Node is already used in another tree.", "child"); + AddChildUnsafe(child, role); + } + + internal void AddChildUntyped(AstNode child, Role role) + { + if (role == null) + throw new ArgumentNullException("role"); + if (child == null || child.IsNull) + return; + if (this.IsNull) + throw new InvalidOperationException("Cannot add children to null nodes"); + if (child.parent != null) + throw new ArgumentException ("Node is already used in another tree.", "child"); + AddChildUnsafe(child, role); + } + + /// + /// Adds a child without performing any safety checks. + /// + void AddChildUnsafe(AstNode child, Role role) + { + child.parent = this; + child.role = role; + if (firstChild == null) { + lastChild = firstChild = child; + } else { + lastChild.nextSibling = child; + child.prevSibling = lastChild; + lastChild = child; + } + } + + public void InsertChildBefore(AstNode nextSibling, T child, Role role) where T : AstNode + { + if (role == null) + throw new ArgumentNullException("role"); + if (nextSibling == null || nextSibling.IsNull) { + AddChild(child, role); + return; + } + + if (child == null || child.IsNull) + return; + if (child.parent != null) + throw new ArgumentException ("Node is already used in another tree.", "child"); + if (nextSibling.parent != this) + throw new ArgumentException ("NextSibling is not a child of this node.", "nextSibling"); + // No need to test for "Cannot add children to null nodes", + // as there isn't any valid nextSibling in null nodes. + InsertChildBeforeUnsafe(nextSibling, child, role); + } + + + void InsertChildBeforeUnsafe(AstNode nextSibling, AstNode child, Role role) + { + child.parent = this; + child.role = role; + child.nextSibling = nextSibling; + child.prevSibling = nextSibling.prevSibling; + + if (nextSibling.prevSibling != null) { + Debug.Assert(nextSibling.prevSibling.nextSibling == nextSibling); + nextSibling.prevSibling.nextSibling = child; + } else { + Debug.Assert(firstChild == nextSibling); + firstChild = child; + } + nextSibling.prevSibling = child; + } + + public void InsertChildAfter(AstNode prevSibling, T child, Role role) where T : AstNode + { + InsertChildBefore((prevSibling == null || prevSibling.IsNull) ? firstChild : prevSibling.nextSibling, child, role); + } + + /// + /// Removes this node from its parent. + /// + public void Remove() + { + if (parent != null) { + if (prevSibling != null) { + Debug.Assert(prevSibling.nextSibling == this); + prevSibling.nextSibling = nextSibling; + } else { + Debug.Assert(parent.firstChild == this); + parent.firstChild = nextSibling; + } + if (nextSibling != null) { + Debug.Assert(nextSibling.prevSibling == this); + nextSibling.prevSibling = prevSibling; + } else { + Debug.Assert(parent.lastChild == this); + parent.lastChild = prevSibling; + } + parent = null; + role = Roles.Root; + prevSibling = null; + nextSibling = null; + } + } + + /// + /// Replaces this node with the new node. + /// + public void ReplaceWith(AstNode newNode) + { + if (newNode == null || newNode.IsNull) { + Remove(); + return; + } + if (newNode == this) + return; // nothing to do... + if (parent == null) { + throw new InvalidOperationException(this.IsNull ? "Cannot replace the null nodes" : "Cannot replace the root node"); + } + // Because this method doesn't statically check the new node's type with the role, + // we perform a runtime test: + if (!role.IsValid(newNode)) { + throw new ArgumentException (string.Format("The new node '{0}' is not valid in the role {1}", newNode.GetType().Name, role.ToString()), "newNode"); + } + if (newNode.parent != null) { + // newNode is used within this tree? + if (newNode.Ancestors.Contains(this)) { + // e.g. "parenthesizedExpr.ReplaceWith(parenthesizedExpr.Expression);" + // enable automatic removal + newNode.Remove(); + } else { + throw new ArgumentException ("Node is already used in another tree.", "newNode"); + } + } + + newNode.parent = parent; + newNode.role = role; + newNode.prevSibling = prevSibling; + newNode.nextSibling = nextSibling; + if (parent != null) { + if (prevSibling != null) { + Debug.Assert(prevSibling.nextSibling == this); + prevSibling.nextSibling = newNode; + } else { + Debug.Assert(parent.firstChild == this); + parent.firstChild = newNode; + } + if (nextSibling != null) { + Debug.Assert(nextSibling.prevSibling == this); + nextSibling.prevSibling = newNode; + } else { + Debug.Assert(parent.lastChild == this); + parent.lastChild = newNode; + } + parent = null; + prevSibling = null; + nextSibling = null; + role = Roles.Root; + } + } + + public AstNode ReplaceWith(Func replaceFunction) + { + if (replaceFunction == null) + throw new ArgumentNullException("replaceFunction"); + if (parent == null) { + throw new InvalidOperationException(this.IsNull ? "Cannot replace the null nodes" : "Cannot replace the root node"); + } + AstNode oldParent = parent; + AstNode oldSuccessor = nextSibling; + Role oldRole = role; + Remove(); + AstNode replacement = replaceFunction(this); + if (oldSuccessor != null && oldSuccessor.parent != oldParent) + throw new InvalidOperationException("replace function changed nextSibling of node being replaced?"); + if (!(replacement == null || replacement.IsNull)) { + if (replacement.parent != null) + throw new InvalidOperationException("replace function must return the root of a tree"); + if (!oldRole.IsValid(replacement)) { + throw new InvalidOperationException (string.Format("The new node '{0}' is not valid in the role {1}", replacement.GetType().Name, oldRole.ToString())); + } + + if (oldSuccessor != null) + oldParent.InsertChildBeforeUnsafe(oldSuccessor, replacement, oldRole); + else + oldParent.AddChildUnsafe(replacement, oldRole); + } + return replacement; + } + + /// + /// Clones the whole subtree starting at this AST node. + /// + /// Annotations are copied over to the new nodes; and any annotations implementating ICloneable will be cloned. + public AstNode Clone() + { + AstNode copy = (AstNode)MemberwiseClone(); + // First, reset the shallow pointer copies + copy.parent = null; + copy.role = Roles.Root; + copy.firstChild = null; + copy.lastChild = null; + copy.prevSibling = null; + copy.nextSibling = null; + + // Then perform a deep copy: + for (AstNode cur = firstChild; cur != null; cur = cur.nextSibling) { + copy.AddChildUnsafe(cur.Clone(), cur.role); + } + + // Finally, clone the annotation, if necessary + ICloneable annotations = copy.annotations as ICloneable; // read from copy (for thread-safety) + if (annotations != null) + copy.annotations = annotations.Clone(); + + return copy; + } + + #region Annotation support + // Annotations: points either null (no annotations), to the single annotation, + // or to an AnnotationList. + // Once it is pointed at an AnnotationList, it will never change (this allows thread-safety support by locking the list) + object annotations; + + sealed class AnnotationList : List, ICloneable + { + // There are two uses for this custom list type: + // 1) it's private, and thus (unlike List) cannot be confused with real annotations + // 2) It allows us to simplify the cloning logic by making the list behave the same as a clonable annotation. + public AnnotationList(int initialCapacity) : base(initialCapacity) + { + } + + public object Clone() + { + lock (this) { + AnnotationList copy = new AnnotationList(this.Count); + for (int i = 0; i < this.Count; i++) { + object obj = this[i]; + ICloneable c = obj as ICloneable; + copy.Add(c != null ? c.Clone() : obj); + } + return copy; + } + } + } + + public void AddAnnotation(object annotation) + { + if (annotation == null) + throw new ArgumentNullException("annotation"); + if (this.IsNull) + throw new InvalidOperationException("Cannot add annotations to the null node"); + retry: // Retry until successful + object oldAnnotation = Interlocked.CompareExchange(ref this.annotations, annotation, null); + if (oldAnnotation == null) { + return; // we successfully added a single annotation + } + AnnotationList list = oldAnnotation as AnnotationList; + if (list == null) { + // we need to transform the old annotation into a list + list = new AnnotationList(4); + list.Add(oldAnnotation); + list.Add(annotation); + if (Interlocked.CompareExchange(ref this.annotations, list, oldAnnotation) != oldAnnotation) { + // the transformation failed (some other thread wrote to this.annotations first) + goto retry; + } + } else { + // once there's a list, use simple locking + lock (list) { + list.Add(annotation); + } + } + } + + public void RemoveAnnotations() where T : class + { + retry: // Retry until successful + object oldAnnotations = this.annotations; + AnnotationList list = oldAnnotations as AnnotationList; + if (list != null) { + lock (list) + list.RemoveAll(obj => obj is T); + } else if (oldAnnotations is T) { + if (Interlocked.CompareExchange(ref this.annotations, null, oldAnnotations) != oldAnnotations) { + // Operation failed (some other thread wrote to this.annotations first) + goto retry; + } + } + } + + public void RemoveAnnotations(Type type) + { + if (type == null) + throw new ArgumentNullException("type"); + retry: // Retry until successful + object oldAnnotations = this.annotations; + AnnotationList list = oldAnnotations as AnnotationList; + if (list != null) { + lock (list) + list.RemoveAll(obj => type.IsInstanceOfType(obj)); + } else if (type.IsInstanceOfType(oldAnnotations)) { + if (Interlocked.CompareExchange(ref this.annotations, null, oldAnnotations) != oldAnnotations) { + // Operation failed (some other thread wrote to this.annotations first) + goto retry; + } + } + } + + public T Annotation() where T: class + { + object annotations = this.annotations; + AnnotationList list = annotations as AnnotationList; + if (list != null) { + lock (list) { + foreach (object obj in list) { + T t = obj as T; + if (t != null) + return t; + } + return null; + } + } else { + return annotations as T; + } + } + + public object Annotation(Type type) + { + if (type == null) + throw new ArgumentNullException("type"); + object annotations = this.annotations; + AnnotationList list = annotations as AnnotationList; + if (list != null) { + lock (list) { + foreach (object obj in list) { + if (type.IsInstanceOfType(obj)) + return obj; + } + } + } else { + if (type.IsInstanceOfType(annotations)) + return annotations; + } + return null; + } + + /// + /// Gets all annotations stored on this AstNode. + /// + public IEnumerable Annotations { + get { + object annotations = this.annotations; + AnnotationList list = annotations as AnnotationList; + if (list != null) { + lock (list) { + return list.ToArray(); + } + } else { + if (annotations != null) + return new object[] { annotations }; + else + return Enumerable.Empty(); + } + } + } + #endregion + + public abstract S AcceptVisitor (IAstVisitor visitor, T data); + + #region Pattern Matching + protected static bool MatchString(string name1, string name2) + { + return string.IsNullOrEmpty(name1) || string.Equals(name1, name2, StringComparison.OrdinalIgnoreCase); + } + + protected static bool MatchStringXml(string name1, string name2) + { + return string.IsNullOrEmpty(name1) || string.Equals(name1, name2, StringComparison.Ordinal); + } + + protected internal abstract bool DoMatch(AstNode other, PatternMatching.Match match); + + bool PatternMatching.INode.DoMatch(PatternMatching.INode other, PatternMatching.Match match) + { + AstNode o = other as AstNode; + // try matching if other is null, or if other is an AstNode + return (other == null || o != null) && DoMatch(o, match); + } + + bool PatternMatching.INode.DoMatchCollection(Role role, PatternMatching.INode pos, PatternMatching.Match match, PatternMatching.BacktrackingInfo backtrackingInfo) + { + AstNode o = pos as AstNode; + return (pos == null || o != null) && DoMatch (o, match); + } + + PatternMatching.INode PatternMatching.INode.NextSibling { + get { return nextSibling; } + } + + PatternMatching.INode PatternMatching.INode.FirstChild { + get { return firstChild; } + } + #endregion + + public AstNode GetNextNode () + { + if (NextSibling != null) + return NextSibling; + if (Parent != null) + return Parent.GetNextNode (); + return null; + } + + public AstNode GetPrevNode () + { + if (PrevSibling != null) + return PrevSibling; + if (Parent != null) + return Parent.GetPrevNode (); + return null; + } + + // filters all non VB nodes (comments, white spaces or pre processor directives) + public AstNode GetVBNodeBefore (AstNode node) + { + var n = node.PrevSibling; + while (n != null) { + if (n.Role != Roles.Comment) + return n; + n = n.GetPrevNode (); + } + return null; + } + + // the Root role must be available when creating the null nodes, so we can't put it in the Roles class + static readonly Role RootRole = new Role("Root"); + + public static class Roles + { + /// + /// Root of an abstract syntax tree. + /// + public static readonly Role Root = RootRole; + + // some pre defined constants for common roles + public static readonly Role Identifier = new Role("Identifier", Ast.Identifier.Null); + public static readonly Role XmlIdentifier = new Role("XmlIdentifier", Ast.XmlIdentifier.Null); + public static readonly Role XmlLiteralString = new Role("XmlLiteralString", Ast.XmlLiteralString.Null); + +// public static readonly Role Body = new Role("Body", CSharp.BlockStatement.Null); + public static readonly Role Parameter = new Role("Parameter"); + public static readonly Role Argument = new Role("Argument", Ast.Expression.Null); + public static readonly Role Type = new Role("Type", AstType.Null); + public static readonly Role Expression = new Role("Expression", Ast.Expression.Null); +// public static readonly Role TargetExpression = new Role("Target", CSharp.Expression.Null); +// public readonly static Role Condition = new Role("Condition", CSharp.Expression.Null); +// + public static readonly Role TypeParameter = new Role("TypeParameter"); + public static readonly Role TypeArgument = new Role("TypeArgument", AstType.Null); +// public static readonly Role Variable = new Role("Variable"); +// public static readonly Role EmbeddedStatement = new Role("EmbeddedStatement", CSharp.Statement.Null); +// + public static readonly Role Keyword = new Role("Keyword", VBTokenNode.Null); +// public static readonly Role InKeyword = new Role("InKeyword", VBTokenNode.Null); + + // some pre defined constants for most used punctuation + public static readonly Role LPar = new Role("LPar", VBTokenNode.Null); + public static readonly Role RPar = new Role("RPar", VBTokenNode.Null); + public static readonly Role LBracket = new Role("LBracket", VBTokenNode.Null); + public static readonly Role RBracket = new Role("RBracket", VBTokenNode.Null); + public static readonly Role LBrace = new Role("LBrace", VBTokenNode.Null); + public static readonly Role RBrace = new Role("RBrace", VBTokenNode.Null); + public static readonly Role LChevron = new Role("LChevron", VBTokenNode.Null); + public static readonly Role RChevron = new Role("RChevron", VBTokenNode.Null); + public static readonly Role Comma = new Role("Comma", VBTokenNode.Null); + public static readonly Role Dot = new Role("Dot", VBTokenNode.Null); + public static readonly Role Semicolon = new Role("Semicolon", VBTokenNode.Null); + public static readonly Role Assign = new Role("Assign", VBTokenNode.Null); + public static readonly Role Colon = new Role("Colon", VBTokenNode.Null); + public static readonly Role StatementTerminator = new Role("StatementTerminator", VBTokenNode.Null); + + // XML + /// + /// Text: < + /// + public static readonly Role XmlOpenTag = new Role("XmlOpenTag", VBTokenNode.Null); + /// + /// Text: > + /// + public static readonly Role XmlCloseTag = new Role("XmlOpenTag", VBTokenNode.Null); + + public static readonly Role Comment = new Role("Comment"); + + } + } + + public class Comment + { + + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/AstNodeCollection.cs b/ICSharpCode.NRefactory.VB/Ast/AstNodeCollection.cs new file mode 100644 index 000000000..236f27a0b --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/AstNodeCollection.cs @@ -0,0 +1,209 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; + +using ICSharpCode.NRefactory.PatternMatching; + +namespace ICSharpCode.NRefactory.VB +{ + /// + /// Represents the children of an AstNode that have a specific role. + /// + public class AstNodeCollection : ICollection where T : AstNode + { + readonly AstNode node; + readonly Role role; + + public AstNodeCollection(AstNode node, Role role) + { + if (node == null) + throw new ArgumentNullException("node"); + if (role == null) + throw new ArgumentNullException("role"); + this.node = node; + this.role = role; + } + + public int Count { + get { + int count = 0; + for (AstNode cur = node.FirstChild; cur != null; cur = cur.NextSibling) { + if (cur.Role == role) + count++; + } + return count; + } + } + + public void Add(T element) + { + node.AddChild(element, role); + } + + public void AddRange(IEnumerable nodes) + { + // Evaluate 'nodes' first, since it might change when we add the new children + // Example: collection.AddRange(collection); + if (nodes != null) { + foreach (T node in nodes.ToList()) + Add(node); + } + } + + public void AddRange(T[] nodes) + { + // Fast overload for arrays - we don't need to create a copy + if (nodes != null) { + foreach (T node in nodes) + Add(node); + } + } + + public void ReplaceWith(IEnumerable nodes) + { + // Evaluate 'nodes' first, since it might change when we call Clear() + // Example: collection.ReplaceWith(collection); + if (nodes != null) + nodes = nodes.ToList(); + Clear(); + foreach (T node in nodes) + Add(node); + } + + public void MoveTo(ICollection targetCollection) + { + foreach (T node in this) { + node.Remove(); + targetCollection.Add(node); + } + } + + public bool Contains(T element) + { + return element != null && element.Parent == node && element.Role == role; + } + + public bool Remove(T element) + { + if (Contains(element)) { + element.Remove(); + return true; + } else { + return false; + } + } + + public void CopyTo(T[] array, int arrayIndex) + { + foreach (T item in this) + array[arrayIndex++] = item; + } + + public void Clear() + { + foreach (T item in this) + item.Remove(); + } + + bool ICollection.IsReadOnly { + get { return false; } + } + + public IEnumerator GetEnumerator() + { + AstNode next; + for (AstNode cur = node.FirstChild; cur != null; cur = next) { + Debug.Assert(cur.Parent == node); + // Remember next before yielding cur. + // This allows removing/replacing nodes while iterating through the list. + next = cur.NextSibling; + if (cur.Role == role) + yield return (T)cur; + } + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + #region Equals and GetHashCode implementation + public override bool Equals(object obj) + { + if (obj is AstNodeCollection) { + return ((AstNodeCollection)obj) == this; + } else { + return false; + } + } + + public override int GetHashCode() + { + return node.GetHashCode() ^ role.GetHashCode(); + } + + public static bool operator ==(AstNodeCollection left, AstNodeCollection right) + { + return left.role == right.role && left.node == right.node; + } + + public static bool operator !=(AstNodeCollection left, AstNodeCollection right) + { + return !(left.role == right.role && left.node == right.node); + } + #endregion + + internal bool DoMatch(AstNodeCollection other, Match match) + { + // TODO : does not compile (ask Daniel)! +// Stack patternStack = new Stack(); +// Stack stack = new Stack(); +// patternStack.Push(this.node.FirstChild); +// stack.Push(new Pattern.PossibleMatch(other.node.FirstChild, match.CheckPoint())); +// while (stack.Count > 0) { +// AstNode cur1 = patternStack.Pop(); +// AstNode cur2 = stack.Peek().NextOther; +// match.RestoreCheckPoint(stack.Pop().Checkpoint); +// bool success = true; +// while (cur1 != null && success) { +// while (cur1 != null && cur1.Role != role) +// cur1 = cur1.NextSibling; +// while (cur2 != null && cur2.Role != role) +// cur2 = cur2.NextSibling; +// if (cur1 == null) +// break; +// +// Debug.Assert(stack.Count == patternStack.Count); +// success = cur1.DoMatchCollection(role, cur2, match, stack); +// Debug.Assert(stack.Count >= patternStack.Count); +// while (stack.Count > patternStack.Count) +// patternStack.Push(cur1.NextSibling); +// +// cur1 = cur1.NextSibling; +// if (cur2 != null) +// cur2 = cur2.NextSibling; +// } +// while (cur2 != null && cur2.Role != role) +// cur2 = cur2.NextSibling; +// if (success && cur2 == null) +// return true; +// } + return false; + } + + public void InsertAfter(T existingItem, T newItem) + { + node.InsertChildAfter(existingItem, newItem, role); + } + + public void InsertBefore(T existingItem, T newItem) + { + node.InsertChildBefore(existingItem, newItem, role); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/Enums.cs b/ICSharpCode.NRefactory.VB/Ast/Enums.cs index f0c6c27b4..d0fc13929 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Enums.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Enums.cs @@ -10,82 +10,45 @@ namespace ICSharpCode.NRefactory.VB.Ast { None = 0x0000, - // Access + // Accessibility Private = 0x0001, - /// C# 'internal', VB 'Friend' - Internal = 0x0002, + Friend = 0x0002, Protected = 0x0004, Public = 0x0008, // Scope - Abstract = 0x0010, // == MustOverride/MustInherit - Virtual = 0x0020, - Sealed = 0x0040, - /// C# 'static', VB 'Shared' - Static = 0x0080, - Override = 0x0100, - /// For fields: readonly (c# and vb), for properties: get-only (vb) - ReadOnly = 0x0200, - Const = 0x0400, - /// C# 'new', VB 'Shadows' - New = 0x0800, - Partial = 0x1000, + MustInherit = 0x0010, // Types + MustOverride = 0x0020, // Members + Overridable = 0x0040, + NotInheritable = 0x0080, // Types + NotOverridable = 0x0100, // Members + Const = 0x0200, + Shared = 0x0400, + Static = 0x0800, + Override = 0x1000, + ReadOnly = 0x2000, + Shadows = 0x4000, + Partial = 0x8000, // Special - Extern = 0x2000, - Volatile = 0x4000, - Unsafe = 0x8000, Overloads = 0x10000, // VB specific WithEvents = 0x20000, // VB specific Default = 0x40000, // VB specific - Fixed = 0x80000, // C# specific (fixed size arrays in unsafe structs) - Dim = 0x100000, // VB.NET SPECIFIC, for fields/local variables only + Dim = 0x80000, // VB.NET SPECIFIC, for fields/local variables only - /// Generated code, not part of parsed code - Synthetic = 0x200000, /// Only for VB properties. - WriteOnly = 0x400000, // VB specific + WriteOnly = 0x100000, // VB specific - Visibility = Private | Public | Protected | Internal, - Classes = New | Visibility | Abstract | Sealed | Partial | Static, - VBModules = Visibility, - VBStructures = Visibility | New, - VBEnums = Visibility | New, - VBInterfacs = Visibility | New, - VBDelegates = Visibility | New, - VBMethods = Visibility | New | Static | Virtual | Sealed | Abstract | Override | Overloads, - VBExternalMethods = Visibility | New | Overloads, - VBEvents = Visibility | New | Overloads, - VBProperties = VBMethods | Default | ReadOnly | WriteOnly, - VBCustomEvents = Visibility | New | Overloads, - VBOperators = Public | Static | Overloads | New, + ByVal = 0x200000, + ByRef = 0x400000, + ParamArray = 0x800000, + Optional = 0x1000000, - - // this is not documented in the spec - VBInterfaceEvents = New, - VBInterfaceMethods = New | Overloads, - VBInterfaceProperties = New | Overloads | ReadOnly | WriteOnly | Default, - VBInterfaceEnums = New, - - Fields = New | Visibility | Static | ReadOnly | Volatile | Fixed, - PropertysEventsMethods = New | Visibility | Static | Virtual | Sealed | Override | Abstract | Extern, - Indexers = New | Visibility | Virtual | Sealed | Override | Abstract | Extern, - Operators = Public | Static | Extern, - Constants = New | Visibility, - StructsInterfacesEnumsDelegates = New | Visibility | Partial, - StaticConstructors = Extern | Static | Unsafe, - Destructors = Extern | Unsafe, - Constructors = Visibility | Extern, - } - - public enum ClassType - { - Class, - Module, - Interface, - Struct, - Enum + /// + /// Special value used to match any modifiers during pattern matching. + /// + Any = unchecked((int)0x80000000) } public enum ParentType @@ -104,18 +67,6 @@ namespace ICSharpCode.NRefactory.VB.Ast Ref } - [Flags] - public enum ParameterModifiers - { - // Values must be the same as in SharpDevelop's ParameterModifiers - None = 0, - In = 1, - Out = 2, - Ref = 4, - Params = 8, - Optional = 16 - } - public enum VarianceModifier { Invariant, @@ -359,20 +310,6 @@ namespace ICSharpCode.NRefactory.VB.Ast Ansi } - /// - /// Compare type, used in the Option Compare - /// pragma (VB only). - /// - public enum OptionType - { - None, - Explicit, - Strict, - CompareBinary, - CompareText, - Infer - } - /// /// Specifies the ordering direction of a QueryExpressionOrdering node. /// diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/Expression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/Expression.cs new file mode 100644 index 000000000..d15756e3e --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/Expression.cs @@ -0,0 +1,33 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + public abstract class Expression : AstNode + { + #region Null + public new static readonly Expression Null = new NullExpression (); + + sealed class NullExpression : Expression + { + public override bool IsNull { + get { + return true; + } + } + + public override S AcceptVisitor (IAstVisitor visitor, T data) + { + return default (S); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + return other == null || other.IsNull; + } + } + #endregion + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/PrimitiveExpression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/PrimitiveExpression.cs new file mode 100644 index 000000000..c01adaf8a --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/PrimitiveExpression.cs @@ -0,0 +1,75 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using ICSharpCode.NRefactory.VB.PrettyPrinter; +using System; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + /// + /// Represents a literal value. + /// + public class PrimitiveExpression : Expression + { + public static readonly object AnyValue = new object(); + + AstLocation startLocation; + public override AstLocation StartLocation { + get { + return startLocation; + } + } + + int length; + public override AstLocation EndLocation { + get { + return new AstLocation(StartLocation.Line, StartLocation.Column + length); + } + } + + public object Value { get; private set; } + + string stringValue; + + public string StringValue { + get { return stringValue; } // TODO ?? VBNetOutputVisitor.ToVBNetString(this); } + } + + public PrimitiveExpression(object value) + { + this.Value = value; + } + + public PrimitiveExpression(object value, string stringValue) + { + this.Value = value; + this.stringValue = stringValue; + } + + public PrimitiveExpression(object value, AstLocation startLocation, int length) + { + this.Value = value; + this.startLocation = startLocation; + this.length = length; + } + + public PrimitiveExpression(object value, string stringValue, AstLocation startLocation, int length) + { + this.Value = value; + this.stringValue = stringValue; + this.startLocation = startLocation; + this.length = length; + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitPrimitiveExpression(this, data); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + PrimitiveExpression o = other as PrimitiveExpression; + return o != null && (this.Value == AnyValue || object.Equals(this.Value, o.Value)); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/SimpleNameExpression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/SimpleNameExpression.cs new file mode 100644 index 000000000..257b8e744 --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/SimpleNameExpression.cs @@ -0,0 +1,27 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + /// + /// Description of IdentifierExpression. + /// + public class SimpleNameExpression : Expression + { + public Identifier Identifier { get; set; } + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + var node = other as SimpleNameExpression; + return node != null + && Identifier.DoMatch(node.Identifier, match); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitSimpleNameExpression(this, data); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/XmlIdentifier.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/XmlIdentifier.cs new file mode 100644 index 000000000..7d3a6ca0b --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/XmlIdentifier.cs @@ -0,0 +1,72 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + /// + /// Description of XmlIdentifier. + /// + public class XmlIdentifier : AstNode + { + public static readonly new XmlIdentifier Null = new NullXmlIdentifier(); + + class NullXmlIdentifier : XmlIdentifier + { + public override bool IsNull { + get { + return true; + } + } + + public override S AcceptVisitor (IAstVisitor visitor, T data) + { + return default(S); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + return other == null || other.IsNull; + } + } + + public string Name { get; set; } + + AstLocation startLocation; + public override AstLocation StartLocation { + get { return startLocation; } + } + + AstLocation endLocation; + public override AstLocation EndLocation { + get { return endLocation; } + } + + private XmlIdentifier() + { + this.Name = string.Empty; + } + + public XmlIdentifier(string name, AstLocation startLocation, AstLocation endLocation) + { + this.Name = name; + this.startLocation = startLocation; + this.endLocation = endLocation; + } + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + var ident = other as XmlIdentifier; + return ident != null + && MatchStringXml(Name, ident.Name) + && ident.startLocation == startLocation + && ident.endLocation == endLocation; + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitXmlIdentifier(this, data); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/XmlLiteralString.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/XmlLiteralString.cs new file mode 100644 index 000000000..3195bcd69 --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/XmlLiteralString.cs @@ -0,0 +1,69 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + public class XmlLiteralString : AstNode + { + public static readonly new XmlLiteralString Null = new XmlLiteralString(); + + class NullXmlLiteralString : XmlLiteralString + { + public override bool IsNull { + get { + return true; + } + } + + public override S AcceptVisitor (IAstVisitor visitor, T data) + { + return default(S); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + return other == null || other.IsNull; + } + } + + public string Value { get; set; } + + AstLocation startLocation; + public override AstLocation StartLocation { + get { return startLocation; } + } + + AstLocation endLocation; + public override AstLocation EndLocation { + get { return endLocation; } + } + + private XmlLiteralString() + { + this.Value = string.Empty; + } + + public XmlLiteralString(string value, AstLocation startLocation, AstLocation endLocation) + { + this.Value = value; + this.startLocation = startLocation; + this.endLocation = endLocation; + } + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + var ident = other as XmlLiteralString; + return ident != null + && MatchStringXml(Value, ident.Value) + && ident.startLocation == startLocation + && ident.endLocation == endLocation; + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitXmlLiteralString(this, data); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/General/Attribute.cs b/ICSharpCode.NRefactory.VB/Ast/General/Attribute.cs new file mode 100644 index 000000000..22261575e --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/General/Attribute.cs @@ -0,0 +1,93 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + public class Attribute : AstNode + { + #region PatternPlaceholder + public static implicit operator Attribute(PatternMatching.Pattern pattern) + { + return pattern != null ? new PatternPlaceholder(pattern) : null; + } + + sealed class PatternPlaceholder : Attribute, PatternMatching.INode + { + readonly PatternMatching.Pattern child; + + public PatternPlaceholder(PatternMatching.Pattern child) + { + this.child = child; + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitPatternPlaceholder(this, child, data); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + return child.DoMatch(other, match); + } + + bool PatternMatching.INode.DoMatchCollection(Role role, PatternMatching.INode pos, PatternMatching.Match match, PatternMatching.BacktrackingInfo backtrackingInfo) + { + return child.DoMatchCollection(role, pos, match, backtrackingInfo); + } + } + #endregion + + public static readonly Role AttributeRole = new Role("Attribute"); + public static readonly Role TargetRole = new Role("Target", VBTokenNode.Null); + + public VBTokenNode Target { + get { return GetChildByRole(TargetRole); } + set { SetChildByRole(TargetRole, value); } + } + + public VBTokenNode ColonToken { + get { return GetChildByRole(Roles.StatementTerminator); } + } + + public AstType Type { + get { return GetChildByRole(Roles.Type); } + set { SetChildByRole(Roles.Type, value); } + } + + public VBTokenNode LParToken { + get { return GetChildByRole(Roles.LPar); } + } + + public AstNodeCollection Arguments { + get { return GetChildrenByRole(Roles.Argument); } + } + + public VBTokenNode RParToken { + get { return GetChildByRole(Roles.RPar); } + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitAttribute(this, data); + } + +// public override string ToString() +// { +// return string.Format("[Attribute Type={0} Arguments={1}]", Type, GetCollectionString(Arguments)); +// } + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + var node = other as Attribute; + return node != null && node.Target.DoMatch(this.Target, match) && node.Type.DoMatch(this.Type, match) && node.Arguments.DoMatch(this.Arguments, match); + } + } + + public enum AttributeTarget + { + Assembly, + Module + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/General/AttributeBlock.cs b/ICSharpCode.NRefactory.VB/Ast/General/AttributeBlock.cs new file mode 100644 index 000000000..2e06d3917 --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/General/AttributeBlock.cs @@ -0,0 +1,36 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + public class AttributeBlock : AstNode + { + public readonly static Role AttributeBlockRole = new Role("AttributeBlock"); + public readonly static Role ReturnTypeAttributeBlockRole = new Role("ReturnTypeAttributeBlock"); + + public VBTokenNode LChevron { + get { return GetChildByRole(Roles.LChevron); } + } + + public AstNodeCollection Attributes { + get { return GetChildrenByRole(Attribute.AttributeRole); } + } + + public VBTokenNode RChevron { + get { return GetChildByRole(Roles.RChevron); } + } + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + var node = other as AttributeBlock; + return node != null && Attributes.DoMatch(node.Attributes, match); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitAttributeBlock(this, data); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/General/AttributedNode.cs b/ICSharpCode.NRefactory.VB/Ast/General/AttributedNode.cs new file mode 100644 index 000000000..37e364ee6 --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/General/AttributedNode.cs @@ -0,0 +1,67 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; +using System.Collections.Generic; +using System.Linq; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + public abstract class AttributedNode : AstNode + { + public AstNodeCollection Attributes { + get { return GetChildrenByRole(AttributeBlock.AttributeBlockRole); } + } + + public static readonly Role ModifierRole = new Role("Modifier"); + + public Modifiers Modifiers { + get { return GetModifiers(this); } + set { SetModifiers(this, value); } + } + + public IEnumerable ModifierTokens { + get { return GetChildrenByRole (ModifierRole); } + } + + internal static Modifiers GetModifiers(AstNode node) + { + Modifiers m = 0; + foreach (VBModifierToken t in node.GetChildrenByRole (ModifierRole)) { + m |= t.Modifier; + } + return m; + } + + internal static void SetModifiers(AstNode node, Modifiers newValue) + { + Modifiers oldValue = GetModifiers(node); + AstNode insertionPos = node.GetChildrenByRole(Attribute.AttributeRole).LastOrDefault(); + foreach (Modifiers m in VBModifierToken.AllModifiers) { + if ((m & newValue) != 0) { + if ((m & oldValue) == 0) { + // Modifier was added + var newToken = new VBModifierToken(AstLocation.Empty, m); + node.InsertChildAfter(insertionPos, newToken, ModifierRole); + insertionPos = newToken; + } else { + // Modifier already exists + insertionPos = node.GetChildrenByRole(ModifierRole).First(t => t.Modifier == m); + } + } else { + if ((m & oldValue) != 0) { + // Modifier was removed + node.GetChildrenByRole (ModifierRole).First(t => t.Modifier == m).Remove(); + } + } + } + } + + protected bool MatchAttributesAndModifiers(AttributedNode o, PatternMatching.Match match) + { + return (this.Modifiers == Modifiers.Any || this.Modifiers == o.Modifiers) && this.Attributes.DoMatch(o.Attributes, match); + } + } + + +} diff --git a/ICSharpCode.NRefactory.VB/Ast/General/BlockStatement.cs b/ICSharpCode.NRefactory.VB/Ast/General/BlockStatement.cs deleted file mode 100644 index 1a3492c86..000000000 --- a/ICSharpCode.NRefactory.VB/Ast/General/BlockStatement.cs +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using System; - -namespace ICSharpCode.NRefactory.VB.Ast -{ - public class BlockStatement : Statement - { - // Children in VB: LabelStatement, EndStatement, Statement - - public static new BlockStatement Null { - get { - return NullBlockStatement.Instance; - } - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) - { - return visitor.VisitBlockStatement(this, data); - } - - public override string ToString() - { - return String.Format("[BlockStatement: Children={0}]", - GetCollectionString(base.Children)); - } - } - - internal sealed class NullBlockStatement : BlockStatement - { - public static readonly NullBlockStatement Instance = new NullBlockStatement(); - - public override bool IsNull { - get { - return true; - } - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) - { - return data; - } - public override object AcceptChildren(IAstVisitor visitor, object data) - { - return data; - } - public override void AddChild(INode childNode) - { - throw new InvalidOperationException(); - } - - public override string ToString() - { - return String.Format("[NullBlockStatement]"); - } - } -} diff --git a/ICSharpCode.NRefactory.VB/Ast/General/CompilationUnit.cs b/ICSharpCode.NRefactory.VB/Ast/General/CompilationUnit.cs index 41bc8e647..6dbe78427 100644 --- a/ICSharpCode.NRefactory.VB/Ast/General/CompilationUnit.cs +++ b/ICSharpCode.NRefactory.VB/Ast/General/CompilationUnit.cs @@ -2,23 +2,80 @@ // This code is distributed under the GNU LGPL (for details please see \doc\license.txt) using System; -using System.Collections; +using System.Collections.Generic; namespace ICSharpCode.NRefactory.VB.Ast { - public class CompilationUnit : AbstractNode + public class CompilationUnit : AstNode { - // Children in C#: UsingAliasDeclaration, UsingDeclaration, AttributeSection, NamespaceDeclaration - // Children in VB: OptionStatements, ImportsStatement, AttributeSection, NamespaceDeclaration + public static readonly Role MemberRole = new Role("Member", AstNode.Null); - public override object AcceptVisitor(IAstVisitor visitor, object data) + public CompilationUnit () { - return visitor.VisitCompilationUnit(this, data); } - public override string ToString() + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { - return String.Format("[CompilationUnit]"); + CompilationUnit o = other as CompilationUnit; + return o != null && GetChildrenByRole(MemberRole).DoMatch(o.GetChildrenByRole(MemberRole), match); + } + + public AstNode GetNodeAt (int line, int column) + { + return GetNodeAt (new AstLocation (line, column)); + } + + public AstNode GetNodeAt (AstLocation location) + { + AstNode node = this; + while (node.FirstChild != null) { + var child = node.FirstChild; + while (child != null) { + if (child.StartLocation <= location && location < child.EndLocation) { + node = child; + break; + } + child = child.NextSibling; + } + // found no better child node - therefore the parent is the right one. + if (child == null) + break; + } + return node; + } + + public IEnumerable GetNodesBetween (int startLine, int startColumn, int endLine, int endColumn) + { + return GetNodesBetween (new AstLocation (startLine, startColumn), new AstLocation (endLine, endColumn)); + } + + public IEnumerable GetNodesBetween (AstLocation start, AstLocation end) + { + AstNode node = this; + while (node != null) { + AstNode next; + if (start <= node.StartLocation && node.EndLocation <= end) { + // Remember next before yielding node. + // This allows iteration to continue when the caller removes/replaces the node. + next = node.NextSibling; + yield return node; + } else { + if (node.EndLocation < start) { + next = node.NextSibling; + } else { + next = node.FirstChild; + } + } + + if (next != null && next.StartLocation > end) + yield break; + node = next; + } + } + + public override S AcceptVisitor (IAstVisitor visitor, T data) + { + return visitor.VisitCompilationUnit (this, data); } } } diff --git a/ICSharpCode.NRefactory.VB/Ast/General/Expression.cs b/ICSharpCode.NRefactory.VB/Ast/General/Expression.cs deleted file mode 100644 index 24824ac73..000000000 --- a/ICSharpCode.NRefactory.VB/Ast/General/Expression.cs +++ /dev/null @@ -1,103 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using System; - -namespace ICSharpCode.NRefactory.VB.Ast -{ - public abstract class Expression : AbstractNode, INullable - { - public static Expression Null { - get { - return NullExpression.Instance; - } - } - - public virtual bool IsNull { - get { - return false; - } - } - - public static Expression CheckNull(Expression expression) - { - return expression == null ? NullExpression.Instance : expression; - } - - /// - /// Returns the existing expression plus the specified integer value. - /// The old object is not modified, but might be a subobject on the new expression - /// (and thus its parent property is modified). - /// - public static Expression AddInteger(Expression expr, int value) - { - PrimitiveExpression pe = expr as PrimitiveExpression; - if (pe != null && pe.Value is int) { - int newVal = (int)pe.Value + value; - return new PrimitiveExpression(newVal, newVal.ToString(System.Globalization.NumberFormatInfo.InvariantInfo)); - } - BinaryOperatorExpression boe = expr as BinaryOperatorExpression; - if (boe != null && boe.Op == BinaryOperatorType.Add) { - // clone boe: - boe = new BinaryOperatorExpression(boe.Left, boe.Op, boe.Right); - - boe.Right = AddInteger(boe.Right, value); - if (boe.Right is PrimitiveExpression && ((PrimitiveExpression)boe.Right).Value is int) { - int newVal = (int)((PrimitiveExpression)boe.Right).Value; - if (newVal == 0) { - return boe.Left; - } else if (newVal < 0) { - ((PrimitiveExpression)boe.Right).Value = -newVal; - boe.Op = BinaryOperatorType.Subtract; - } - } - return boe; - } - if (boe != null && boe.Op == BinaryOperatorType.Subtract) { - pe = boe.Right as PrimitiveExpression; - if (pe != null && pe.Value is int) { - int newVal = (int)pe.Value - value; - if (newVal == 0) - return boe.Left; - - // clone boe: - boe = new BinaryOperatorExpression(boe.Left, boe.Op, boe.Right); - - if (newVal < 0) { - newVal = -newVal; - boe.Op = BinaryOperatorType.Add; - } - boe.Right = new PrimitiveExpression(newVal, newVal.ToString(System.Globalization.NumberFormatInfo.InvariantInfo)); - return boe; - } - } - BinaryOperatorType opType = BinaryOperatorType.Add; - if (value < 0) { - value = -value; - opType = BinaryOperatorType.Subtract; - } - return new BinaryOperatorExpression(expr, opType, new PrimitiveExpression(value, value.ToString(System.Globalization.NumberFormatInfo.InvariantInfo))); - } - } - - internal sealed class NullExpression : Expression - { - internal static readonly NullExpression Instance = new NullExpression(); - - public override bool IsNull { - get { - return true; - } - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) - { - return null; - } - - public override string ToString() - { - return String.Format("[NullExpression]"); - } - } -} diff --git a/ICSharpCode.NRefactory.VB/Ast/General/LocalVariableDeclaration.cs b/ICSharpCode.NRefactory.VB/Ast/General/LocalVariableDeclaration.cs deleted file mode 100644 index bc5a9f3f2..000000000 --- a/ICSharpCode.NRefactory.VB/Ast/General/LocalVariableDeclaration.cs +++ /dev/null @@ -1,99 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using System; -using System.Collections.Generic; - -namespace ICSharpCode.NRefactory.VB.Ast -{ - public class LocalVariableDeclaration : Statement - { - TypeReference typeReference; - Modifiers modifier = Modifiers.None; - List variables = new List(); - - public TypeReference TypeReference { - get { - return typeReference; - } - set { - typeReference = TypeReference.CheckNull(value); - if (!typeReference.IsNull) typeReference.Parent = this; - } - } - - public Modifiers Modifier { - get { - return modifier; - } - set { - modifier = value; - } - } - - public List Variables { - get { - return variables; - } - } - - public TypeReference GetTypeForVariable(int variableIndex) - { - if (!typeReference.IsNull) { - return typeReference; - } - - for (int i = variableIndex; i < Variables.Count;++i) { - if (!((VariableDeclaration)Variables[i]).TypeReference.IsNull) { - return ((VariableDeclaration)Variables[i]).TypeReference; - } - } - return null; - } - - public LocalVariableDeclaration(VariableDeclaration declaration) : this(TypeReference.Null) - { - Variables.Add(declaration); - } - - public LocalVariableDeclaration(TypeReference typeReference) - { - this.TypeReference = typeReference; - } - - public LocalVariableDeclaration(TypeReference typeReference, Modifiers modifier) - { - this.TypeReference = typeReference; - this.modifier = modifier; - } - - public LocalVariableDeclaration(Modifiers modifier) - { - this.typeReference = TypeReference.Null; - this.modifier = modifier; - } - - public VariableDeclaration GetVariableDeclaration(string variableName) - { - foreach (VariableDeclaration variableDeclaration in variables) { - if (variableDeclaration.Name == variableName) { - return variableDeclaration; - } - } - return null; - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) - { - return visitor.VisitLocalVariableDeclaration(this, data); - } - - public override string ToString() - { - return String.Format("[LocalVariableDeclaration: Type={0}, Modifier ={1} Variables={2}]", - typeReference, - modifier, - GetCollectionString(variables)); - } - } -} diff --git a/ICSharpCode.NRefactory.VB/Ast/General/ParameterDeclaration.cs b/ICSharpCode.NRefactory.VB/Ast/General/ParameterDeclaration.cs new file mode 100644 index 000000000..87b4162b4 --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/General/ParameterDeclaration.cs @@ -0,0 +1,40 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + public class ParameterDeclaration : AttributedNode + { + public Identifier Name { + get { return GetChildByRole(Roles.Identifier); } + set { SetChildByRole(Roles.Identifier, value); } + } + + public Expression OptionalValue { + get { return GetChildByRole(Roles.Expression); } + set { SetChildByRole(Roles.Expression, value); } + } + + public AstType ReturnType { + get { return GetChildByRole(Roles.Type); } + set { SetChildByRole(Roles.Type, value); } + } + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + var param = other as ParameterDeclaration; + return param != null && + MatchAttributesAndModifiers(param, match) && + Name.DoMatch(param.Name, match) && + OptionalValue.DoMatch(param.OptionalValue, match) && + ReturnType.DoMatch(param.ReturnType, match); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitParameterDeclaration(this, data); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/General/PrimitiveExpression.cs b/ICSharpCode.NRefactory.VB/Ast/General/PrimitiveExpression.cs deleted file mode 100644 index b7676a663..000000000 --- a/ICSharpCode.NRefactory.VB/Ast/General/PrimitiveExpression.cs +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using ICSharpCode.NRefactory.VB.PrettyPrinter; -using System; - -namespace ICSharpCode.NRefactory.VB.Ast -{ - public class PrimitiveExpression : Expression - { - string stringValue; - - public Parser.LiteralFormat LiteralFormat { get; set; } - public object Value { get; set; } - - public string StringValue { - get { - if (stringValue == null) - return VBNetOutputVisitor.ToVBNetString(this); - else - return stringValue; - } - set { - stringValue = value == null ? String.Empty : value; - } - } - - public PrimitiveExpression(object val) - { - this.Value = val; - } - - public PrimitiveExpression(object val, string stringValue) - { - this.Value = val; - this.StringValue = stringValue; - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) - { - return visitor.VisitPrimitiveExpression(this, data); - } - - public override string ToString() - { - return String.Format("[PrimitiveExpression: Value={1}, ValueType={2}, StringValue={0}]", - this.StringValue, - this.Value, - this.Value == null ? "null" : this.Value.GetType().FullName - ); - } - } -} diff --git a/ICSharpCode.NRefactory.VB/Ast/General/Statement.cs b/ICSharpCode.NRefactory.VB/Ast/General/Statement.cs deleted file mode 100644 index 8859bbc2f..000000000 --- a/ICSharpCode.NRefactory.VB/Ast/General/Statement.cs +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using System; - -namespace ICSharpCode.NRefactory.VB.Ast -{ - public abstract class Statement : AbstractNode, INullable - { - public static Statement Null { - get { - return NullStatement.Instance; - } - } - - public virtual bool IsNull { - get { - return false; - } - } - - public static Statement CheckNull(Statement statement) - { - return statement ?? NullStatement.Instance; - } - } - - public abstract class StatementWithEmbeddedStatement : Statement - { - Statement embeddedStatement; - - public Statement EmbeddedStatement { - get { - return embeddedStatement; - } - set { - embeddedStatement = Statement.CheckNull(value); - if (value != null) - value.Parent = this; - } - } - } - - internal sealed class NullStatement : Statement - { - public static readonly NullStatement Instance = new NullStatement(); - - public override bool IsNull { - get { return true; } - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) - { - return data; - } - - public override string ToString() - { - return String.Format("[NullStatement]"); - } - } -} diff --git a/ICSharpCode.NRefactory.VB/Ast/General/TypeParameterDeclaration.cs b/ICSharpCode.NRefactory.VB/Ast/General/TypeParameterDeclaration.cs new file mode 100644 index 000000000..794615fc2 --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/General/TypeParameterDeclaration.cs @@ -0,0 +1,44 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; +using System.Collections.Generic; +using System.Linq; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + /// + /// [In|Out] Name [As Contraints] + /// + /// Represents a type parameter. + /// + public class TypeParameterDeclaration : AstNode + { + public static readonly Role TypeConstraintRole = TypeDeclaration.InheritsTypeRole; + public static readonly Role VarianceRole = new Role("Variance"); + + public VarianceModifier Variance { get; set; } + + public string Name { + get { return GetChildByRole (Roles.Identifier).Name; } + set { SetChildByRole(Roles.Identifier, new Identifier(value, AstLocation.Empty)); } + } + + public AstNodeCollection Constraints { + get { return GetChildrenByRole(TypeConstraintRole); } + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitTypeParameterDeclaration(this, data); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + TypeParameterDeclaration o = other as TypeParameterDeclaration; + return o != null && this.Variance == o.Variance + && MatchString(this.Name, o.Name) + && this.Constraints.DoMatch(o.Constraints, match); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/Generated.cs b/ICSharpCode.NRefactory.VB/Ast/Generated.cs index 64315b83f..bd973a0d7 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Generated.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Generated.cs @@ -1,5153 +1,4866 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:4.0.30319.1 +//// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +//// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +//using System; +//using System.Collections.Generic; // -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace ICSharpCode.NRefactory.VB.Ast { - using System; - using System.Collections.Generic; - - - public class AddHandlerStatement : Statement { - - Expression eventExpression; - - Expression handlerExpression; - - public Expression EventExpression { - get { - return eventExpression; - } - set { - eventExpression = value ?? Expression.Null; - if (!eventExpression.IsNull) eventExpression.Parent = this; - } - } - - public Expression HandlerExpression { - get { - return handlerExpression; - } - set { - handlerExpression = value ?? Expression.Null; - if (!handlerExpression.IsNull) handlerExpression.Parent = this; - } - } - - public AddHandlerStatement(Expression eventExpression, Expression handlerExpression) { - EventExpression = eventExpression; - HandlerExpression = handlerExpression; - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitAddHandlerStatement(this, data); - } - - public override string ToString() { - return string.Format("[AddHandlerStatement EventExpression={0} HandlerExpression={1}]", EventExpression, HandlerExpression); - } - } - - public class AddressOfExpression : Expression { - - Expression expression; - - public Expression Expression { - get { - return expression; - } - set { - expression = value ?? Expression.Null; - if (!expression.IsNull) expression.Parent = this; - } - } - - public AddressOfExpression(Expression expression) { - Expression = expression; - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitAddressOfExpression(this, data); - } - - public override string ToString() { - return string.Format("[AddressOfExpression Expression={0}]", Expression); - } - } - - public class ArrayCreateExpression : Expression { - - TypeReference createType; - - List arguments; - - CollectionInitializerExpression arrayInitializer; - - public TypeReference CreateType { - get { - return createType; - } - set { - createType = value ?? TypeReference.Null; - if (!createType.IsNull) createType.Parent = this; - } - } - - public List Arguments { - get { - return arguments; - } - set { - arguments = value ?? new List(); - } - } - - public CollectionInitializerExpression ArrayInitializer { - get { - return arrayInitializer; - } - set { - arrayInitializer = value ?? CollectionInitializerExpression.Null; - if (!arrayInitializer.IsNull) arrayInitializer.Parent = this; - } - } - - public ArrayCreateExpression(TypeReference createType) { - CreateType = createType; - arguments = new List(); - arrayInitializer = CollectionInitializerExpression.Null; - } - - public ArrayCreateExpression(TypeReference createType, List arguments) { - CreateType = createType; - Arguments = arguments; - arrayInitializer = CollectionInitializerExpression.Null; - } - - public ArrayCreateExpression(TypeReference createType, CollectionInitializerExpression arrayInitializer) { - CreateType = createType; - ArrayInitializer = arrayInitializer; - arguments = new List(); - } - - public bool IsImplicitlyTyped { - get { - return createType.IsNull || string.IsNullOrEmpty(createType.Type); - } - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitArrayCreateExpression(this, data); - } - - public override string ToString() { - return string.Format("[ArrayCreateExpression CreateType={0} Arguments={1} ArrayInitializer={2}]", CreateType, GetCollectionString(Arguments), ArrayInitializer); - } - } - - public class AssignmentExpression : Expression { - - Expression left; - - AssignmentOperatorType op; - - Expression right; - - public Expression Left { - get { - return left; - } - set { - left = value ?? Expression.Null; - if (!left.IsNull) left.Parent = this; - } - } - - public AssignmentOperatorType Op { - get { - return op; - } - set { - op = value; - } - } - - public Expression Right { - get { - return right; - } - set { - right = value ?? Expression.Null; - if (!right.IsNull) right.Parent = this; - } - } - - public AssignmentExpression(Expression left, AssignmentOperatorType op, Expression right) { - Left = left; - Op = op; - Right = right; - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitAssignmentExpression(this, data); - } - - public override string ToString() { - return string.Format("[AssignmentExpression Left={0} Op={1} Right={2}]", Left, Op, Right); - } - } - - public class Attribute : AbstractNode { - - string name; - - List positionalArguments; - - List namedArguments; - - public string Name { - get { - return name; - } - set { - name = value ?? ""; - } - } - - public List PositionalArguments { - get { - return positionalArguments; - } - set { - positionalArguments = value ?? new List(); - } - } - - public List NamedArguments { - get { - return namedArguments; - } - set { - namedArguments = value ?? new List(); - } - } - - public Attribute() { - name = ""; - positionalArguments = new List(); - namedArguments = new List(); - } - - public Attribute(string name, List positionalArguments, List namedArguments) { - Name = name; - PositionalArguments = positionalArguments; - NamedArguments = namedArguments; - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitAttribute(this, data); - } - - public override string ToString() { - return string.Format("[Attribute Name={0} PositionalArguments={1} NamedArguments={2}]", Name, GetCollectionString(PositionalArguments), GetCollectionString(NamedArguments)); - } - } - - public abstract class AttributedNode : AbstractNode { - - List attributes; - - Modifiers modifier; - - public List Attributes { - get { - return attributes; - } - set { - attributes = value ?? new List(); - } - } - - public Modifiers Modifier { - get { - return modifier; - } - set { - modifier = value; - } - } - - protected AttributedNode() { - attributes = new List(); - } - - protected AttributedNode(List attributes) { - Attributes = attributes; - } - - protected AttributedNode(Modifiers modifier, List attributes) { - Modifier = modifier; - Attributes = attributes; - } - } - - public class AttributeSection : AbstractNode { - - string attributeTarget; - - List attributes; - - public string AttributeTarget { - get { - return attributeTarget; - } - set { - attributeTarget = value ?? ""; - } - } - - public List Attributes { - get { - return attributes; - } - set { - attributes = value ?? new List(); - } - } - - public AttributeSection() { - attributeTarget = ""; - attributes = new List(); - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitAttributeSection(this, data); - } - - public override string ToString() { - return string.Format("[AttributeSection AttributeTarget={0} Attributes={1}]", AttributeTarget, GetCollectionString(Attributes)); - } - } - - public class BaseReferenceExpression : Expression { - - public BaseReferenceExpression() { - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitBaseReferenceExpression(this, data); - } - - public override string ToString() { - return "[BaseReferenceExpression]"; - } - } - - public class BinaryOperatorExpression : Expression { - - Expression left; - - BinaryOperatorType op; - - Expression right; - - public Expression Left { - get { - return left; - } - set { - left = value ?? Expression.Null; - if (!left.IsNull) left.Parent = this; - } - } - - public BinaryOperatorType Op { - get { - return op; - } - set { - op = value; - } - } - - public Expression Right { - get { - return right; - } - set { - right = value ?? Expression.Null; - if (!right.IsNull) right.Parent = this; - } - } - - public BinaryOperatorExpression() { - left = Expression.Null; - right = Expression.Null; - } - - public BinaryOperatorExpression(Expression left, BinaryOperatorType op, Expression right) { - Left = left; - Op = op; - Right = right; - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitBinaryOperatorExpression(this, data); - } - - public override string ToString() { - return string.Format("[BinaryOperatorExpression Left={0} Op={1} Right={2}]", Left, Op, Right); - } - } - - public class CaseLabel : AbstractNode { - - Expression label; - - BinaryOperatorType binaryOperatorType; - - Expression toExpression; - - public Expression Label { - get { - return label; - } - set { - label = value ?? Expression.Null; - if (!label.IsNull) label.Parent = this; - } - } - - public BinaryOperatorType BinaryOperatorType { - get { - return binaryOperatorType; - } - set { - binaryOperatorType = value; - } - } - - public Expression ToExpression { - get { - return toExpression; - } - set { - toExpression = value ?? Expression.Null; - if (!toExpression.IsNull) toExpression.Parent = this; - } - } - - public CaseLabel() { - label = Expression.Null; - toExpression = Expression.Null; - } - - public CaseLabel(Expression label) { - Label = label; - toExpression = Expression.Null; - } - - public CaseLabel(Expression label, Expression toExpression) { - Label = label; - ToExpression = toExpression; - } - - public CaseLabel(BinaryOperatorType binaryOperatorType, Expression label) { - BinaryOperatorType = binaryOperatorType; - Label = label; - toExpression = Expression.Null; - } - - public bool IsDefault { - get { - return label.IsNull; - } - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitCaseLabel(this, data); - } - - public override string ToString() { - return string.Format("[CaseLabel Label={0} BinaryOperatorType={1} ToExpression={2}]", Label, BinaryOperatorType, ToExpression); - } - } - - public class CastExpression : Expression { - - TypeReference castTo; - - Expression expression; - - CastType castType; - - public TypeReference CastTo { - get { - return castTo; - } - set { - castTo = value ?? TypeReference.Null; - if (!castTo.IsNull) castTo.Parent = this; - } - } - - public Expression Expression { - get { - return expression; - } - set { - expression = value ?? Expression.Null; - if (!expression.IsNull) expression.Parent = this; - } - } - - public CastType CastType { - get { - return castType; - } - set { - castType = value; - } - } - - public CastExpression(TypeReference castTo) { - CastTo = castTo; - expression = Expression.Null; - } - - public CastExpression(TypeReference castTo, Expression expression, CastType castType) { - CastTo = castTo; - Expression = expression; - CastType = castType; - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitCastExpression(this, data); - } - - public override string ToString() { - return string.Format("[CastExpression CastTo={0} Expression={1} CastType={2}]", CastTo, Expression, CastType); - } - } - - public class CatchClause : AbstractNode { - - TypeReference typeReference; - - string variableName; - - Statement statementBlock; - - Expression condition; - - public TypeReference TypeReference { - get { - return typeReference; - } - set { - typeReference = value ?? TypeReference.Null; - if (!typeReference.IsNull) typeReference.Parent = this; - } - } - - public string VariableName { - get { - return variableName; - } - set { - variableName = value ?? ""; - } - } - - public Statement StatementBlock { - get { - return statementBlock; - } - set { - statementBlock = value ?? Statement.Null; - if (!statementBlock.IsNull) statementBlock.Parent = this; - } - } - - public Expression Condition { - get { - return condition; - } - set { - condition = value ?? Expression.Null; - if (!condition.IsNull) condition.Parent = this; - } - } - - public CatchClause(TypeReference typeReference, string variableName, Statement statementBlock) { - TypeReference = typeReference; - VariableName = variableName; - StatementBlock = statementBlock; - condition = Expression.Null; - } - - public CatchClause(TypeReference typeReference, string variableName, Statement statementBlock, Expression condition) { - TypeReference = typeReference; - VariableName = variableName; - StatementBlock = statementBlock; - Condition = condition; - } - - public CatchClause(Statement statementBlock) { - StatementBlock = statementBlock; - typeReference = TypeReference.Null; - variableName = ""; - condition = Expression.Null; - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitCatchClause(this, data); - } - - public override string ToString() { - return string.Format("[CatchClause TypeReference={0} VariableName={1} StatementBlock={2} Condition={3}]" + - "", TypeReference, VariableName, StatementBlock, Condition); - } - } - - public class ClassReferenceExpression : Expression { - - public ClassReferenceExpression() { - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitClassReferenceExpression(this, data); - } - - public override string ToString() { - return "[ClassReferenceExpression]"; - } - } - - public class CollectionInitializerExpression : Expression { - - List createExpressions; - - public List CreateExpressions { - get { - return createExpressions; - } - set { - createExpressions = value ?? new List(); - } - } - - public CollectionInitializerExpression() { - createExpressions = new List(); - } - - public CollectionInitializerExpression(List createExpressions) { - CreateExpressions = createExpressions; - } - - public new static CollectionInitializerExpression Null { - get { - return NullCollectionInitializerExpression.Instance; - } - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitCollectionInitializerExpression(this, data); - } - - public override string ToString() { - return string.Format("[CollectionInitializerExpression CreateExpressions={0}]", GetCollectionString(CreateExpressions)); - } - } - - internal sealed class NullCollectionInitializerExpression : CollectionInitializerExpression { - - internal static NullCollectionInitializerExpression Instance = new NullCollectionInitializerExpression(); - - public override bool IsNull { - get { - return true; - } - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return null; - } - - public override string ToString() { - return "[NullCollectionInitializerExpression]"; - } - } - - public class CollectionRangeVariable : AbstractNode, INullable { - - string identifier; - - Expression expression; - - TypeReference type; - - public string Identifier { - get { - return identifier; - } - set { - identifier = value ?? ""; - } - } - - public Expression Expression { - get { - return expression; - } - set { - expression = value ?? Expression.Null; - if (!expression.IsNull) expression.Parent = this; - } - } - - public TypeReference Type { - get { - return type; - } - set { - type = value ?? TypeReference.Null; - if (!type.IsNull) type.Parent = this; - } - } - - public CollectionRangeVariable() { - identifier = ""; - expression = Expression.Null; - type = TypeReference.Null; - } - - public virtual bool IsNull { - get { - return false; - } - } - - public static CollectionRangeVariable Null { - get { - return NullCollectionRangeVariable.Instance; - } - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitCollectionRangeVariable(this, data); - } - - public override string ToString() { - return string.Format("[CollectionRangeVariable Identifier={0} Expression={1} Type={2}]", Identifier, Expression, Type); - } - } - - internal sealed class NullCollectionRangeVariable : CollectionRangeVariable { - - internal static NullCollectionRangeVariable Instance = new NullCollectionRangeVariable(); - - public override bool IsNull { - get { - return true; - } - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return null; - } - - public override string ToString() { - return "[NullCollectionRangeVariable]"; - } - } - - public class ConditionalExpression : Expression { - - Expression condition; - - Expression trueExpression; - - Expression falseExpression; - - public Expression Condition { - get { - return condition; - } - set { - condition = value ?? Expression.Null; - if (!condition.IsNull) condition.Parent = this; - } - } - - public Expression TrueExpression { - get { - return trueExpression; - } - set { - trueExpression = value ?? Expression.Null; - if (!trueExpression.IsNull) trueExpression.Parent = this; - } - } - - public Expression FalseExpression { - get { - return falseExpression; - } - set { - falseExpression = value ?? Expression.Null; - if (!falseExpression.IsNull) falseExpression.Parent = this; - } - } - - public ConditionalExpression() { - condition = Expression.Null; - trueExpression = Expression.Null; - falseExpression = Expression.Null; - } - - public ConditionalExpression(Expression condition, Expression trueExpression, Expression falseExpression) { - Condition = condition; - TrueExpression = trueExpression; - FalseExpression = falseExpression; - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitConditionalExpression(this, data); - } - - public override string ToString() { - return string.Format("[ConditionalExpression Condition={0} TrueExpression={1} FalseExpression={2}]", Condition, TrueExpression, FalseExpression); - } - } - - public class ConstructorDeclaration : ParametrizedNode { - - ConstructorInitializer constructorInitializer; - - BlockStatement body; - - public ConstructorInitializer ConstructorInitializer { - get { - return constructorInitializer; - } - set { - constructorInitializer = value ?? ConstructorInitializer.Null; - if (!constructorInitializer.IsNull) constructorInitializer.Parent = this; - } - } - - public BlockStatement Body { - get { - return body; - } - set { - body = value ?? BlockStatement.Null; - if (!body.IsNull) body.Parent = this; - } - } - - public ConstructorDeclaration(string name, Modifiers modifier, List parameters, List attributes) { - Name = name; - Modifier = modifier; - Parameters = parameters; - Attributes = attributes; - constructorInitializer = ConstructorInitializer.Null; - body = BlockStatement.Null; - } - - public ConstructorDeclaration(string name, Modifiers modifier, List parameters, ConstructorInitializer constructorInitializer, List attributes) { - Name = name; - Modifier = modifier; - Parameters = parameters; - ConstructorInitializer = constructorInitializer; - Attributes = attributes; - body = BlockStatement.Null; - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitConstructorDeclaration(this, data); - } - - public override string ToString() { - return string.Format("[ConstructorDeclaration ConstructorInitializer={0} Body={1} Name={2} Parameters={" + - "3} Attributes={4} Modifier={5}]", ConstructorInitializer, Body, Name, GetCollectionString(Parameters), GetCollectionString(Attributes), Modifier); - } - } - - public class ConstructorInitializer : AbstractNode, INullable { - - ConstructorInitializerType constructorInitializerType; - - List arguments; - - public ConstructorInitializerType ConstructorInitializerType { - get { - return constructorInitializerType; - } - set { - constructorInitializerType = value; - } - } - - public List Arguments { - get { - return arguments; - } - set { - arguments = value ?? new List(); - } - } - - public ConstructorInitializer() { - arguments = new List(); - } - - public virtual bool IsNull { - get { - return false; - } - } - - public static ConstructorInitializer Null { - get { - return NullConstructorInitializer.Instance; - } - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitConstructorInitializer(this, data); - } - - public override string ToString() { - return string.Format("[ConstructorInitializer ConstructorInitializerType={0} Arguments={1}]", ConstructorInitializerType, GetCollectionString(Arguments)); - } - } - - internal sealed class NullConstructorInitializer : ConstructorInitializer { - - internal static NullConstructorInitializer Instance = new NullConstructorInitializer(); - - public override bool IsNull { - get { - return true; - } - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return null; - } - - public override string ToString() { - return "[NullConstructorInitializer]"; - } - } - - public class ContinueStatement : Statement { - - ContinueType continueType; - - public ContinueType ContinueType { - get { - return continueType; - } - set { - continueType = value; - } - } - - public ContinueStatement() { - } - - public ContinueStatement(ContinueType continueType) { - ContinueType = continueType; - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitContinueStatement(this, data); - } - - public override string ToString() { - return string.Format("[ContinueStatement ContinueType={0}]", ContinueType); - } - } - - public class DeclareDeclaration : ParametrizedNode { - - string alias; - - string library; - - CharsetModifier charset; - - TypeReference typeReference; - - public string Alias { - get { - return alias; - } - set { - alias = value ?? ""; - } - } - - public string Library { - get { - return library; - } - set { - library = value ?? ""; - } - } - - public CharsetModifier Charset { - get { - return charset; - } - set { - charset = value; - } - } - - public TypeReference TypeReference { - get { - return typeReference; - } - set { - typeReference = value ?? TypeReference.Null; - if (!typeReference.IsNull) typeReference.Parent = this; - } - } - - public DeclareDeclaration(string name, Modifiers modifier, TypeReference typeReference, List parameters, List attributes, string library, string alias, CharsetModifier charset) { - Name = name; - Modifier = modifier; - TypeReference = typeReference; - Parameters = parameters; - Attributes = attributes; - Library = library; - Alias = alias; - Charset = charset; - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitDeclareDeclaration(this, data); - } - - public override string ToString() { - return string.Format("[DeclareDeclaration Alias={0} Library={1} Charset={2} TypeReference={3} Name={4} " + - "Parameters={5} Attributes={6} Modifier={7}]", Alias, Library, Charset, TypeReference, Name, GetCollectionString(Parameters), GetCollectionString(Attributes), Modifier); - } - } - - public class DefaultValueExpression : Expression { - - TypeReference typeReference; - - public TypeReference TypeReference { - get { - return typeReference; - } - set { - typeReference = value ?? TypeReference.Null; - if (!typeReference.IsNull) typeReference.Parent = this; - } - } - - public DefaultValueExpression(TypeReference typeReference) { - TypeReference = typeReference; - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitDefaultValueExpression(this, data); - } - - public override string ToString() { - return string.Format("[DefaultValueExpression TypeReference={0}]", TypeReference); - } - } - - public class DelegateDeclaration : AttributedNode { - - string name; - - TypeReference returnType; - - List parameters; - - List templates; - - public string Name { - get { - return name; - } - set { - name = string.IsNullOrEmpty(value) ? "?" : value; - } - } - - public TypeReference ReturnType { - get { - return returnType; - } - set { - returnType = value ?? TypeReference.Null; - if (!returnType.IsNull) returnType.Parent = this; - } - } - - public List Parameters { - get { - return parameters; - } - set { - parameters = value ?? new List(); - } - } - - public List Templates { - get { - return templates; - } - set { - templates = value ?? new List(); - } - } - - public DelegateDeclaration(Modifiers modifier, List attributes) { - Modifier = modifier; - Attributes = attributes; - name = "?"; - returnType = TypeReference.Null; - parameters = new List(); - templates = new List(); - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitDelegateDeclaration(this, data); - } - - public override string ToString() { - return string.Format("[DelegateDeclaration Name={0} ReturnType={1} Parameters={2} Templates={3} Attribu" + - "tes={4} Modifier={5}]", Name, ReturnType, GetCollectionString(Parameters), GetCollectionString(Templates), GetCollectionString(Attributes), Modifier); - } - } - - public class DirectionExpression : Expression { - - FieldDirection fieldDirection; - - Expression expression; - - public FieldDirection FieldDirection { - get { - return fieldDirection; - } - set { - fieldDirection = value; - } - } - - public Expression Expression { - get { - return expression; - } - set { - expression = value ?? Expression.Null; - if (!expression.IsNull) expression.Parent = this; - } - } - - public DirectionExpression(FieldDirection fieldDirection, Expression expression) { - FieldDirection = fieldDirection; - Expression = expression; - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitDirectionExpression(this, data); - } - - public override string ToString() { - return string.Format("[DirectionExpression FieldDirection={0} Expression={1}]", FieldDirection, Expression); - } - } - - public class DoLoopStatement : StatementWithEmbeddedStatement { - - Expression condition; - - ConditionType conditionType; - - ConditionPosition conditionPosition; - - public Expression Condition { - get { - return condition; - } - set { - condition = value ?? Expression.Null; - if (!condition.IsNull) condition.Parent = this; - } - } - - public ConditionType ConditionType { - get { - return conditionType; - } - set { - conditionType = value; - } - } - - public ConditionPosition ConditionPosition { - get { - return conditionPosition; - } - set { - conditionPosition = value; - } - } - - public DoLoopStatement(Expression condition, Statement embeddedStatement, ConditionType conditionType, ConditionPosition conditionPosition) { - Condition = condition; - EmbeddedStatement = embeddedStatement; - ConditionType = conditionType; - ConditionPosition = conditionPosition; - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitDoLoopStatement(this, data); - } - - public override string ToString() { - return string.Format("[DoLoopStatement Condition={0} ConditionType={1} ConditionPosition={2} EmbeddedSt" + - "atement={3}]", Condition, ConditionType, ConditionPosition, EmbeddedStatement); - } - } - - public class ElseIfSection : StatementWithEmbeddedStatement { - - Expression condition; - - public Expression Condition { - get { - return condition; - } - set { - condition = value ?? Expression.Null; - if (!condition.IsNull) condition.Parent = this; - } - } - - public ElseIfSection(Expression condition, Statement embeddedStatement) { - Condition = condition; - EmbeddedStatement = embeddedStatement; - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitElseIfSection(this, data); - } - - public override string ToString() { - return string.Format("[ElseIfSection Condition={0} EmbeddedStatement={1}]", Condition, EmbeddedStatement); - } - } - - public class EndStatement : Statement { - - public EndStatement() { - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitEndStatement(this, data); - } - - public override string ToString() { - return "[EndStatement]"; - } - } - - public class EraseStatement : Statement { - - List expressions; - - public List Expressions { - get { - return expressions; - } - set { - expressions = value ?? new List(); - } - } - - public EraseStatement() { - expressions = new List(); - } - - public EraseStatement(List expressions) { - Expressions = expressions; - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitEraseStatement(this, data); - } - - public override string ToString() { - return string.Format("[EraseStatement Expressions={0}]", GetCollectionString(Expressions)); - } - } - - public class ErrorStatement : Statement { - - Expression expression; - - public Expression Expression { - get { - return expression; - } - set { - expression = value ?? Expression.Null; - if (!expression.IsNull) expression.Parent = this; - } - } - - public ErrorStatement(Expression expression) { - Expression = expression; - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitErrorStatement(this, data); - } - - public override string ToString() { - return string.Format("[ErrorStatement Expression={0}]", Expression); - } - } - - public class EventAddRegion : EventAddRemoveRegion { - - public EventAddRegion(List attributes) : - base(attributes) { - } - - public static EventAddRegion Null { - get { - return NullEventAddRegion.Instance; - } - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitEventAddRegion(this, data); - } - - public override string ToString() { - return string.Format("[EventAddRegion Block={0} Parameters={1} Attributes={2} Modifier={3}]", Block, GetCollectionString(Parameters), GetCollectionString(Attributes), Modifier); - } - } - - internal sealed class NullEventAddRegion : EventAddRegion { - - private NullEventAddRegion() : - base(null) { - } - - internal static NullEventAddRegion Instance = new NullEventAddRegion(); - - public override bool IsNull { - get { - return true; - } - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return null; - } - - public override string ToString() { - return "[NullEventAddRegion]"; - } - } - - public abstract class EventAddRemoveRegion : AttributedNode, INullable { - - BlockStatement block; - - List parameters; - - public BlockStatement Block { - get { - return block; - } - set { - block = value ?? BlockStatement.Null; - if (!block.IsNull) block.Parent = this; - } - } - - public List Parameters { - get { - return parameters; - } - set { - parameters = value ?? new List(); - } - } - - protected EventAddRemoveRegion(List attributes) { - Attributes = attributes; - block = BlockStatement.Null; - parameters = new List(); - } - - public virtual bool IsNull { - get { - return false; - } - } - } - - public class EventDeclaration : MemberNode { - - EventAddRegion addRegion; - - EventRemoveRegion removeRegion; - - EventRaiseRegion raiseRegion; - - Location bodyStart; - - Location bodyEnd; - - Expression initializer; - - public EventAddRegion AddRegion { - get { - return addRegion; - } - set { - addRegion = value ?? EventAddRegion.Null; - if (!addRegion.IsNull) addRegion.Parent = this; - } - } - - public EventRemoveRegion RemoveRegion { - get { - return removeRegion; - } - set { - removeRegion = value ?? EventRemoveRegion.Null; - if (!removeRegion.IsNull) removeRegion.Parent = this; - } - } - - public EventRaiseRegion RaiseRegion { - get { - return raiseRegion; - } - set { - raiseRegion = value ?? EventRaiseRegion.Null; - if (!raiseRegion.IsNull) raiseRegion.Parent = this; - } - } - - public Location BodyStart { - get { - return bodyStart; - } - set { - bodyStart = value; - } - } - - public Location BodyEnd { - get { - return bodyEnd; - } - set { - bodyEnd = value; - } - } - - public Expression Initializer { - get { - return initializer; - } - set { - initializer = value ?? Expression.Null; - if (!initializer.IsNull) initializer.Parent = this; - } - } - - public EventDeclaration() { - addRegion = EventAddRegion.Null; - removeRegion = EventRemoveRegion.Null; - raiseRegion = EventRaiseRegion.Null; - bodyStart = Location.Empty; - bodyEnd = Location.Empty; - initializer = Expression.Null; - } - - public bool HasAddRegion { - get { - return !addRegion.IsNull; - } - } - - public bool HasRemoveRegion { - get { - return !removeRegion.IsNull; - } - } - - public bool HasRaiseRegion { - get { - return !raiseRegion.IsNull; - } - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitEventDeclaration(this, data); - } - - public override string ToString() { - return string.Format("[EventDeclaration AddRegion={0} RemoveRegion={1} RaiseRegion={2} BodyStart={3} Bo" + - "dyEnd={4} Initializer={5} InterfaceImplementations={6} TypeReference={7} Name={8" + - "} Parameters={9} Attributes={10} Modifier={11}]", AddRegion, RemoveRegion, RaiseRegion, BodyStart, BodyEnd, Initializer, GetCollectionString(InterfaceImplementations), TypeReference, Name, GetCollectionString(Parameters), GetCollectionString(Attributes), Modifier); - } - } - - public class EventRaiseRegion : EventAddRemoveRegion { - - public EventRaiseRegion(List attributes) : - base(attributes) { - } - - public static EventRaiseRegion Null { - get { - return NullEventRaiseRegion.Instance; - } - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitEventRaiseRegion(this, data); - } - - public override string ToString() { - return string.Format("[EventRaiseRegion Block={0} Parameters={1} Attributes={2} Modifier={3}]", Block, GetCollectionString(Parameters), GetCollectionString(Attributes), Modifier); - } - } - - internal sealed class NullEventRaiseRegion : EventRaiseRegion { - - private NullEventRaiseRegion() : - base(null) { - } - - internal static NullEventRaiseRegion Instance = new NullEventRaiseRegion(); - - public override bool IsNull { - get { - return true; - } - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return null; - } - - public override string ToString() { - return "[NullEventRaiseRegion]"; - } - } - - public class EventRemoveRegion : EventAddRemoveRegion { - - public EventRemoveRegion(List attributes) : - base(attributes) { - } - - public static EventRemoveRegion Null { - get { - return NullEventRemoveRegion.Instance; - } - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitEventRemoveRegion(this, data); - } - - public override string ToString() { - return string.Format("[EventRemoveRegion Block={0} Parameters={1} Attributes={2} Modifier={3}]", Block, GetCollectionString(Parameters), GetCollectionString(Attributes), Modifier); - } - } - - internal sealed class NullEventRemoveRegion : EventRemoveRegion { - - private NullEventRemoveRegion() : - base(null) { - } - - internal static NullEventRemoveRegion Instance = new NullEventRemoveRegion(); - - public override bool IsNull { - get { - return true; - } - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return null; - } - - public override string ToString() { - return "[NullEventRemoveRegion]"; - } - } - - public class ExitStatement : Statement { - - ExitType exitType; - - public ExitType ExitType { - get { - return exitType; - } - set { - exitType = value; - } - } - - public ExitStatement(ExitType exitType) { - ExitType = exitType; - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitExitStatement(this, data); - } - - public override string ToString() { - return string.Format("[ExitStatement ExitType={0}]", ExitType); - } - } - - public class ExpressionRangeVariable : AbstractNode, INullable { - - string identifier; - - Expression expression; - - TypeReference type; - - public string Identifier { - get { - return identifier; - } - set { - identifier = value ?? ""; - } - } - - public Expression Expression { - get { - return expression; - } - set { - expression = value ?? Expression.Null; - if (!expression.IsNull) expression.Parent = this; - } - } - - public TypeReference Type { - get { - return type; - } - set { - type = value ?? TypeReference.Null; - if (!type.IsNull) type.Parent = this; - } - } - - public ExpressionRangeVariable() { - identifier = ""; - expression = Expression.Null; - type = TypeReference.Null; - } - - public virtual bool IsNull { - get { - return false; - } - } - - public static ExpressionRangeVariable Null { - get { - return NullExpressionRangeVariable.Instance; - } - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitExpressionRangeVariable(this, data); - } - - public override string ToString() { - return string.Format("[ExpressionRangeVariable Identifier={0} Expression={1} Type={2}]", Identifier, Expression, Type); - } - } - - internal sealed class NullExpressionRangeVariable : ExpressionRangeVariable { - - internal static NullExpressionRangeVariable Instance = new NullExpressionRangeVariable(); - - public override bool IsNull { - get { - return true; - } - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return null; - } - - public override string ToString() { - return "[NullExpressionRangeVariable]"; - } - } - - public class ExpressionStatement : Statement { - - Expression expression; - - public Expression Expression { - get { - return expression; - } - set { - expression = value ?? Expression.Null; - if (!expression.IsNull) expression.Parent = this; - } - } - - public ExpressionStatement(Expression expression) { - Expression = expression; - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitExpressionStatement(this, data); - } - - public override string ToString() { - return string.Format("[ExpressionStatement Expression={0}]", Expression); - } - } - - public class ExternAliasDirective : AbstractNode { - - string name; - - public string Name { - get { - return name; - } - set { - name = value ?? ""; - } - } - - public ExternAliasDirective() { - name = ""; - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitExternAliasDirective(this, data); - } - - public override string ToString() { - return string.Format("[ExternAliasDirective Name={0}]", Name); - } - } - - public class FieldDeclaration : AttributedNode { - - TypeReference typeReference; - - List fields; - - public TypeReference TypeReference { - get { - return typeReference; - } - set { - typeReference = value ?? TypeReference.Null; - if (!typeReference.IsNull) typeReference.Parent = this; - } - } - - public List Fields { - get { - return fields; - } - set { - fields = value ?? new List(); - } - } - - public FieldDeclaration(List attributes) { - Attributes = attributes; - typeReference = TypeReference.Null; - fields = new List(); - } - - public FieldDeclaration(List attributes, TypeReference typeReference, Modifiers modifier) { - Attributes = attributes; - TypeReference = typeReference; - Modifier = modifier; - fields = new List(); - } - - - public TypeReference GetTypeForField(int fieldIndex) - { - if (!typeReference.IsNull) { - return typeReference; - } - return ((VariableDeclaration)Fields[fieldIndex]).TypeReference; - } - - - public VariableDeclaration GetVariableDeclaration(string variableName) - { - foreach (VariableDeclaration variableDeclaration in Fields) { - if (variableDeclaration.Name == variableName) { - return variableDeclaration; - } - } - return null; - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitFieldDeclaration(this, data); - } - - public override string ToString() { - return string.Format("[FieldDeclaration TypeReference={0} Fields={1} Attributes={2} Modifier={3}]", TypeReference, GetCollectionString(Fields), GetCollectionString(Attributes), Modifier); - } - } - - public class ForeachStatement : StatementWithEmbeddedStatement { - - TypeReference typeReference; - - string variableName; - - Expression expression; - - Expression nextExpression; - - public TypeReference TypeReference { - get { - return typeReference; - } - set { - typeReference = value ?? TypeReference.Null; - if (!typeReference.IsNull) typeReference.Parent = this; - } - } - - public string VariableName { - get { - return variableName; - } - set { - variableName = value ?? ""; - } - } - - public Expression Expression { - get { - return expression; - } - set { - expression = value ?? Expression.Null; - if (!expression.IsNull) expression.Parent = this; - } - } - - public Expression NextExpression { - get { - return nextExpression; - } - set { - nextExpression = value ?? Expression.Null; - if (!nextExpression.IsNull) nextExpression.Parent = this; - } - } - - public ForeachStatement(TypeReference typeReference, string variableName, Expression expression, Statement embeddedStatement) { - TypeReference = typeReference; - VariableName = variableName; - Expression = expression; - EmbeddedStatement = embeddedStatement; - nextExpression = Expression.Null; - } - - public ForeachStatement(TypeReference typeReference, string variableName, Expression expression, Statement embeddedStatement, Expression nextExpression) { - TypeReference = typeReference; - VariableName = variableName; - Expression = expression; - EmbeddedStatement = embeddedStatement; - NextExpression = nextExpression; - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitForeachStatement(this, data); - } - - public override string ToString() { - return string.Format("[ForeachStatement TypeReference={0} VariableName={1} Expression={2} NextExpressio" + - "n={3} EmbeddedStatement={4}]", TypeReference, VariableName, Expression, NextExpression, EmbeddedStatement); - } - } - - public class ForNextStatement : StatementWithEmbeddedStatement { - - Expression start; - - Expression end; - - Expression step; - - List nextExpressions; - - TypeReference typeReference; - - string variableName; - - Expression loopVariableExpression; - - public Expression Start { - get { - return start; - } - set { - start = value ?? Expression.Null; - if (!start.IsNull) start.Parent = this; - } - } - - public Expression End { - get { - return end; - } - set { - end = value ?? Expression.Null; - if (!end.IsNull) end.Parent = this; - } - } - - public Expression Step { - get { - return step; - } - set { - step = value ?? Expression.Null; - if (!step.IsNull) step.Parent = this; - } - } - - public List NextExpressions { - get { - return nextExpressions; - } - set { - nextExpressions = value ?? new List(); - } - } - - public TypeReference TypeReference { - get { - return typeReference; - } - set { - typeReference = value ?? TypeReference.Null; - if (!typeReference.IsNull) typeReference.Parent = this; - } - } - - public string VariableName { - get { - return variableName; - } - set { - variableName = value ?? ""; - } - } - - public Expression LoopVariableExpression { - get { - return loopVariableExpression; - } - set { - loopVariableExpression = value ?? Expression.Null; - if (!loopVariableExpression.IsNull) loopVariableExpression.Parent = this; - } - } - - public ForNextStatement() { - start = Expression.Null; - end = Expression.Null; - step = Expression.Null; - nextExpressions = new List(); - typeReference = TypeReference.Null; - variableName = ""; - loopVariableExpression = Expression.Null; - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitForNextStatement(this, data); - } - - public override string ToString() { - return string.Format("[ForNextStatement Start={0} End={1} Step={2} NextExpressions={3} TypeReference={4" + - "} VariableName={5} LoopVariableExpression={6} EmbeddedStatement={7}]", Start, End, Step, GetCollectionString(NextExpressions), TypeReference, VariableName, LoopVariableExpression, EmbeddedStatement); - } - } - - public class GotoStatement : Statement { - - string label; - - public string Label { - get { - return label; - } - set { - label = value ?? ""; - } - } - - public GotoStatement(string label) { - Label = label; - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitGotoStatement(this, data); - } - - public override string ToString() { - return string.Format("[GotoStatement Label={0}]", Label); - } - } - - public class IdentifierExpression : Expression { - - string identifier; - - List typeArguments; - - public string Identifier { - get { - return identifier; - } - set { - identifier = value ?? ""; - } - } - - public List TypeArguments { - get { - return typeArguments; - } - set { - typeArguments = value ?? new List(); - } - } - - public IdentifierExpression(string identifier) { - Identifier = identifier; - typeArguments = new List(); - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitIdentifierExpression(this, data); - } - - public override string ToString() { - return string.Format("[IdentifierExpression Identifier={0} TypeArguments={1}]", Identifier, GetCollectionString(TypeArguments)); - } - } - - public class IfElseStatement : Statement { - - Expression condition; - - List trueStatement; - - List falseStatement; - - List elseIfSections; - - public Expression Condition { - get { - return condition; - } - set { - condition = value ?? Expression.Null; - if (!condition.IsNull) condition.Parent = this; - } - } - - public List TrueStatement { - get { - return trueStatement; - } - set { - trueStatement = value ?? new List(); - } - } - - public List FalseStatement { - get { - return falseStatement; - } - set { - falseStatement = value ?? new List(); - } - } - - public List ElseIfSections { - get { - return elseIfSections; - } - set { - elseIfSections = value ?? new List(); - } - } - - public IfElseStatement(Expression condition) { - Condition = condition; - trueStatement = new List(); - falseStatement = new List(); - elseIfSections = new List(); - } - - - public IfElseStatement(Expression condition, Statement trueStatement) - : this(condition) { - this.trueStatement.Add(Statement.CheckNull(trueStatement)); - if (trueStatement != null) trueStatement.Parent = this; - } - - public bool HasElseStatements { - get { - return falseStatement.Count > 0; - } - } - - public bool HasElseIfSections { - get { - return elseIfSections.Count > 0; - } - } - - - public IfElseStatement(Expression condition, Statement trueStatement, Statement falseStatement) - : this(condition) { - this.trueStatement.Add(Statement.CheckNull(trueStatement)); - this.falseStatement.Add(Statement.CheckNull(falseStatement)); - if (trueStatement != null) trueStatement.Parent = this; - if (falseStatement != null) falseStatement.Parent = this; - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitIfElseStatement(this, data); - } - - public override string ToString() { - return string.Format("[IfElseStatement Condition={0} TrueStatement={1} FalseStatement={2} ElseIfSection" + - "s={3}]", Condition, GetCollectionString(TrueStatement), GetCollectionString(FalseStatement), GetCollectionString(ElseIfSections)); - } - } - - public class InterfaceImplementation : AbstractNode { - - TypeReference interfaceType; - - string memberName; - - public TypeReference InterfaceType { - get { - return interfaceType; - } - set { - interfaceType = value ?? TypeReference.Null; - if (!interfaceType.IsNull) interfaceType.Parent = this; - } - } - - public string MemberName { - get { - return memberName; - } - set { - memberName = string.IsNullOrEmpty(value) ? "?" : value; - } - } - - public InterfaceImplementation(TypeReference interfaceType, string memberName) { - InterfaceType = interfaceType; - MemberName = memberName; - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitInterfaceImplementation(this, data); - } - - public override string ToString() { - return string.Format("[InterfaceImplementation InterfaceType={0} MemberName={1}]", InterfaceType, MemberName); - } - } - - public class InvocationExpression : Expression { - - Expression targetObject; - - List arguments; - - public Expression TargetObject { - get { - return targetObject; - } - set { - targetObject = value ?? Expression.Null; - if (!targetObject.IsNull) targetObject.Parent = this; - } - } - - public List Arguments { - get { - return arguments; - } - set { - arguments = value ?? new List(); - } - } - - public InvocationExpression(Expression targetObject) { - TargetObject = targetObject; - arguments = new List(); - } - - public InvocationExpression(Expression targetObject, List arguments) { - TargetObject = targetObject; - Arguments = arguments; - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitInvocationExpression(this, data); - } - - public override string ToString() { - return string.Format("[InvocationExpression TargetObject={0} Arguments={1}]", TargetObject, GetCollectionString(Arguments)); - } - } - - public class LabelStatement : Statement { - - string label; - - public string Label { - get { - return label; - } - set { - label = value ?? ""; - } - } - - public LabelStatement(string label) { - Label = label; - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitLabelStatement(this, data); - } - - public override string ToString() { - return string.Format("[LabelStatement Label={0}]", Label); - } - } - - public class LambdaExpression : Expression { - - List parameters; - - Statement statementBody; - - Expression expressionBody; - - TypeReference returnType; - - public List Parameters { - get { - return parameters; - } - set { - parameters = value ?? new List(); - } - } - - public Statement StatementBody { - get { - return statementBody; - } - set { - statementBody = value ?? Statement.Null; - if (!statementBody.IsNull) statementBody.Parent = this; - } - } - - public Expression ExpressionBody { - get { - return expressionBody; - } - set { - expressionBody = value ?? Expression.Null; - if (!expressionBody.IsNull) expressionBody.Parent = this; - } - } - - public TypeReference ReturnType { - get { - return returnType; - } - set { - returnType = value ?? TypeReference.Null; - if (!returnType.IsNull) returnType.Parent = this; - } - } - - public LambdaExpression() { - parameters = new List(); - statementBody = Statement.Null; - expressionBody = Expression.Null; - returnType = TypeReference.Null; - } - -public Location ExtendedEndLocation { get; set; } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitLambdaExpression(this, data); - } - - public override string ToString() { - return string.Format("[LambdaExpression Parameters={0} StatementBody={1} ExpressionBody={2} ReturnType=" + - "{3}]", GetCollectionString(Parameters), StatementBody, ExpressionBody, ReturnType); - } - } - - public class LockStatement : StatementWithEmbeddedStatement { - - Expression lockExpression; - - public Expression LockExpression { - get { - return lockExpression; - } - set { - lockExpression = value ?? Expression.Null; - if (!lockExpression.IsNull) lockExpression.Parent = this; - } - } - - public LockStatement(Expression lockExpression, Statement embeddedStatement) { - LockExpression = lockExpression; - EmbeddedStatement = embeddedStatement; - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitLockStatement(this, data); - } - - public override string ToString() { - return string.Format("[LockStatement LockExpression={0} EmbeddedStatement={1}]", LockExpression, EmbeddedStatement); - } - } - - public class MemberInitializerExpression : Expression { - - string name; - - bool isKey; - - Expression expression; - - public string Name { - get { - return name; - } - set { - name = value ?? ""; - } - } - - public bool IsKey { - get { - return isKey; - } - set { - isKey = value; - } - } - - public Expression Expression { - get { - return expression; - } - set { - expression = value ?? Expression.Null; - if (!expression.IsNull) expression.Parent = this; - } - } - - public MemberInitializerExpression() { - name = ""; - expression = Expression.Null; - } - - public MemberInitializerExpression(string name, Expression expression) { - Name = name; - Expression = expression; - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitMemberInitializerExpression(this, data); - } - - public override string ToString() { - return string.Format("[MemberInitializerExpression Name={0} IsKey={1} Expression={2}]", Name, IsKey, Expression); - } - } - - public abstract class MemberNode : ParametrizedNode { - - List interfaceImplementations; - - TypeReference typeReference; - - public List InterfaceImplementations { - get { - return interfaceImplementations; - } - set { - interfaceImplementations = value ?? new List(); - } - } - - public TypeReference TypeReference { - get { - return typeReference; - } - set { - typeReference = value ?? TypeReference.Null; - if (!typeReference.IsNull) typeReference.Parent = this; - } - } - - protected MemberNode() { - interfaceImplementations = new List(); - typeReference = TypeReference.Null; - } - - protected MemberNode(Modifiers modifier, List attributes, string name, List parameters) { - Modifier = modifier; - Attributes = attributes; - Name = name; - Parameters = parameters; - interfaceImplementations = new List(); - typeReference = TypeReference.Null; - } - } - - public class MemberReferenceExpression : Expression { - - Expression targetObject; - - string memberName; - - List typeArguments; - - public Expression TargetObject { - get { - return targetObject; - } - set { - targetObject = value ?? Expression.Null; - if (!targetObject.IsNull) targetObject.Parent = this; - } - } - - public string MemberName { - get { - return memberName; - } - set { - memberName = value ?? ""; - } - } - - public List TypeArguments { - get { - return typeArguments; - } - set { - typeArguments = value ?? new List(); - } - } - - public MemberReferenceExpression(Expression targetObject, string memberName) { - TargetObject = targetObject; - MemberName = memberName; - typeArguments = new List(); - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitMemberReferenceExpression(this, data); - } - - public override string ToString() { - return string.Format("[MemberReferenceExpression TargetObject={0} MemberName={1} TypeArguments={2}]", TargetObject, MemberName, GetCollectionString(TypeArguments)); - } - } - - public class MethodDeclaration : MemberNode { - - BlockStatement body; - - List handlesClause; - - List templates; - - bool isExtensionMethod; - - public BlockStatement Body { - get { - return body; - } - set { - body = value ?? BlockStatement.Null; - if (!body.IsNull) body.Parent = this; - } - } - - public List HandlesClause { - get { - return handlesClause; - } - set { - handlesClause = value ?? new List(); - } - } - - public List Templates { - get { - return templates; - } - set { - templates = value ?? new List(); - } - } - - public bool IsExtensionMethod { - get { - return isExtensionMethod; - } - set { - isExtensionMethod = value; - } - } - - public MethodDeclaration() { - body = BlockStatement.Null; - handlesClause = new List(); - templates = new List(); - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitMethodDeclaration(this, data); - } - - public override string ToString() { - return string.Format("[MethodDeclaration Body={0} HandlesClause={1} Templates={2} IsExtensionMethod={3}" + - " InterfaceImplementations={4} TypeReference={5} Name={6} Parameters={7} Attribut" + - "es={8} Modifier={9}]", Body, GetCollectionString(HandlesClause), GetCollectionString(Templates), IsExtensionMethod, GetCollectionString(InterfaceImplementations), TypeReference, Name, GetCollectionString(Parameters), GetCollectionString(Attributes), Modifier); - } - } - - public class NamedArgumentExpression : Expression { - - string name; - - Expression expression; - - public string Name { - get { - return name; - } - set { - name = value ?? ""; - } - } - - public Expression Expression { - get { - return expression; - } - set { - expression = value ?? Expression.Null; - if (!expression.IsNull) expression.Parent = this; - } - } - - public NamedArgumentExpression() { - name = ""; - expression = Expression.Null; - } - - public NamedArgumentExpression(string name, Expression expression) { - Name = name; - Expression = expression; - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitNamedArgumentExpression(this, data); - } - - public override string ToString() { - return string.Format("[NamedArgumentExpression Name={0} Expression={1}]", Name, Expression); - } - } - - public class NamespaceDeclaration : AbstractNode { - - string name; - - public string Name { - get { - return name; - } - set { - name = value ?? ""; - } - } - - public NamespaceDeclaration(string name) { - Name = name; - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitNamespaceDeclaration(this, data); - } - - public override string ToString() { - return string.Format("[NamespaceDeclaration Name={0}]", Name); - } - } - - public class ObjectCreateExpression : Expression { - - TypeReference createType; - - List parameters; - - CollectionInitializerExpression objectInitializer; - - public TypeReference CreateType { - get { - return createType; - } - set { - createType = value ?? TypeReference.Null; - if (!createType.IsNull) createType.Parent = this; - } - } - - public List Parameters { - get { - return parameters; - } - set { - parameters = value ?? new List(); - } - } - - public CollectionInitializerExpression ObjectInitializer { - get { - return objectInitializer; - } - set { - objectInitializer = value ?? CollectionInitializerExpression.Null; - if (!objectInitializer.IsNull) objectInitializer.Parent = this; - } - } - - public ObjectCreateExpression(TypeReference createType, List parameters) { - CreateType = createType; - Parameters = parameters; - objectInitializer = CollectionInitializerExpression.Null; - } - - public bool IsAnonymousType { - get { - return createType.IsNull || string.IsNullOrEmpty(createType.Type); - } - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitObjectCreateExpression(this, data); - } - - public override string ToString() { - return string.Format("[ObjectCreateExpression CreateType={0} Parameters={1} ObjectInitializer={2}]", CreateType, GetCollectionString(Parameters), ObjectInitializer); - } - } - - public class OnErrorStatement : StatementWithEmbeddedStatement { - - public OnErrorStatement(Statement embeddedStatement) { - EmbeddedStatement = embeddedStatement; - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitOnErrorStatement(this, data); - } - - public override string ToString() { - return string.Format("[OnErrorStatement EmbeddedStatement={0}]", EmbeddedStatement); - } - } - - public class OperatorDeclaration : MethodDeclaration { - - ConversionType conversionType; - - OverloadableOperatorType overloadableOperator; - - public ConversionType ConversionType { - get { - return conversionType; - } - set { - conversionType = value; - } - } - - public OverloadableOperatorType OverloadableOperator { - get { - return overloadableOperator; - } - set { - overloadableOperator = value; - } - } - - public OperatorDeclaration() { - } - - public bool IsConversionOperator { - get { - return conversionType != ConversionType.None; - } - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitOperatorDeclaration(this, data); - } - - public override string ToString() { - return string.Format("[OperatorDeclaration ConversionType={0} OverloadableOperator={1} Body={2} Handles" + - "Clause={3} Templates={4} IsExtensionMethod={5} InterfaceImplementations={6} Type" + - "Reference={7} Name={8} Parameters={9} Attributes={10} Modifier={11}]", ConversionType, OverloadableOperator, Body, GetCollectionString(HandlesClause), GetCollectionString(Templates), IsExtensionMethod, GetCollectionString(InterfaceImplementations), TypeReference, Name, GetCollectionString(Parameters), GetCollectionString(Attributes), Modifier); - } - } - - public class OptionDeclaration : AbstractNode { - - OptionType optionType; - - bool optionValue; - - public OptionType OptionType { - get { - return optionType; - } - set { - optionType = value; - } - } - - public bool OptionValue { - get { - return optionValue; - } - set { - optionValue = value; - } - } - - public OptionDeclaration(OptionType optionType, bool optionValue) { - OptionType = optionType; - OptionValue = optionValue; - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitOptionDeclaration(this, data); - } - - public override string ToString() { - return string.Format("[OptionDeclaration OptionType={0} OptionValue={1}]", OptionType, OptionValue); - } - } - - public class ParameterDeclarationExpression : Expression { - - List attributes; - - string parameterName; - - TypeReference typeReference; - - ParameterModifiers paramModifier; - - Expression defaultValue; - - public List Attributes { - get { - return attributes; - } - set { - attributes = value ?? new List(); - } - } - - public string ParameterName { - get { - return parameterName; - } - set { - parameterName = string.IsNullOrEmpty(value) ? "?" : value; - } - } - - public TypeReference TypeReference { - get { - return typeReference; - } - set { - typeReference = value ?? TypeReference.Null; - if (!typeReference.IsNull) typeReference.Parent = this; - } - } - - public ParameterModifiers ParamModifier { - get { - return paramModifier; - } - set { - paramModifier = value; - } - } - - public Expression DefaultValue { - get { - return defaultValue; - } - set { - defaultValue = value ?? Expression.Null; - if (!defaultValue.IsNull) defaultValue.Parent = this; - } - } - - public ParameterDeclarationExpression(TypeReference typeReference, string parameterName) { - TypeReference = typeReference; - ParameterName = parameterName; - attributes = new List(); - defaultValue = Expression.Null; - } - - public ParameterDeclarationExpression(TypeReference typeReference, string parameterName, ParameterModifiers paramModifier) { - TypeReference = typeReference; - ParameterName = parameterName; - ParamModifier = paramModifier; - attributes = new List(); - defaultValue = Expression.Null; - } - - public ParameterDeclarationExpression(TypeReference typeReference, string parameterName, ParameterModifiers paramModifier, Expression defaultValue) { - TypeReference = typeReference; - ParameterName = parameterName; - ParamModifier = paramModifier; - DefaultValue = defaultValue; - attributes = new List(); - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitParameterDeclarationExpression(this, data); - } - - public override string ToString() { - return string.Format("[ParameterDeclarationExpression Attributes={0} ParameterName={1} TypeReference={2" + - "} ParamModifier={3} DefaultValue={4}]", GetCollectionString(Attributes), ParameterName, TypeReference, ParamModifier, DefaultValue); - } - } - - public abstract class ParametrizedNode : AttributedNode { - - string name; - - List parameters; - - public string Name { - get { - return name; - } - set { - name = value ?? ""; - } - } - - public List Parameters { - get { - return parameters; - } - set { - parameters = value ?? new List(); - } - } - - protected ParametrizedNode() { - name = ""; - parameters = new List(); - } - - protected ParametrizedNode(Modifiers modifier, List attributes, string name, List parameters) { - Modifier = modifier; - Attributes = attributes; - Name = name; - Parameters = parameters; - } - } - - public class ParenthesizedExpression : Expression { - - Expression expression; - - public Expression Expression { - get { - return expression; - } - set { - expression = value ?? Expression.Null; - if (!expression.IsNull) expression.Parent = this; - } - } - - public ParenthesizedExpression(Expression expression) { - Expression = expression; - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitParenthesizedExpression(this, data); - } - - public override string ToString() { - return string.Format("[ParenthesizedExpression Expression={0}]", Expression); - } - } - - public class PropertyDeclaration : MemberNode { - - Location bodyStart; - - Location bodyEnd; - - PropertyGetRegion getRegion; - - PropertySetRegion setRegion; - - Expression initializer; - - public Location BodyStart { - get { - return bodyStart; - } - set { - bodyStart = value; - } - } - - public Location BodyEnd { - get { - return bodyEnd; - } - set { - bodyEnd = value; - } - } - - public PropertyGetRegion GetRegion { - get { - return getRegion; - } - set { - getRegion = value ?? PropertyGetRegion.Null; - if (!getRegion.IsNull) getRegion.Parent = this; - } - } - - public PropertySetRegion SetRegion { - get { - return setRegion; - } - set { - setRegion = value ?? PropertySetRegion.Null; - if (!setRegion.IsNull) setRegion.Parent = this; - } - } - - public Expression Initializer { - get { - return initializer; - } - set { - initializer = value ?? Expression.Null; - if (!initializer.IsNull) initializer.Parent = this; - } - } - - public PropertyDeclaration(Modifiers modifier, List attributes, string name, List parameters) { - Modifier = modifier; - Attributes = attributes; - Name = name; - Parameters = parameters; - bodyStart = Location.Empty; - bodyEnd = Location.Empty; - getRegion = PropertyGetRegion.Null; - setRegion = PropertySetRegion.Null; - initializer = Expression.Null; - } - - public bool IsReadOnly { - get { - return HasGetRegion && !HasSetRegion; - } - } - - public bool HasGetRegion { - get { - return !getRegion.IsNull; - } - } - - public bool IsWriteOnly { - get { - return !HasGetRegion && HasSetRegion; - } - } - - public bool IsIndexer { - get { - return (Modifier & Modifiers.Default) != 0; - } - } - - - internal PropertyDeclaration(string name, TypeReference typeReference, Modifiers modifier, List attributes) : this(modifier, attributes, name, null) - { - this.TypeReference = typeReference; - if ((modifier & Modifiers.ReadOnly) != Modifiers.ReadOnly) { - this.SetRegion = new PropertySetRegion(null, null); - } - if ((modifier & Modifiers.WriteOnly) != Modifiers.WriteOnly) { - this.GetRegion = new PropertyGetRegion(null, null); - } - } - - public bool HasSetRegion { - get { - return !setRegion.IsNull; - } - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitPropertyDeclaration(this, data); - } - - public override string ToString() { - return string.Format("[PropertyDeclaration BodyStart={0} BodyEnd={1} GetRegion={2} SetRegion={3} Initia" + - "lizer={4} InterfaceImplementations={5} TypeReference={6} Name={7} Parameters={8}" + - " Attributes={9} Modifier={10}]", BodyStart, BodyEnd, GetRegion, SetRegion, Initializer, GetCollectionString(InterfaceImplementations), TypeReference, Name, GetCollectionString(Parameters), GetCollectionString(Attributes), Modifier); - } - } - - public class PropertyGetRegion : PropertyGetSetRegion { - - public PropertyGetRegion(BlockStatement block, List attributes) : - base(block, attributes) { - } - - public static PropertyGetRegion Null { - get { - return NullPropertyGetRegion.Instance; - } - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitPropertyGetRegion(this, data); - } - - public override string ToString() { - return string.Format("[PropertyGetRegion Block={0} Attributes={1} Modifier={2}]", Block, GetCollectionString(Attributes), Modifier); - } - } - - internal sealed class NullPropertyGetRegion : PropertyGetRegion { - - private NullPropertyGetRegion() : - base(null, null) { - } - - internal static NullPropertyGetRegion Instance = new NullPropertyGetRegion(); - - public override bool IsNull { - get { - return true; - } - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return null; - } - - public override string ToString() { - return "[NullPropertyGetRegion]"; - } - } - - public abstract class PropertyGetSetRegion : AttributedNode, INullable { - - BlockStatement block; - - public BlockStatement Block { - get { - return block; - } - set { - block = value ?? BlockStatement.Null; - if (!block.IsNull) block.Parent = this; - } - } - - protected PropertyGetSetRegion(BlockStatement block, List attributes) { - Block = block; - Attributes = attributes; - } - - public virtual bool IsNull { - get { - return false; - } - } - } - - public class PropertySetRegion : PropertyGetSetRegion { - - List parameters; - - public List Parameters { - get { - return parameters; - } - set { - parameters = value ?? new List(); - } - } - - public PropertySetRegion(BlockStatement block, List attributes) : - base(block, attributes) { - parameters = new List(); - } - - public static PropertySetRegion Null { - get { - return NullPropertySetRegion.Instance; - } - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitPropertySetRegion(this, data); - } - - public override string ToString() { - return string.Format("[PropertySetRegion Parameters={0} Block={1} Attributes={2} Modifier={3}]", GetCollectionString(Parameters), Block, GetCollectionString(Attributes), Modifier); - } - } - - internal sealed class NullPropertySetRegion : PropertySetRegion { - - private NullPropertySetRegion() : - base(null, null) { - } - - internal static NullPropertySetRegion Instance = new NullPropertySetRegion(); - - public override bool IsNull { - get { - return true; - } - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return null; - } - - public override string ToString() { - return "[NullPropertySetRegion]"; - } - } - - public class QueryExpression : Expression { - - List clauses; - - public List Clauses { - get { - return clauses; - } - set { - clauses = value ?? new List(); - } - } - - public QueryExpression() { - clauses = new List(); - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitQueryExpression(this, data); - } - - public override string ToString() { - return string.Format("[QueryExpression Clauses={0}]", GetCollectionString(Clauses)); - } - } - - public class QueryExpressionAggregateClause : QueryExpressionClause { - - CollectionRangeVariable source; - - List middleClauses; - - List intoVariables; - - public CollectionRangeVariable Source { - get { - return source; - } - set { - source = value ?? CollectionRangeVariable.Null; - if (!source.IsNull) source.Parent = this; - } - } - - public List MiddleClauses { - get { - return middleClauses; - } - set { - middleClauses = value ?? new List(); - } - } - - public List IntoVariables { - get { - return intoVariables; - } - set { - intoVariables = value ?? new List(); - } - } - - public QueryExpressionAggregateClause() { - source = CollectionRangeVariable.Null; - middleClauses = new List(); - intoVariables = new List(); - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitQueryExpressionAggregateClause(this, data); - } - - public override string ToString() { - return string.Format("[QueryExpressionAggregateClause Source={0} MiddleClauses={1} IntoVariables={2}]", Source, GetCollectionString(MiddleClauses), GetCollectionString(IntoVariables)); - } - } - - public abstract class QueryExpressionClause : AbstractNode, INullable { - - protected QueryExpressionClause() { - } - - public virtual bool IsNull { - get { - return false; - } - } - - public static QueryExpressionClause Null { - get { - return NullQueryExpressionClause.Instance; - } - } - } - - internal sealed class NullQueryExpressionClause : QueryExpressionClause { - - internal static NullQueryExpressionClause Instance = new NullQueryExpressionClause(); - - public override bool IsNull { - get { - return true; - } - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return null; - } - - public override string ToString() { - return "[NullQueryExpressionClause]"; - } - } - - public class QueryExpressionDistinctClause : QueryExpressionClause { - - public QueryExpressionDistinctClause() { - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitQueryExpressionDistinctClause(this, data); - } - - public override string ToString() { - return "[QueryExpressionDistinctClause]"; - } - } - - public class QueryExpressionFromClause : QueryExpressionClause { - - List sources; - - public List Sources { - get { - return sources; - } - set { - sources = value ?? new List(); - } - } - - public QueryExpressionFromClause() { - sources = new List(); - } - - public new static QueryExpressionFromClause Null { - get { - return NullQueryExpressionFromClause.Instance; - } - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitQueryExpressionFromClause(this, data); - } - - public override string ToString() { - return string.Format("[QueryExpressionFromClause Sources={0}]", GetCollectionString(Sources)); - } - } - - internal sealed class NullQueryExpressionFromClause : QueryExpressionFromClause { - - internal static NullQueryExpressionFromClause Instance = new NullQueryExpressionFromClause(); - - public override bool IsNull { - get { - return true; - } - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return null; - } - - public override string ToString() { - return "[NullQueryExpressionFromClause]"; - } - } - - public class QueryExpressionGroupClause : QueryExpressionClause { - - Expression projection; - - Expression groupBy; - - public Expression Projection { - get { - return projection; - } - set { - projection = value ?? Expression.Null; - if (!projection.IsNull) projection.Parent = this; - } - } - - public Expression GroupBy { - get { - return groupBy; - } - set { - groupBy = value ?? Expression.Null; - if (!groupBy.IsNull) groupBy.Parent = this; - } - } - - public QueryExpressionGroupClause() { - projection = Expression.Null; - groupBy = Expression.Null; - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitQueryExpressionGroupClause(this, data); - } - - public override string ToString() { - return string.Format("[QueryExpressionGroupClause Projection={0} GroupBy={1}]", Projection, GroupBy); - } - } - - public class QueryExpressionGroupJoinVBClause : QueryExpressionClause { - - QueryExpressionJoinVBClause joinClause; - - List intoVariables; - - public QueryExpressionJoinVBClause JoinClause { - get { - return joinClause; - } - set { - joinClause = value ?? QueryExpressionJoinVBClause.Null; - if (!joinClause.IsNull) joinClause.Parent = this; - } - } - - public List IntoVariables { - get { - return intoVariables; - } - set { - intoVariables = value ?? new List(); - } - } - - public QueryExpressionGroupJoinVBClause() { - joinClause = QueryExpressionJoinVBClause.Null; - intoVariables = new List(); - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitQueryExpressionGroupJoinVBClause(this, data); - } - - public override string ToString() { - return string.Format("[QueryExpressionGroupJoinVBClause JoinClause={0} IntoVariables={1}]", JoinClause, GetCollectionString(IntoVariables)); - } - } - - public class QueryExpressionGroupVBClause : QueryExpressionClause { - - List groupVariables; - - List byVariables; - - List intoVariables; - - public List GroupVariables { - get { - return groupVariables; - } - set { - groupVariables = value ?? new List(); - } - } - - public List ByVariables { - get { - return byVariables; - } - set { - byVariables = value ?? new List(); - } - } - - public List IntoVariables { - get { - return intoVariables; - } - set { - intoVariables = value ?? new List(); - } - } - - public QueryExpressionGroupVBClause() { - groupVariables = new List(); - byVariables = new List(); - intoVariables = new List(); - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitQueryExpressionGroupVBClause(this, data); - } - - public override string ToString() { - return string.Format("[QueryExpressionGroupVBClause GroupVariables={0} ByVariables={1} IntoVariables={2" + - "}]", GetCollectionString(GroupVariables), GetCollectionString(ByVariables), GetCollectionString(IntoVariables)); - } - } - - public class QueryExpressionJoinClause : QueryExpressionClause { - - Expression onExpression; - - Expression equalsExpression; - - CollectionRangeVariable source; - - string intoIdentifier; - - public Expression OnExpression { - get { - return onExpression; - } - set { - onExpression = value ?? Expression.Null; - if (!onExpression.IsNull) onExpression.Parent = this; - } - } - - public Expression EqualsExpression { - get { - return equalsExpression; - } - set { - equalsExpression = value ?? Expression.Null; - if (!equalsExpression.IsNull) equalsExpression.Parent = this; - } - } - - public CollectionRangeVariable Source { - get { - return source; - } - set { - source = value ?? CollectionRangeVariable.Null; - if (!source.IsNull) source.Parent = this; - } - } - - public string IntoIdentifier { - get { - return intoIdentifier; - } - set { - intoIdentifier = value ?? ""; - } - } - - public QueryExpressionJoinClause() { - onExpression = Expression.Null; - equalsExpression = Expression.Null; - source = CollectionRangeVariable.Null; - intoIdentifier = ""; - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitQueryExpressionJoinClause(this, data); - } - - public override string ToString() { - return string.Format("[QueryExpressionJoinClause OnExpression={0} EqualsExpression={1} Source={2} IntoI" + - "dentifier={3}]", OnExpression, EqualsExpression, Source, IntoIdentifier); - } - } - - public class QueryExpressionJoinConditionVB : AbstractNode { - - Expression leftSide; - - Expression rightSide; - - public Expression LeftSide { - get { - return leftSide; - } - set { - leftSide = value ?? Expression.Null; - if (!leftSide.IsNull) leftSide.Parent = this; - } - } - - public Expression RightSide { - get { - return rightSide; - } - set { - rightSide = value ?? Expression.Null; - if (!rightSide.IsNull) rightSide.Parent = this; - } - } - - public QueryExpressionJoinConditionVB() { - leftSide = Expression.Null; - rightSide = Expression.Null; - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitQueryExpressionJoinConditionVB(this, data); - } - - public override string ToString() { - return string.Format("[QueryExpressionJoinConditionVB LeftSide={0} RightSide={1}]", LeftSide, RightSide); - } - } - - public class QueryExpressionJoinVBClause : QueryExpressionClause { - - CollectionRangeVariable joinVariable; - - QueryExpressionJoinVBClause subJoin; - - List conditions; - - public CollectionRangeVariable JoinVariable { - get { - return joinVariable; - } - set { - joinVariable = value ?? CollectionRangeVariable.Null; - if (!joinVariable.IsNull) joinVariable.Parent = this; - } - } - - public QueryExpressionJoinVBClause SubJoin { - get { - return subJoin; - } - set { - subJoin = value ?? QueryExpressionJoinVBClause.Null; - if (!subJoin.IsNull) subJoin.Parent = this; - } - } - - public List Conditions { - get { - return conditions; - } - set { - conditions = value ?? new List(); - } - } - - public QueryExpressionJoinVBClause() { - joinVariable = CollectionRangeVariable.Null; - subJoin = QueryExpressionJoinVBClause.Null; - conditions = new List(); - } - - public new static QueryExpressionJoinVBClause Null { - get { - return NullQueryExpressionJoinVBClause.Instance; - } - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitQueryExpressionJoinVBClause(this, data); - } - - public override string ToString() { - return string.Format("[QueryExpressionJoinVBClause JoinVariable={0} SubJoin={1} Conditions={2}]", JoinVariable, SubJoin, GetCollectionString(Conditions)); - } - } - - internal sealed class NullQueryExpressionJoinVBClause : QueryExpressionJoinVBClause { - - internal static NullQueryExpressionJoinVBClause Instance = new NullQueryExpressionJoinVBClause(); - - public override bool IsNull { - get { - return true; - } - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return null; - } - - public override string ToString() { - return "[NullQueryExpressionJoinVBClause]"; - } - } - - public class QueryExpressionLetClause : QueryExpressionClause { - - string identifier; - - Expression expression; - - public string Identifier { - get { - return identifier; - } - set { - identifier = string.IsNullOrEmpty(value) ? "?" : value; - } - } - - public Expression Expression { - get { - return expression; - } - set { - expression = value ?? Expression.Null; - if (!expression.IsNull) expression.Parent = this; - } - } - - public QueryExpressionLetClause() { - identifier = "?"; - expression = Expression.Null; - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitQueryExpressionLetClause(this, data); - } - - public override string ToString() { - return string.Format("[QueryExpressionLetClause Identifier={0} Expression={1}]", Identifier, Expression); - } - } - - public class QueryExpressionLetVBClause : QueryExpressionClause { - - List variables; - - public List Variables { - get { - return variables; - } - set { - variables = value ?? new List(); - } - } - - public QueryExpressionLetVBClause() { - variables = new List(); - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitQueryExpressionLetVBClause(this, data); - } - - public override string ToString() { - return string.Format("[QueryExpressionLetVBClause Variables={0}]", GetCollectionString(Variables)); - } - } - - public class QueryExpressionOrderClause : QueryExpressionClause { - - List orderings; - - public List Orderings { - get { - return orderings; - } - set { - orderings = value ?? new List(); - } - } - - public QueryExpressionOrderClause() { - orderings = new List(); - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitQueryExpressionOrderClause(this, data); - } - - public override string ToString() { - return string.Format("[QueryExpressionOrderClause Orderings={0}]", GetCollectionString(Orderings)); - } - } - - public class QueryExpressionOrdering : AbstractNode { - - Expression criteria; - - QueryExpressionOrderingDirection direction; - - public Expression Criteria { - get { - return criteria; - } - set { - criteria = value ?? Expression.Null; - if (!criteria.IsNull) criteria.Parent = this; - } - } - - public QueryExpressionOrderingDirection Direction { - get { - return direction; - } - set { - direction = value; - } - } - - public QueryExpressionOrdering() { - criteria = Expression.Null; - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitQueryExpressionOrdering(this, data); - } - - public override string ToString() { - return string.Format("[QueryExpressionOrdering Criteria={0} Direction={1}]", Criteria, Direction); - } - } - - public class QueryExpressionPartitionVBClause : QueryExpressionClause { - - Expression expression; - - QueryExpressionPartitionType partitionType; - - public Expression Expression { - get { - return expression; - } - set { - expression = value ?? Expression.Null; - if (!expression.IsNull) expression.Parent = this; - } - } - - public QueryExpressionPartitionType PartitionType { - get { - return partitionType; - } - set { - partitionType = value; - } - } - - public QueryExpressionPartitionVBClause() { - expression = Expression.Null; - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitQueryExpressionPartitionVBClause(this, data); - } - - public override string ToString() { - return string.Format("[QueryExpressionPartitionVBClause Expression={0} PartitionType={1}]", Expression, PartitionType); - } - } - - public class QueryExpressionSelectClause : QueryExpressionClause { - - Expression projection; - - public Expression Projection { - get { - return projection; - } - set { - projection = value ?? Expression.Null; - if (!projection.IsNull) projection.Parent = this; - } - } - - public QueryExpressionSelectClause() { - projection = Expression.Null; - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitQueryExpressionSelectClause(this, data); - } - - public override string ToString() { - return string.Format("[QueryExpressionSelectClause Projection={0}]", Projection); - } - } - - public class QueryExpressionSelectVBClause : QueryExpressionClause { - - List variables; - - public List Variables { - get { - return variables; - } - set { - variables = value ?? new List(); - } - } - - public QueryExpressionSelectVBClause() { - variables = new List(); - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitQueryExpressionSelectVBClause(this, data); - } - - public override string ToString() { - return string.Format("[QueryExpressionSelectVBClause Variables={0}]", GetCollectionString(Variables)); - } - } - - public class QueryExpressionWhereClause : QueryExpressionClause { - - Expression condition; - - public Expression Condition { - get { - return condition; - } - set { - condition = value ?? Expression.Null; - if (!condition.IsNull) condition.Parent = this; - } - } - - public QueryExpressionWhereClause() { - condition = Expression.Null; - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitQueryExpressionWhereClause(this, data); - } - - public override string ToString() { - return string.Format("[QueryExpressionWhereClause Condition={0}]", Condition); - } - } - - public class RaiseEventStatement : Statement { - - string eventName; - - List arguments; - - public string EventName { - get { - return eventName; - } - set { - eventName = value ?? ""; - } - } - - public List Arguments { - get { - return arguments; - } - set { - arguments = value ?? new List(); - } - } - - public RaiseEventStatement(string eventName, List arguments) { - EventName = eventName; - Arguments = arguments; - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitRaiseEventStatement(this, data); - } - - public override string ToString() { - return string.Format("[RaiseEventStatement EventName={0} Arguments={1}]", EventName, GetCollectionString(Arguments)); - } - } - - public class ReDimStatement : Statement { - - List reDimClauses; - - bool isPreserve; - - public List ReDimClauses { - get { - return reDimClauses; - } - set { - reDimClauses = value ?? new List(); - } - } - - public bool IsPreserve { - get { - return isPreserve; - } - set { - isPreserve = value; - } - } - - public ReDimStatement(bool isPreserve) { - IsPreserve = isPreserve; - reDimClauses = new List(); - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitReDimStatement(this, data); - } - - public override string ToString() { - return string.Format("[ReDimStatement ReDimClauses={0} IsPreserve={1}]", GetCollectionString(ReDimClauses), IsPreserve); - } - } - - public class RemoveHandlerStatement : Statement { - - Expression eventExpression; - - Expression handlerExpression; - - public Expression EventExpression { - get { - return eventExpression; - } - set { - eventExpression = value ?? Expression.Null; - if (!eventExpression.IsNull) eventExpression.Parent = this; - } - } - - public Expression HandlerExpression { - get { - return handlerExpression; - } - set { - handlerExpression = value ?? Expression.Null; - if (!handlerExpression.IsNull) handlerExpression.Parent = this; - } - } - - public RemoveHandlerStatement(Expression eventExpression, Expression handlerExpression) { - EventExpression = eventExpression; - HandlerExpression = handlerExpression; - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitRemoveHandlerStatement(this, data); - } - - public override string ToString() { - return string.Format("[RemoveHandlerStatement EventExpression={0} HandlerExpression={1}]", EventExpression, HandlerExpression); - } - } - - public class ResumeStatement : Statement { - - string labelName; - - bool isResumeNext; - - public string LabelName { - get { - return labelName; - } - set { - labelName = value ?? ""; - } - } - - public bool IsResumeNext { - get { - return isResumeNext; - } - set { - isResumeNext = value; - } - } - - public ResumeStatement(bool isResumeNext) { - IsResumeNext = isResumeNext; - labelName = ""; - } - - public ResumeStatement(string labelName) { - LabelName = labelName; - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitResumeStatement(this, data); - } - - public override string ToString() { - return string.Format("[ResumeStatement LabelName={0} IsResumeNext={1}]", LabelName, IsResumeNext); - } - } - - public class ReturnStatement : Statement { - - Expression expression; - - public Expression Expression { - get { - return expression; - } - set { - expression = value ?? Expression.Null; - if (!expression.IsNull) expression.Parent = this; - } - } - - public ReturnStatement(Expression expression) { - Expression = expression; - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitReturnStatement(this, data); - } - - public override string ToString() { - return string.Format("[ReturnStatement Expression={0}]", Expression); - } - } - - public class StopStatement : Statement { - - public StopStatement() { - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitStopStatement(this, data); - } - - public override string ToString() { - return "[StopStatement]"; - } - } - - public class SwitchSection : BlockStatement { - - List switchLabels; - - public List SwitchLabels { - get { - return switchLabels; - } - set { - switchLabels = value ?? new List(); - } - } - - public SwitchSection() { - switchLabels = new List(); - } - - public SwitchSection(List switchLabels) { - SwitchLabels = switchLabels; - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitSwitchSection(this, data); - } - - public override string ToString() { - return string.Format("[SwitchSection SwitchLabels={0}]", GetCollectionString(SwitchLabels)); - } - } - - public class SwitchStatement : Statement { - - Expression switchExpression; - - List switchSections; - - public Expression SwitchExpression { - get { - return switchExpression; - } - set { - switchExpression = value ?? Expression.Null; - if (!switchExpression.IsNull) switchExpression.Parent = this; - } - } - - public List SwitchSections { - get { - return switchSections; - } - set { - switchSections = value ?? new List(); - } - } - - public SwitchStatement(Expression switchExpression, List switchSections) { - SwitchExpression = switchExpression; - SwitchSections = switchSections; - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitSwitchStatement(this, data); - } - - public override string ToString() { - return string.Format("[SwitchStatement SwitchExpression={0} SwitchSections={1}]", SwitchExpression, GetCollectionString(SwitchSections)); - } - } - - public class TemplateDefinition : AttributedNode { - - string name; - - VarianceModifier varianceModifier; - - List bases; - - public string Name { - get { - return name; - } - set { - name = string.IsNullOrEmpty(value) ? "?" : value; - } - } - - public VarianceModifier VarianceModifier { - get { - return varianceModifier; - } - set { - varianceModifier = value; - } - } - - public List Bases { - get { - return bases; - } - set { - bases = value ?? new List(); - } - } - - public TemplateDefinition() { - name = "?"; - bases = new List(); - } - - public TemplateDefinition(string name, List attributes) { - Name = name; - Attributes = attributes; - bases = new List(); - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitTemplateDefinition(this, data); - } - - public override string ToString() { - return string.Format("[TemplateDefinition Name={0} VarianceModifier={1} Bases={2} Attributes={3} Modifi" + - "er={4}]", Name, VarianceModifier, GetCollectionString(Bases), GetCollectionString(Attributes), Modifier); - } - } - - public class ThisReferenceExpression : Expression { - - public ThisReferenceExpression() { - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitThisReferenceExpression(this, data); - } - - public override string ToString() { - return "[ThisReferenceExpression]"; - } - } - - public class ThrowStatement : Statement { - - Expression expression; - - public Expression Expression { - get { - return expression; - } - set { - expression = value ?? Expression.Null; - if (!expression.IsNull) expression.Parent = this; - } - } - - public ThrowStatement(Expression expression) { - Expression = expression; - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitThrowStatement(this, data); - } - - public override string ToString() { - return string.Format("[ThrowStatement Expression={0}]", Expression); - } - } - - public class TryCatchStatement : Statement { - - Statement statementBlock; - - List catchClauses; - - Statement finallyBlock; - - public Statement StatementBlock { - get { - return statementBlock; - } - set { - statementBlock = value ?? Statement.Null; - if (!statementBlock.IsNull) statementBlock.Parent = this; - } - } - - public List CatchClauses { - get { - return catchClauses; - } - set { - catchClauses = value ?? new List(); - } - } - - public Statement FinallyBlock { - get { - return finallyBlock; - } - set { - finallyBlock = value ?? Statement.Null; - if (!finallyBlock.IsNull) finallyBlock.Parent = this; - } - } - - public TryCatchStatement(Statement statementBlock, List catchClauses, Statement finallyBlock) { - StatementBlock = statementBlock; - CatchClauses = catchClauses; - FinallyBlock = finallyBlock; - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitTryCatchStatement(this, data); - } - - public override string ToString() { - return string.Format("[TryCatchStatement StatementBlock={0} CatchClauses={1} FinallyBlock={2}]", StatementBlock, GetCollectionString(CatchClauses), FinallyBlock); - } - } - - public class TypeDeclaration : AttributedNode { - - string name; - - ClassType type; - - List baseTypes; - - List templates; - - Location bodyStartLocation; - - public string Name { - get { - return name; - } - set { - name = value ?? ""; - } - } - - public ClassType Type { - get { - return type; - } - set { - type = value; - } - } - - public List BaseTypes { - get { - return baseTypes; - } - set { - baseTypes = value ?? new List(); - } - } - - public List Templates { - get { - return templates; - } - set { - templates = value ?? new List(); - } - } - - public Location BodyStartLocation { - get { - return bodyStartLocation; - } - set { - bodyStartLocation = value; - } - } - - public TypeDeclaration(Modifiers modifier, List attributes) { - Modifier = modifier; - Attributes = attributes; - name = ""; - baseTypes = new List(); - templates = new List(); - bodyStartLocation = Location.Empty; - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitTypeDeclaration(this, data); - } - - public override string ToString() { - return string.Format("[TypeDeclaration Name={0} Type={1} BaseTypes={2} Templates={3} BodyStartLocation=" + - "{4} Attributes={5} Modifier={6}]", Name, Type, GetCollectionString(BaseTypes), GetCollectionString(Templates), BodyStartLocation, GetCollectionString(Attributes), Modifier); - } - } - - public class TypeOfExpression : Expression { - - TypeReference typeReference; - - public TypeReference TypeReference { - get { - return typeReference; - } - set { - typeReference = value ?? TypeReference.Null; - if (!typeReference.IsNull) typeReference.Parent = this; - } - } - - public TypeOfExpression(TypeReference typeReference) { - TypeReference = typeReference; - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitTypeOfExpression(this, data); - } - - public override string ToString() { - return string.Format("[TypeOfExpression TypeReference={0}]", TypeReference); - } - } - - public class TypeOfIsExpression : Expression { - - Expression expression; - - TypeReference typeReference; - - public Expression Expression { - get { - return expression; - } - set { - expression = value ?? Expression.Null; - if (!expression.IsNull) expression.Parent = this; - } - } - - public TypeReference TypeReference { - get { - return typeReference; - } - set { - typeReference = value ?? TypeReference.Null; - if (!typeReference.IsNull) typeReference.Parent = this; - } - } - - public TypeOfIsExpression(Expression expression, TypeReference typeReference) { - Expression = expression; - TypeReference = typeReference; - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitTypeOfIsExpression(this, data); - } - - public override string ToString() { - return string.Format("[TypeOfIsExpression Expression={0} TypeReference={1}]", Expression, TypeReference); - } - } - - public class TypeReferenceExpression : Expression { - - TypeReference typeReference; - - public TypeReference TypeReference { - get { - return typeReference; - } - set { - typeReference = value ?? TypeReference.Null; - if (!typeReference.IsNull) typeReference.Parent = this; - } - } - - public TypeReferenceExpression(TypeReference typeReference) { - TypeReference = typeReference; - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitTypeReferenceExpression(this, data); - } - - public override string ToString() { - return string.Format("[TypeReferenceExpression TypeReference={0}]", TypeReference); - } - } - - public class UnaryOperatorExpression : Expression { - - UnaryOperatorType op; - - Expression expression; - - public UnaryOperatorType Op { - get { - return op; - } - set { - op = value; - } - } - - public Expression Expression { - get { - return expression; - } - set { - expression = value ?? Expression.Null; - if (!expression.IsNull) expression.Parent = this; - } - } - - public UnaryOperatorExpression(UnaryOperatorType op) { - Op = op; - expression = Expression.Null; - } - - public UnaryOperatorExpression(Expression expression, UnaryOperatorType op) { - Expression = expression; - Op = op; - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitUnaryOperatorExpression(this, data); - } - - public override string ToString() { - return string.Format("[UnaryOperatorExpression Op={0} Expression={1}]", Op, Expression); - } - } - - public class Using : AbstractNode { - - string name; - - TypeReference alias; - - string xmlPrefix; - - public string Name { - get { - return name; - } - set { - name = string.IsNullOrEmpty(value) ? "?" : value; - } - } - - public TypeReference Alias { - get { - return alias; - } - set { - alias = value ?? TypeReference.Null; - if (!alias.IsNull) alias.Parent = this; - } - } - - public string XmlPrefix { - get { - return xmlPrefix; - } - set { - xmlPrefix = value ?? ""; - } - } - - public Using(string name) { - Name = name; - alias = TypeReference.Null; - xmlPrefix = ""; - } - - public Using(string name, TypeReference alias) { - Name = name; - Alias = alias; - xmlPrefix = ""; - } - - public Using(string name, string xmlPrefix) { - Name = name; - XmlPrefix = xmlPrefix; - alias = TypeReference.Null; - } - - public bool IsXml { - get { - return xmlPrefix != null; - } - } - - public bool IsAlias { - get { - return !alias.IsNull; - } - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitUsing(this, data); - } - - public override string ToString() { - return string.Format("[Using Name={0} Alias={1} XmlPrefix={2}]", Name, Alias, XmlPrefix); - } - } - - public class UsingDeclaration : AbstractNode { - - List usings; - - public List Usings { - get { - return usings; - } - set { - usings = value ?? new List(); - } - } - - public UsingDeclaration(List usings) { - Usings = usings; - } - -public UsingDeclaration(string xmlNamespace, string prefix) { usings = new List(1); usings.Add(new Using(xmlNamespace, prefix)); } - -public UsingDeclaration(string @namespace) : this(@namespace, TypeReference.Null) {} - -public UsingDeclaration(string @namespace, TypeReference alias) { usings = new List(1); usings.Add(new Using(@namespace, alias)); } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitUsingDeclaration(this, data); - } - - public override string ToString() { - return string.Format("[UsingDeclaration Usings={0}]", GetCollectionString(Usings)); - } - } - - public class UsingStatement : StatementWithEmbeddedStatement { - - Statement resourceAcquisition; - - public Statement ResourceAcquisition { - get { - return resourceAcquisition; - } - set { - resourceAcquisition = value ?? Statement.Null; - if (!resourceAcquisition.IsNull) resourceAcquisition.Parent = this; - } - } - - public UsingStatement(Statement resourceAcquisition, Statement embeddedStatement) { - ResourceAcquisition = resourceAcquisition; - EmbeddedStatement = embeddedStatement; - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitUsingStatement(this, data); - } - - public override string ToString() { - return string.Format("[UsingStatement ResourceAcquisition={0} EmbeddedStatement={1}]", ResourceAcquisition, EmbeddedStatement); - } - } - - public class VariableDeclaration : AbstractNode { - - string name; - - Expression initializer; - - TypeReference typeReference; - - Expression fixedArrayInitialization; - - public string Name { - get { - return name; - } - set { - name = value ?? ""; - } - } - - public Expression Initializer { - get { - return initializer; - } - set { - initializer = value ?? Expression.Null; - if (!initializer.IsNull) initializer.Parent = this; - } - } - - public TypeReference TypeReference { - get { - return typeReference; - } - set { - typeReference = value ?? TypeReference.Null; - if (!typeReference.IsNull) typeReference.Parent = this; - } - } - - public Expression FixedArrayInitialization { - get { - return fixedArrayInitialization; - } - set { - fixedArrayInitialization = value ?? Expression.Null; - if (!fixedArrayInitialization.IsNull) fixedArrayInitialization.Parent = this; - } - } - - public VariableDeclaration(string name) { - Name = name; - initializer = Expression.Null; - typeReference = TypeReference.Null; - fixedArrayInitialization = Expression.Null; - } - - public VariableDeclaration(string name, Expression initializer) { - Name = name; - Initializer = initializer; - typeReference = TypeReference.Null; - fixedArrayInitialization = Expression.Null; - } - - public VariableDeclaration(string name, Expression initializer, TypeReference typeReference) { - Name = name; - Initializer = initializer; - TypeReference = typeReference; - fixedArrayInitialization = Expression.Null; - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitVariableDeclaration(this, data); - } - - public override string ToString() { - return string.Format("[VariableDeclaration Name={0} Initializer={1} TypeReference={2} FixedArrayInitial" + - "ization={3}]", Name, Initializer, TypeReference, FixedArrayInitialization); - } - } - - public class WithStatement : Statement { - - Expression expression; - - BlockStatement body; - - public Expression Expression { - get { - return expression; - } - set { - expression = value ?? Expression.Null; - if (!expression.IsNull) expression.Parent = this; - } - } - - public BlockStatement Body { - get { - return body; - } - set { - body = value ?? BlockStatement.Null; - if (!body.IsNull) body.Parent = this; - } - } - - public WithStatement(Expression expression) { - Expression = expression; - body = BlockStatement.Null; - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitWithStatement(this, data); - } - - public override string ToString() { - return string.Format("[WithStatement Expression={0} Body={1}]", Expression, Body); - } - } - - public class XmlAttributeExpression : XmlExpression { - - string name; - - string literalValue; - - bool useDoubleQuotes; - - Expression expressionValue; - - public string Name { - get { - return name; - } - set { - name = value ?? ""; - } - } - - public string LiteralValue { - get { - return literalValue; - } - set { - literalValue = value ?? ""; - } - } - - public bool UseDoubleQuotes { - get { - return useDoubleQuotes; - } - set { - useDoubleQuotes = value; - } - } - - public Expression ExpressionValue { - get { - return expressionValue; - } - set { - expressionValue = value ?? Expression.Null; - if (!expressionValue.IsNull) expressionValue.Parent = this; - } - } - - public XmlAttributeExpression() { - name = ""; - literalValue = ""; - expressionValue = Expression.Null; - } - - public bool IsLiteralValue { - get { - return expressionValue.IsNull; - } - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitXmlAttributeExpression(this, data); - } - - public override string ToString() { - return string.Format("[XmlAttributeExpression Name={0} LiteralValue={1} UseDoubleQuotes={2} ExpressionV" + - "alue={3}]", Name, LiteralValue, UseDoubleQuotes, ExpressionValue); - } - } - - public class XmlContentExpression : XmlExpression { - - string content; - - XmlContentType type; - - public string Content { - get { - return content; - } - set { - content = value ?? ""; - } - } - - public XmlContentType Type { - get { - return type; - } - set { - type = value; - } - } - - public XmlContentExpression(string content, XmlContentType type) { - Content = content; - Type = type; - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitXmlContentExpression(this, data); - } - - public override string ToString() { - return string.Format("[XmlContentExpression Content={0} Type={1}]", Content, Type); - } - } - - public class XmlDocumentExpression : XmlExpression { - - List expressions; - - public List Expressions { - get { - return expressions; - } - set { - expressions = value ?? new List(); - } - } - - public XmlDocumentExpression() { - expressions = new List(); - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitXmlDocumentExpression(this, data); - } - - public override string ToString() { - return string.Format("[XmlDocumentExpression Expressions={0}]", GetCollectionString(Expressions)); - } - } - - public class XmlElementExpression : XmlExpression { - - Expression content; - - Expression nameExpression; - - string xmlName; - - List attributes; - - public Expression Content { - get { - return content; - } - set { - content = value ?? Expression.Null; - if (!content.IsNull) content.Parent = this; - } - } - - public Expression NameExpression { - get { - return nameExpression; - } - set { - nameExpression = value ?? Expression.Null; - if (!nameExpression.IsNull) nameExpression.Parent = this; - } - } - - public string XmlName { - get { - return xmlName; - } - set { - xmlName = value ?? ""; - } - } - - public List Attributes { - get { - return attributes; - } - set { - attributes = value ?? new List(); - } - } - - public XmlElementExpression() { - content = Expression.Null; - nameExpression = Expression.Null; - xmlName = ""; - attributes = new List(); - } - - public bool IsExpression { - get { - return !content.IsNull; - } - } - - public bool NameIsExpression { - get { - return !nameExpression.IsNull; - } - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitXmlElementExpression(this, data); - } - - public override string ToString() { - return string.Format("[XmlElementExpression Content={0} NameExpression={1} XmlName={2} Attributes={3}]", Content, NameExpression, XmlName, GetCollectionString(Attributes)); - } - } - - public class XmlEmbeddedExpression : XmlExpression { - - Expression inlineVBExpression; - - public Expression InlineVBExpression { - get { - return inlineVBExpression; - } - set { - inlineVBExpression = value ?? Expression.Null; - if (!inlineVBExpression.IsNull) inlineVBExpression.Parent = this; - } - } - - public XmlEmbeddedExpression() { - inlineVBExpression = Expression.Null; - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitXmlEmbeddedExpression(this, data); - } - - public override string ToString() { - return string.Format("[XmlEmbeddedExpression InlineVBExpression={0}]", InlineVBExpression); - } - } - - public abstract class XmlExpression : Expression { - - protected XmlExpression() { - } - } - - public class XmlMemberAccessExpression : Expression { - - Expression targetObject; - - XmlAxisType axisType; - - bool isXmlIdentifier; - - string identifier; - - public Expression TargetObject { - get { - return targetObject; - } - set { - targetObject = value ?? Expression.Null; - if (!targetObject.IsNull) targetObject.Parent = this; - } - } - - public XmlAxisType AxisType { - get { - return axisType; - } - set { - axisType = value; - } - } - - public bool IsXmlIdentifier { - get { - return isXmlIdentifier; - } - set { - isXmlIdentifier = value; - } - } - - public string Identifier { - get { - return identifier; - } - set { - identifier = value ?? ""; - } - } - - public XmlMemberAccessExpression(Expression targetObject, XmlAxisType axisType, string identifier, bool isXmlIdentifier) { - TargetObject = targetObject; - AxisType = axisType; - Identifier = identifier; - IsXmlIdentifier = isXmlIdentifier; - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitXmlMemberAccessExpression(this, data); - } - - public override string ToString() { - return string.Format("[XmlMemberAccessExpression TargetObject={0} AxisType={1} IsXmlIdentifier={2} Iden" + - "tifier={3}]", TargetObject, AxisType, IsXmlIdentifier, Identifier); - } - } -} +//namespace ICSharpCode.NRefactory.VB.Ast { +// public class AddHandlerStatement : Statement { +// +// Expression eventExpression; +// +// Expression handlerExpression; +// +// public Expression EventExpression { +// get { +// return eventExpression; +// } +// set { +// eventExpression = value ?? Expression.Null; +// if (!eventExpression.IsNull) eventExpression.Parent = this; +// } +// } +// +// public Expression HandlerExpression { +// get { +// return handlerExpression; +// } +// set { +// handlerExpression = value ?? Expression.Null; +// if (!handlerExpression.IsNull) handlerExpression.Parent = this; +// } +// } +// +// public AddHandlerStatement(Expression eventExpression, Expression handlerExpression) { +// EventExpression = eventExpression; +// HandlerExpression = handlerExpression; +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitAddHandlerStatement(this, data); +// } +// +// public override string ToString() { +// return string.Format("[AddHandlerStatement EventExpression={0} HandlerExpression={1}]", EventExpression, HandlerExpression); +// } +// } +// +// public class AddressOfExpression : Expression { +// +// Expression expression; +// +// public Expression Expression { +// get { +// return expression; +// } +// set { +// expression = value ?? Expression.Null; +// if (!expression.IsNull) expression.Parent = this; +// } +// } +// +// public AddressOfExpression(Expression expression) { +// Expression = expression; +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitAddressOfExpression(this, data); +// } +// +// public override string ToString() { +// return string.Format("[AddressOfExpression Expression={0}]", Expression); +// } +// } +// +// public class ArrayCreateExpression : Expression { +// +// TypeReference createType; +// +// List arguments; +// +// CollectionInitializerExpression arrayInitializer; +// +// public TypeReference CreateType { +// get { +// return createType; +// } +// set { +// createType = value ?? TypeReference.Null; +// if (!createType.IsNull) createType.Parent = this; +// } +// } +// +// public List Arguments { +// get { +// return arguments; +// } +// set { +// arguments = value ?? new List(); +// } +// } +// +// public CollectionInitializerExpression ArrayInitializer { +// get { +// return arrayInitializer; +// } +// set { +// arrayInitializer = value ?? CollectionInitializerExpression.Null; +// if (!arrayInitializer.IsNull) arrayInitializer.Parent = this; +// } +// } +// +// public ArrayCreateExpression(TypeReference createType) { +// CreateType = createType; +// arguments = new List(); +// arrayInitializer = CollectionInitializerExpression.Null; +// } +// +// public ArrayCreateExpression(TypeReference createType, List arguments) { +// CreateType = createType; +// Arguments = arguments; +// arrayInitializer = CollectionInitializerExpression.Null; +// } +// +// public ArrayCreateExpression(TypeReference createType, CollectionInitializerExpression arrayInitializer) { +// CreateType = createType; +// ArrayInitializer = arrayInitializer; +// arguments = new List(); +// } +// +// public bool IsImplicitlyTyped { +// get { +// return createType.IsNull || string.IsNullOrEmpty(createType.Type); +// } +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitArrayCreateExpression(this, data); +// } +// +// public override string ToString() { +// return string.Format("[ArrayCreateExpression CreateType={0} Arguments={1} ArrayInitializer={2}]", CreateType, GetCollectionString(Arguments), ArrayInitializer); +// } +// } +// +// public class AssignmentExpression : Expression { +// +// Expression left; +// +// AssignmentOperatorType op; +// +// Expression right; +// +// public Expression Left { +// get { +// return left; +// } +// set { +// left = value ?? Expression.Null; +// if (!left.IsNull) left.Parent = this; +// } +// } +// +// public AssignmentOperatorType Op { +// get { +// return op; +// } +// set { +// op = value; +// } +// } +// +// public Expression Right { +// get { +// return right; +// } +// set { +// right = value ?? Expression.Null; +// if (!right.IsNull) right.Parent = this; +// } +// } +// +// public AssignmentExpression(Expression left, AssignmentOperatorType op, Expression right) { +// Left = left; +// Op = op; +// Right = right; +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitAssignmentExpression(this, data); +// } +// +// public override string ToString() { +// return string.Format("[AssignmentExpression Left={0} Op={1} Right={2}]", Left, Op, Right); +// } +// } +// +// public abstract class AttributedNode : AbstractNode { +// +// List attributes; +// +// Modifiers modifier; +// +// public List Attributes { +// get { +// return attributes; +// } +// set { +// attributes = value ?? new List(); +// } +// } +// +// public Modifiers Modifier { +// get { +// return modifier; +// } +// set { +// modifier = value; +// } +// } +// +// protected AttributedNode() { +// attributes = new List(); +// } +// +// protected AttributedNode(List attributes) { +// Attributes = attributes; +// } +// +// protected AttributedNode(Modifiers modifier, List attributes) { +// Modifier = modifier; +// Attributes = attributes; +// } +// } +// +// public class AttributeSection : AbstractNode { +// +// string attributeTarget; +// +// List attributes; +// +// public string AttributeTarget { +// get { +// return attributeTarget; +// } +// set { +// attributeTarget = value ?? ""; +// } +// } +// +// public List Attributes { +// get { +// return attributes; +// } +// set { +// attributes = value ?? new List(); +// } +// } +// +// public AttributeSection() { +// attributeTarget = ""; +// attributes = new List(); +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitAttributeSection(this, data); +// } +// +// public override string ToString() { +// return string.Format("[AttributeSection AttributeTarget={0} Attributes={1}]", AttributeTarget, GetCollectionString(Attributes)); +// } +// } +// +// public class BaseReferenceExpression : Expression { +// +// public BaseReferenceExpression() { +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitBaseReferenceExpression(this, data); +// } +// +// public override string ToString() { +// return "[BaseReferenceExpression]"; +// } +// } +// +// public class BinaryOperatorExpression : Expression { +// +// Expression left; +// +// BinaryOperatorType op; +// +// Expression right; +// +// public Expression Left { +// get { +// return left; +// } +// set { +// left = value ?? Expression.Null; +// if (!left.IsNull) left.Parent = this; +// } +// } +// +// public BinaryOperatorType Op { +// get { +// return op; +// } +// set { +// op = value; +// } +// } +// +// public Expression Right { +// get { +// return right; +// } +// set { +// right = value ?? Expression.Null; +// if (!right.IsNull) right.Parent = this; +// } +// } +// +// public BinaryOperatorExpression() { +// left = Expression.Null; +// right = Expression.Null; +// } +// +// public BinaryOperatorExpression(Expression left, BinaryOperatorType op, Expression right) { +// Left = left; +// Op = op; +// Right = right; +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitBinaryOperatorExpression(this, data); +// } +// +// public override string ToString() { +// return string.Format("[BinaryOperatorExpression Left={0} Op={1} Right={2}]", Left, Op, Right); +// } +// } +// +// public class CaseLabel : AbstractNode { +// +// Expression label; +// +// BinaryOperatorType binaryOperatorType; +// +// Expression toExpression; +// +// public Expression Label { +// get { +// return label; +// } +// set { +// label = value ?? Expression.Null; +// if (!label.IsNull) label.Parent = this; +// } +// } +// +// public BinaryOperatorType BinaryOperatorType { +// get { +// return binaryOperatorType; +// } +// set { +// binaryOperatorType = value; +// } +// } +// +// public Expression ToExpression { +// get { +// return toExpression; +// } +// set { +// toExpression = value ?? Expression.Null; +// if (!toExpression.IsNull) toExpression.Parent = this; +// } +// } +// +// public CaseLabel() { +// label = Expression.Null; +// toExpression = Expression.Null; +// } +// +// public CaseLabel(Expression label) { +// Label = label; +// toExpression = Expression.Null; +// } +// +// public CaseLabel(Expression label, Expression toExpression) { +// Label = label; +// ToExpression = toExpression; +// } +// +// public CaseLabel(BinaryOperatorType binaryOperatorType, Expression label) { +// BinaryOperatorType = binaryOperatorType; +// Label = label; +// toExpression = Expression.Null; +// } +// +// public bool IsDefault { +// get { +// return label.IsNull; +// } +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitCaseLabel(this, data); +// } +// +// public override string ToString() { +// return string.Format("[CaseLabel Label={0} BinaryOperatorType={1} ToExpression={2}]", Label, BinaryOperatorType, ToExpression); +// } +// } +// +// public class CastExpression : Expression { +// +// TypeReference castTo; +// +// Expression expression; +// +// CastType castType; +// +// public TypeReference CastTo { +// get { +// return castTo; +// } +// set { +// castTo = value ?? TypeReference.Null; +// if (!castTo.IsNull) castTo.Parent = this; +// } +// } +// +// public Expression Expression { +// get { +// return expression; +// } +// set { +// expression = value ?? Expression.Null; +// if (!expression.IsNull) expression.Parent = this; +// } +// } +// +// public CastType CastType { +// get { +// return castType; +// } +// set { +// castType = value; +// } +// } +// +// public CastExpression(TypeReference castTo) { +// CastTo = castTo; +// expression = Expression.Null; +// } +// +// public CastExpression(TypeReference castTo, Expression expression, CastType castType) { +// CastTo = castTo; +// Expression = expression; +// CastType = castType; +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitCastExpression(this, data); +// } +// +// public override string ToString() { +// return string.Format("[CastExpression CastTo={0} Expression={1} CastType={2}]", CastTo, Expression, CastType); +// } +// } +// +// public class CatchClause : AbstractNode { +// +// TypeReference typeReference; +// +// string variableName; +// +// Statement statementBlock; +// +// Expression condition; +// +// public TypeReference TypeReference { +// get { +// return typeReference; +// } +// set { +// typeReference = value ?? TypeReference.Null; +// if (!typeReference.IsNull) typeReference.Parent = this; +// } +// } +// +// public string VariableName { +// get { +// return variableName; +// } +// set { +// variableName = value ?? ""; +// } +// } +// +// public Statement StatementBlock { +// get { +// return statementBlock; +// } +// set { +// statementBlock = value ?? Statement.Null; +// if (!statementBlock.IsNull) statementBlock.Parent = this; +// } +// } +// +// public Expression Condition { +// get { +// return condition; +// } +// set { +// condition = value ?? Expression.Null; +// if (!condition.IsNull) condition.Parent = this; +// } +// } +// +// public CatchClause(TypeReference typeReference, string variableName, Statement statementBlock) { +// TypeReference = typeReference; +// VariableName = variableName; +// StatementBlock = statementBlock; +// condition = Expression.Null; +// } +// +// public CatchClause(TypeReference typeReference, string variableName, Statement statementBlock, Expression condition) { +// TypeReference = typeReference; +// VariableName = variableName; +// StatementBlock = statementBlock; +// Condition = condition; +// } +// +// public CatchClause(Statement statementBlock) { +// StatementBlock = statementBlock; +// typeReference = TypeReference.Null; +// variableName = ""; +// condition = Expression.Null; +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitCatchClause(this, data); +// } +// +// public override string ToString() { +// return string.Format("[CatchClause TypeReference={0} VariableName={1} StatementBlock={2} Condition={3}]" + +// "", TypeReference, VariableName, StatementBlock, Condition); +// } +// } +// +// public class ClassReferenceExpression : Expression { +// +// public ClassReferenceExpression() { +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitClassReferenceExpression(this, data); +// } +// +// public override string ToString() { +// return "[ClassReferenceExpression]"; +// } +// } +// +// public class CollectionInitializerExpression : Expression { +// +// List createExpressions; +// +// public List CreateExpressions { +// get { +// return createExpressions; +// } +// set { +// createExpressions = value ?? new List(); +// } +// } +// +// public CollectionInitializerExpression() { +// createExpressions = new List(); +// } +// +// public CollectionInitializerExpression(List createExpressions) { +// CreateExpressions = createExpressions; +// } +// +// public new static CollectionInitializerExpression Null { +// get { +// return NullCollectionInitializerExpression.Instance; +// } +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitCollectionInitializerExpression(this, data); +// } +// +// public override string ToString() { +// return string.Format("[CollectionInitializerExpression CreateExpressions={0}]", GetCollectionString(CreateExpressions)); +// } +// } +// +// internal sealed class NullCollectionInitializerExpression : CollectionInitializerExpression { +// +// internal static NullCollectionInitializerExpression Instance = new NullCollectionInitializerExpression(); +// +// public override bool IsNull { +// get { +// return true; +// } +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return null; +// } +// +// public override string ToString() { +// return "[NullCollectionInitializerExpression]"; +// } +// } +// +// public class CollectionRangeVariable : AbstractNode, INullable { +// +// string identifier; +// +// Expression expression; +// +// TypeReference type; +// +// public string Identifier { +// get { +// return identifier; +// } +// set { +// identifier = value ?? ""; +// } +// } +// +// public Expression Expression { +// get { +// return expression; +// } +// set { +// expression = value ?? Expression.Null; +// if (!expression.IsNull) expression.Parent = this; +// } +// } +// +// public TypeReference Type { +// get { +// return type; +// } +// set { +// type = value ?? TypeReference.Null; +// if (!type.IsNull) type.Parent = this; +// } +// } +// +// public CollectionRangeVariable() { +// identifier = ""; +// expression = Expression.Null; +// type = TypeReference.Null; +// } +// +// public virtual bool IsNull { +// get { +// return false; +// } +// } +// +// public static CollectionRangeVariable Null { +// get { +// return NullCollectionRangeVariable.Instance; +// } +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitCollectionRangeVariable(this, data); +// } +// +// public override string ToString() { +// return string.Format("[CollectionRangeVariable Identifier={0} Expression={1} Type={2}]", Identifier, Expression, Type); +// } +// } +// +// internal sealed class NullCollectionRangeVariable : CollectionRangeVariable { +// +// internal static NullCollectionRangeVariable Instance = new NullCollectionRangeVariable(); +// +// public override bool IsNull { +// get { +// return true; +// } +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return null; +// } +// +// public override string ToString() { +// return "[NullCollectionRangeVariable]"; +// } +// } +// +// public class ConditionalExpression : Expression { +// +// Expression condition; +// +// Expression trueExpression; +// +// Expression falseExpression; +// +// public Expression Condition { +// get { +// return condition; +// } +// set { +// condition = value ?? Expression.Null; +// if (!condition.IsNull) condition.Parent = this; +// } +// } +// +// public Expression TrueExpression { +// get { +// return trueExpression; +// } +// set { +// trueExpression = value ?? Expression.Null; +// if (!trueExpression.IsNull) trueExpression.Parent = this; +// } +// } +// +// public Expression FalseExpression { +// get { +// return falseExpression; +// } +// set { +// falseExpression = value ?? Expression.Null; +// if (!falseExpression.IsNull) falseExpression.Parent = this; +// } +// } +// +// public ConditionalExpression() { +// condition = Expression.Null; +// trueExpression = Expression.Null; +// falseExpression = Expression.Null; +// } +// +// public ConditionalExpression(Expression condition, Expression trueExpression, Expression falseExpression) { +// Condition = condition; +// TrueExpression = trueExpression; +// FalseExpression = falseExpression; +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitConditionalExpression(this, data); +// } +// +// public override string ToString() { +// return string.Format("[ConditionalExpression Condition={0} TrueExpression={1} FalseExpression={2}]", Condition, TrueExpression, FalseExpression); +// } +// } +// +// public class ConstructorDeclaration : ParametrizedNode { +// +// ConstructorInitializer constructorInitializer; +// +// BlockStatement body; +// +// public ConstructorInitializer ConstructorInitializer { +// get { +// return constructorInitializer; +// } +// set { +// constructorInitializer = value ?? ConstructorInitializer.Null; +// if (!constructorInitializer.IsNull) constructorInitializer.Parent = this; +// } +// } +// +// public BlockStatement Body { +// get { +// return body; +// } +// set { +// body = value ?? BlockStatement.Null; +// if (!body.IsNull) body.Parent = this; +// } +// } +// +// public ConstructorDeclaration(string name, Modifiers modifier, List parameters, List attributes) { +// Name = name; +// Modifier = modifier; +// Parameters = parameters; +// Attributes = attributes; +// constructorInitializer = ConstructorInitializer.Null; +// body = BlockStatement.Null; +// } +// +// public ConstructorDeclaration(string name, Modifiers modifier, List parameters, ConstructorInitializer constructorInitializer, List attributes) { +// Name = name; +// Modifier = modifier; +// Parameters = parameters; +// ConstructorInitializer = constructorInitializer; +// Attributes = attributes; +// body = BlockStatement.Null; +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitConstructorDeclaration(this, data); +// } +// +// public override string ToString() { +// return string.Format("[ConstructorDeclaration ConstructorInitializer={0} Body={1} Name={2} Parameters={" + +// "3} Attributes={4} Modifier={5}]", ConstructorInitializer, Body, Name, GetCollectionString(Parameters), GetCollectionString(Attributes), Modifier); +// } +// } +// +// public class ConstructorInitializer : AbstractNode, INullable { +// +// ConstructorInitializerType constructorInitializerType; +// +// List arguments; +// +// public ConstructorInitializerType ConstructorInitializerType { +// get { +// return constructorInitializerType; +// } +// set { +// constructorInitializerType = value; +// } +// } +// +// public List Arguments { +// get { +// return arguments; +// } +// set { +// arguments = value ?? new List(); +// } +// } +// +// public ConstructorInitializer() { +// arguments = new List(); +// } +// +// public virtual bool IsNull { +// get { +// return false; +// } +// } +// +// public static ConstructorInitializer Null { +// get { +// return NullConstructorInitializer.Instance; +// } +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitConstructorInitializer(this, data); +// } +// +// public override string ToString() { +// return string.Format("[ConstructorInitializer ConstructorInitializerType={0} Arguments={1}]", ConstructorInitializerType, GetCollectionString(Arguments)); +// } +// } +// +// internal sealed class NullConstructorInitializer : ConstructorInitializer { +// +// internal static NullConstructorInitializer Instance = new NullConstructorInitializer(); +// +// public override bool IsNull { +// get { +// return true; +// } +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return null; +// } +// +// public override string ToString() { +// return "[NullConstructorInitializer]"; +// } +// } +// +// public class ContinueStatement : Statement { +// +// ContinueType continueType; +// +// public ContinueType ContinueType { +// get { +// return continueType; +// } +// set { +// continueType = value; +// } +// } +// +// public ContinueStatement() { +// } +// +// public ContinueStatement(ContinueType continueType) { +// ContinueType = continueType; +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitContinueStatement(this, data); +// } +// +// public override string ToString() { +// return string.Format("[ContinueStatement ContinueType={0}]", ContinueType); +// } +// } +// +// public class DeclareDeclaration : ParametrizedNode { +// +// string alias; +// +// string library; +// +// CharsetModifier charset; +// +// TypeReference typeReference; +// +// public string Alias { +// get { +// return alias; +// } +// set { +// alias = value ?? ""; +// } +// } +// +// public string Library { +// get { +// return library; +// } +// set { +// library = value ?? ""; +// } +// } +// +// public CharsetModifier Charset { +// get { +// return charset; +// } +// set { +// charset = value; +// } +// } +// +// public TypeReference TypeReference { +// get { +// return typeReference; +// } +// set { +// typeReference = value ?? TypeReference.Null; +// if (!typeReference.IsNull) typeReference.Parent = this; +// } +// } +// +// public DeclareDeclaration(string name, Modifiers modifier, TypeReference typeReference, List parameters, List attributes, string library, string alias, CharsetModifier charset) { +// Name = name; +// Modifier = modifier; +// TypeReference = typeReference; +// Parameters = parameters; +// Attributes = attributes; +// Library = library; +// Alias = alias; +// Charset = charset; +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitDeclareDeclaration(this, data); +// } +// +// public override string ToString() { +// return string.Format("[DeclareDeclaration Alias={0} Library={1} Charset={2} TypeReference={3} Name={4} " + +// "Parameters={5} Attributes={6} Modifier={7}]", Alias, Library, Charset, TypeReference, Name, GetCollectionString(Parameters), GetCollectionString(Attributes), Modifier); +// } +// } +// +// public class DefaultValueExpression : Expression { +// +// TypeReference typeReference; +// +// public TypeReference TypeReference { +// get { +// return typeReference; +// } +// set { +// typeReference = value ?? TypeReference.Null; +// if (!typeReference.IsNull) typeReference.Parent = this; +// } +// } +// +// public DefaultValueExpression(TypeReference typeReference) { +// TypeReference = typeReference; +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitDefaultValueExpression(this, data); +// } +// +// public override string ToString() { +// return string.Format("[DefaultValueExpression TypeReference={0}]", TypeReference); +// } +// } +// +// public class DelegateDeclaration : AttributedNode { +// +// string name; +// +// TypeReference returnType; +// +// List parameters; +// +// List templates; +// +// public string Name { +// get { +// return name; +// } +// set { +// name = string.IsNullOrEmpty(value) ? "?" : value; +// } +// } +// +// public TypeReference ReturnType { +// get { +// return returnType; +// } +// set { +// returnType = value ?? TypeReference.Null; +// if (!returnType.IsNull) returnType.Parent = this; +// } +// } +// +// public List Parameters { +// get { +// return parameters; +// } +// set { +// parameters = value ?? new List(); +// } +// } +// +// public List Templates { +// get { +// return templates; +// } +// set { +// templates = value ?? new List(); +// } +// } +// +// public DelegateDeclaration(Modifiers modifier, List attributes) { +// Modifier = modifier; +// Attributes = attributes; +// name = "?"; +// returnType = TypeReference.Null; +// parameters = new List(); +// templates = new List(); +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitDelegateDeclaration(this, data); +// } +// +// public override string ToString() { +// return string.Format("[DelegateDeclaration Name={0} ReturnType={1} Parameters={2} Templates={3} Attribu" + +// "tes={4} Modifier={5}]", Name, ReturnType, GetCollectionString(Parameters), GetCollectionString(Templates), GetCollectionString(Attributes), Modifier); +// } +// } +// +// public class DirectionExpression : Expression { +// +// FieldDirection fieldDirection; +// +// Expression expression; +// +// public FieldDirection FieldDirection { +// get { +// return fieldDirection; +// } +// set { +// fieldDirection = value; +// } +// } +// +// public Expression Expression { +// get { +// return expression; +// } +// set { +// expression = value ?? Expression.Null; +// if (!expression.IsNull) expression.Parent = this; +// } +// } +// +// public DirectionExpression(FieldDirection fieldDirection, Expression expression) { +// FieldDirection = fieldDirection; +// Expression = expression; +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitDirectionExpression(this, data); +// } +// +// public override string ToString() { +// return string.Format("[DirectionExpression FieldDirection={0} Expression={1}]", FieldDirection, Expression); +// } +// } +// +// public class DoLoopStatement : StatementWithEmbeddedStatement { +// +// Expression condition; +// +// ConditionType conditionType; +// +// ConditionPosition conditionPosition; +// +// public Expression Condition { +// get { +// return condition; +// } +// set { +// condition = value ?? Expression.Null; +// if (!condition.IsNull) condition.Parent = this; +// } +// } +// +// public ConditionType ConditionType { +// get { +// return conditionType; +// } +// set { +// conditionType = value; +// } +// } +// +// public ConditionPosition ConditionPosition { +// get { +// return conditionPosition; +// } +// set { +// conditionPosition = value; +// } +// } +// +// public DoLoopStatement(Expression condition, Statement embeddedStatement, ConditionType conditionType, ConditionPosition conditionPosition) { +// Condition = condition; +// EmbeddedStatement = embeddedStatement; +// ConditionType = conditionType; +// ConditionPosition = conditionPosition; +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitDoLoopStatement(this, data); +// } +// +// public override string ToString() { +// return string.Format("[DoLoopStatement Condition={0} ConditionType={1} ConditionPosition={2} EmbeddedSt" + +// "atement={3}]", Condition, ConditionType, ConditionPosition, EmbeddedStatement); +// } +// } +// +// public class ElseIfSection : StatementWithEmbeddedStatement { +// +// Expression condition; +// +// public Expression Condition { +// get { +// return condition; +// } +// set { +// condition = value ?? Expression.Null; +// if (!condition.IsNull) condition.Parent = this; +// } +// } +// +// public ElseIfSection(Expression condition, Statement embeddedStatement) { +// Condition = condition; +// EmbeddedStatement = embeddedStatement; +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitElseIfSection(this, data); +// } +// +// public override string ToString() { +// return string.Format("[ElseIfSection Condition={0} EmbeddedStatement={1}]", Condition, EmbeddedStatement); +// } +// } +// +// public class EndStatement : Statement { +// +// public EndStatement() { +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitEndStatement(this, data); +// } +// +// public override string ToString() { +// return "[EndStatement]"; +// } +// } +// +// public class EraseStatement : Statement { +// +// List expressions; +// +// public List Expressions { +// get { +// return expressions; +// } +// set { +// expressions = value ?? new List(); +// } +// } +// +// public EraseStatement() { +// expressions = new List(); +// } +// +// public EraseStatement(List expressions) { +// Expressions = expressions; +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitEraseStatement(this, data); +// } +// +// public override string ToString() { +// return string.Format("[EraseStatement Expressions={0}]", GetCollectionString(Expressions)); +// } +// } +// +// public class ErrorStatement : Statement { +// +// Expression expression; +// +// public Expression Expression { +// get { +// return expression; +// } +// set { +// expression = value ?? Expression.Null; +// if (!expression.IsNull) expression.Parent = this; +// } +// } +// +// public ErrorStatement(Expression expression) { +// Expression = expression; +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitErrorStatement(this, data); +// } +// +// public override string ToString() { +// return string.Format("[ErrorStatement Expression={0}]", Expression); +// } +// } +// +// public class EventAddRegion : EventAddRemoveRegion { +// +// public EventAddRegion(List attributes) : +// base(attributes) { +// } +// +// public static EventAddRegion Null { +// get { +// return NullEventAddRegion.Instance; +// } +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitEventAddRegion(this, data); +// } +// +// public override string ToString() { +// return string.Format("[EventAddRegion Block={0} Parameters={1} Attributes={2} Modifier={3}]", Block, GetCollectionString(Parameters), GetCollectionString(Attributes), Modifier); +// } +// } +// +// internal sealed class NullEventAddRegion : EventAddRegion { +// +// private NullEventAddRegion() : +// base(null) { +// } +// +// internal static NullEventAddRegion Instance = new NullEventAddRegion(); +// +// public override bool IsNull { +// get { +// return true; +// } +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return null; +// } +// +// public override string ToString() { +// return "[NullEventAddRegion]"; +// } +// } +// +// public abstract class EventAddRemoveRegion : AttributedNode, INullable { +// +// BlockStatement block; +// +// List parameters; +// +// public BlockStatement Block { +// get { +// return block; +// } +// set { +// block = value ?? BlockStatement.Null; +// if (!block.IsNull) block.Parent = this; +// } +// } +// +// public List Parameters { +// get { +// return parameters; +// } +// set { +// parameters = value ?? new List(); +// } +// } +// +// protected EventAddRemoveRegion(List attributes) { +// Attributes = attributes; +// block = BlockStatement.Null; +// parameters = new List(); +// } +// +// public virtual bool IsNull { +// get { +// return false; +// } +// } +// } +// +// public class EventDeclaration : MemberNode { +// +// EventAddRegion addRegion; +// +// EventRemoveRegion removeRegion; +// +// EventRaiseRegion raiseRegion; +// +// Location bodyStart; +// +// Location bodyEnd; +// +// Expression initializer; +// +// public EventAddRegion AddRegion { +// get { +// return addRegion; +// } +// set { +// addRegion = value ?? EventAddRegion.Null; +// if (!addRegion.IsNull) addRegion.Parent = this; +// } +// } +// +// public EventRemoveRegion RemoveRegion { +// get { +// return removeRegion; +// } +// set { +// removeRegion = value ?? EventRemoveRegion.Null; +// if (!removeRegion.IsNull) removeRegion.Parent = this; +// } +// } +// +// public EventRaiseRegion RaiseRegion { +// get { +// return raiseRegion; +// } +// set { +// raiseRegion = value ?? EventRaiseRegion.Null; +// if (!raiseRegion.IsNull) raiseRegion.Parent = this; +// } +// } +// +// public Location BodyStart { +// get { +// return bodyStart; +// } +// set { +// bodyStart = value; +// } +// } +// +// public Location BodyEnd { +// get { +// return bodyEnd; +// } +// set { +// bodyEnd = value; +// } +// } +// +// public Expression Initializer { +// get { +// return initializer; +// } +// set { +// initializer = value ?? Expression.Null; +// if (!initializer.IsNull) initializer.Parent = this; +// } +// } +// +// public EventDeclaration() { +// addRegion = EventAddRegion.Null; +// removeRegion = EventRemoveRegion.Null; +// raiseRegion = EventRaiseRegion.Null; +// bodyStart = Location.Empty; +// bodyEnd = Location.Empty; +// initializer = Expression.Null; +// } +// +// public bool HasAddRegion { +// get { +// return !addRegion.IsNull; +// } +// } +// +// public bool HasRemoveRegion { +// get { +// return !removeRegion.IsNull; +// } +// } +// +// public bool HasRaiseRegion { +// get { +// return !raiseRegion.IsNull; +// } +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitEventDeclaration(this, data); +// } +// +// public override string ToString() { +// return string.Format("[EventDeclaration AddRegion={0} RemoveRegion={1} RaiseRegion={2} BodyStart={3} Bo" + +// "dyEnd={4} Initializer={5} InterfaceImplementations={6} TypeReference={7} Name={8" + +// "} Parameters={9} Attributes={10} Modifier={11}]", AddRegion, RemoveRegion, RaiseRegion, BodyStart, BodyEnd, Initializer, GetCollectionString(InterfaceImplementations), TypeReference, Name, GetCollectionString(Parameters), GetCollectionString(Attributes), Modifier); +// } +// } +// +// public class EventRaiseRegion : EventAddRemoveRegion { +// +// public EventRaiseRegion(List attributes) : +// base(attributes) { +// } +// +// public static EventRaiseRegion Null { +// get { +// return NullEventRaiseRegion.Instance; +// } +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitEventRaiseRegion(this, data); +// } +// +// public override string ToString() { +// return string.Format("[EventRaiseRegion Block={0} Parameters={1} Attributes={2} Modifier={3}]", Block, GetCollectionString(Parameters), GetCollectionString(Attributes), Modifier); +// } +// } +// +// internal sealed class NullEventRaiseRegion : EventRaiseRegion { +// +// private NullEventRaiseRegion() : +// base(null) { +// } +// +// internal static NullEventRaiseRegion Instance = new NullEventRaiseRegion(); +// +// public override bool IsNull { +// get { +// return true; +// } +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return null; +// } +// +// public override string ToString() { +// return "[NullEventRaiseRegion]"; +// } +// } +// +// public class EventRemoveRegion : EventAddRemoveRegion { +// +// public EventRemoveRegion(List attributes) : +// base(attributes) { +// } +// +// public static EventRemoveRegion Null { +// get { +// return NullEventRemoveRegion.Instance; +// } +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitEventRemoveRegion(this, data); +// } +// +// public override string ToString() { +// return string.Format("[EventRemoveRegion Block={0} Parameters={1} Attributes={2} Modifier={3}]", Block, GetCollectionString(Parameters), GetCollectionString(Attributes), Modifier); +// } +// } +// +// internal sealed class NullEventRemoveRegion : EventRemoveRegion { +// +// private NullEventRemoveRegion() : +// base(null) { +// } +// +// internal static NullEventRemoveRegion Instance = new NullEventRemoveRegion(); +// +// public override bool IsNull { +// get { +// return true; +// } +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return null; +// } +// +// public override string ToString() { +// return "[NullEventRemoveRegion]"; +// } +// } +// +// public class ExitStatement : Statement { +// +// ExitType exitType; +// +// public ExitType ExitType { +// get { +// return exitType; +// } +// set { +// exitType = value; +// } +// } +// +// public ExitStatement(ExitType exitType) { +// ExitType = exitType; +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitExitStatement(this, data); +// } +// +// public override string ToString() { +// return string.Format("[ExitStatement ExitType={0}]", ExitType); +// } +// } +// +// public class ExpressionRangeVariable : AbstractNode, INullable { +// +// string identifier; +// +// Expression expression; +// +// TypeReference type; +// +// public string Identifier { +// get { +// return identifier; +// } +// set { +// identifier = value ?? ""; +// } +// } +// +// public Expression Expression { +// get { +// return expression; +// } +// set { +// expression = value ?? Expression.Null; +// if (!expression.IsNull) expression.Parent = this; +// } +// } +// +// public TypeReference Type { +// get { +// return type; +// } +// set { +// type = value ?? TypeReference.Null; +// if (!type.IsNull) type.Parent = this; +// } +// } +// +// public ExpressionRangeVariable() { +// identifier = ""; +// expression = Expression.Null; +// type = TypeReference.Null; +// } +// +// public virtual bool IsNull { +// get { +// return false; +// } +// } +// +// public static ExpressionRangeVariable Null { +// get { +// return NullExpressionRangeVariable.Instance; +// } +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitExpressionRangeVariable(this, data); +// } +// +// public override string ToString() { +// return string.Format("[ExpressionRangeVariable Identifier={0} Expression={1} Type={2}]", Identifier, Expression, Type); +// } +// } +// +// internal sealed class NullExpressionRangeVariable : ExpressionRangeVariable { +// +// internal static NullExpressionRangeVariable Instance = new NullExpressionRangeVariable(); +// +// public override bool IsNull { +// get { +// return true; +// } +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return null; +// } +// +// public override string ToString() { +// return "[NullExpressionRangeVariable]"; +// } +// } +// +// public class ExpressionStatement : Statement { +// +// Expression expression; +// +// public Expression Expression { +// get { +// return expression; +// } +// set { +// expression = value ?? Expression.Null; +// if (!expression.IsNull) expression.Parent = this; +// } +// } +// +// public ExpressionStatement(Expression expression) { +// Expression = expression; +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitExpressionStatement(this, data); +// } +// +// public override string ToString() { +// return string.Format("[ExpressionStatement Expression={0}]", Expression); +// } +// } +// +// public class ExternAliasDirective : AbstractNode { +// +// string name; +// +// public string Name { +// get { +// return name; +// } +// set { +// name = value ?? ""; +// } +// } +// +// public ExternAliasDirective() { +// name = ""; +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitExternAliasDirective(this, data); +// } +// +// public override string ToString() { +// return string.Format("[ExternAliasDirective Name={0}]", Name); +// } +// } +// +// public class FieldDeclaration : AttributedNode { +// +// TypeReference typeReference; +// +// List fields; +// +// public TypeReference TypeReference { +// get { +// return typeReference; +// } +// set { +// typeReference = value ?? TypeReference.Null; +// if (!typeReference.IsNull) typeReference.Parent = this; +// } +// } +// +// public List Fields { +// get { +// return fields; +// } +// set { +// fields = value ?? new List(); +// } +// } +// +// public FieldDeclaration(List attributes) { +// Attributes = attributes; +// typeReference = TypeReference.Null; +// fields = new List(); +// } +// +// public FieldDeclaration(List attributes, TypeReference typeReference, Modifiers modifier) { +// Attributes = attributes; +// TypeReference = typeReference; +// Modifier = modifier; +// fields = new List(); +// } +// +// +// public TypeReference GetTypeForField(int fieldIndex) +// { +// if (!typeReference.IsNull) { +// return typeReference; +// } +// return ((VariableDeclaration)Fields[fieldIndex]).TypeReference; +// } +// +// +// public VariableDeclaration GetVariableDeclaration(string variableName) +// { +// foreach (VariableDeclaration variableDeclaration in Fields) { +// if (variableDeclaration.Name == variableName) { +// return variableDeclaration; +// } +// } +// return null; +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitFieldDeclaration(this, data); +// } +// +// public override string ToString() { +// return string.Format("[FieldDeclaration TypeReference={0} Fields={1} Attributes={2} Modifier={3}]", TypeReference, GetCollectionString(Fields), GetCollectionString(Attributes), Modifier); +// } +// } +// +// public class ForeachStatement : StatementWithEmbeddedStatement { +// +// TypeReference typeReference; +// +// string variableName; +// +// Expression expression; +// +// Expression nextExpression; +// +// public TypeReference TypeReference { +// get { +// return typeReference; +// } +// set { +// typeReference = value ?? TypeReference.Null; +// if (!typeReference.IsNull) typeReference.Parent = this; +// } +// } +// +// public string VariableName { +// get { +// return variableName; +// } +// set { +// variableName = value ?? ""; +// } +// } +// +// public Expression Expression { +// get { +// return expression; +// } +// set { +// expression = value ?? Expression.Null; +// if (!expression.IsNull) expression.Parent = this; +// } +// } +// +// public Expression NextExpression { +// get { +// return nextExpression; +// } +// set { +// nextExpression = value ?? Expression.Null; +// if (!nextExpression.IsNull) nextExpression.Parent = this; +// } +// } +// +// public ForeachStatement(TypeReference typeReference, string variableName, Expression expression, Statement embeddedStatement) { +// TypeReference = typeReference; +// VariableName = variableName; +// Expression = expression; +// EmbeddedStatement = embeddedStatement; +// nextExpression = Expression.Null; +// } +// +// public ForeachStatement(TypeReference typeReference, string variableName, Expression expression, Statement embeddedStatement, Expression nextExpression) { +// TypeReference = typeReference; +// VariableName = variableName; +// Expression = expression; +// EmbeddedStatement = embeddedStatement; +// NextExpression = nextExpression; +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitForeachStatement(this, data); +// } +// +// public override string ToString() { +// return string.Format("[ForeachStatement TypeReference={0} VariableName={1} Expression={2} NextExpressio" + +// "n={3} EmbeddedStatement={4}]", TypeReference, VariableName, Expression, NextExpression, EmbeddedStatement); +// } +// } +// +// public class ForNextStatement : StatementWithEmbeddedStatement { +// +// Expression start; +// +// Expression end; +// +// Expression step; +// +// List nextExpressions; +// +// TypeReference typeReference; +// +// string variableName; +// +// Expression loopVariableExpression; +// +// public Expression Start { +// get { +// return start; +// } +// set { +// start = value ?? Expression.Null; +// if (!start.IsNull) start.Parent = this; +// } +// } +// +// public Expression End { +// get { +// return end; +// } +// set { +// end = value ?? Expression.Null; +// if (!end.IsNull) end.Parent = this; +// } +// } +// +// public Expression Step { +// get { +// return step; +// } +// set { +// step = value ?? Expression.Null; +// if (!step.IsNull) step.Parent = this; +// } +// } +// +// public List NextExpressions { +// get { +// return nextExpressions; +// } +// set { +// nextExpressions = value ?? new List(); +// } +// } +// +// public TypeReference TypeReference { +// get { +// return typeReference; +// } +// set { +// typeReference = value ?? TypeReference.Null; +// if (!typeReference.IsNull) typeReference.Parent = this; +// } +// } +// +// public string VariableName { +// get { +// return variableName; +// } +// set { +// variableName = value ?? ""; +// } +// } +// +// public Expression LoopVariableExpression { +// get { +// return loopVariableExpression; +// } +// set { +// loopVariableExpression = value ?? Expression.Null; +// if (!loopVariableExpression.IsNull) loopVariableExpression.Parent = this; +// } +// } +// +// public ForNextStatement() { +// start = Expression.Null; +// end = Expression.Null; +// step = Expression.Null; +// nextExpressions = new List(); +// typeReference = TypeReference.Null; +// variableName = ""; +// loopVariableExpression = Expression.Null; +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitForNextStatement(this, data); +// } +// +// public override string ToString() { +// return string.Format("[ForNextStatement Start={0} End={1} Step={2} NextExpressions={3} TypeReference={4" + +// "} VariableName={5} LoopVariableExpression={6} EmbeddedStatement={7}]", Start, End, Step, GetCollectionString(NextExpressions), TypeReference, VariableName, LoopVariableExpression, EmbeddedStatement); +// } +// } +// +// public class GotoStatement : Statement { +// +// string label; +// +// public string Label { +// get { +// return label; +// } +// set { +// label = value ?? ""; +// } +// } +// +// public GotoStatement(string label) { +// Label = label; +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitGotoStatement(this, data); +// } +// +// public override string ToString() { +// return string.Format("[GotoStatement Label={0}]", Label); +// } +// } +// +// public class IfElseStatement : Statement { +// +// Expression condition; +// +// List trueStatement; +// +// List falseStatement; +// +// List elseIfSections; +// +// public Expression Condition { +// get { +// return condition; +// } +// set { +// condition = value ?? Expression.Null; +// if (!condition.IsNull) condition.Parent = this; +// } +// } +// +// public List TrueStatement { +// get { +// return trueStatement; +// } +// set { +// trueStatement = value ?? new List(); +// } +// } +// +// public List FalseStatement { +// get { +// return falseStatement; +// } +// set { +// falseStatement = value ?? new List(); +// } +// } +// +// public List ElseIfSections { +// get { +// return elseIfSections; +// } +// set { +// elseIfSections = value ?? new List(); +// } +// } +// +// public IfElseStatement(Expression condition) { +// Condition = condition; +// trueStatement = new List(); +// falseStatement = new List(); +// elseIfSections = new List(); +// } +// +// +// public IfElseStatement(Expression condition, Statement trueStatement) +// : this(condition) { +// this.trueStatement.Add(Statement.CheckNull(trueStatement)); +// if (trueStatement != null) trueStatement.Parent = this; +// } +// +// public bool HasElseStatements { +// get { +// return falseStatement.Count > 0; +// } +// } +// +// public bool HasElseIfSections { +// get { +// return elseIfSections.Count > 0; +// } +// } +// +// +// public IfElseStatement(Expression condition, Statement trueStatement, Statement falseStatement) +// : this(condition) { +// this.trueStatement.Add(Statement.CheckNull(trueStatement)); +// this.falseStatement.Add(Statement.CheckNull(falseStatement)); +// if (trueStatement != null) trueStatement.Parent = this; +// if (falseStatement != null) falseStatement.Parent = this; +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitIfElseStatement(this, data); +// } +// +// public override string ToString() { +// return string.Format("[IfElseStatement Condition={0} TrueStatement={1} FalseStatement={2} ElseIfSection" + +// "s={3}]", Condition, GetCollectionString(TrueStatement), GetCollectionString(FalseStatement), GetCollectionString(ElseIfSections)); +// } +// } +// +// public class InterfaceImplementation : AbstractNode { +// +// TypeReference interfaceType; +// +// string memberName; +// +// public TypeReference InterfaceType { +// get { +// return interfaceType; +// } +// set { +// interfaceType = value ?? TypeReference.Null; +// if (!interfaceType.IsNull) interfaceType.Parent = this; +// } +// } +// +// public string MemberName { +// get { +// return memberName; +// } +// set { +// memberName = string.IsNullOrEmpty(value) ? "?" : value; +// } +// } +// +// public InterfaceImplementation(TypeReference interfaceType, string memberName) { +// InterfaceType = interfaceType; +// MemberName = memberName; +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitInterfaceImplementation(this, data); +// } +// +// public override string ToString() { +// return string.Format("[InterfaceImplementation InterfaceType={0} MemberName={1}]", InterfaceType, MemberName); +// } +// } +// +// public class InvocationExpression : Expression { +// +// Expression targetObject; +// +// List arguments; +// +// public Expression TargetObject { +// get { +// return targetObject; +// } +// set { +// targetObject = value ?? Expression.Null; +// if (!targetObject.IsNull) targetObject.Parent = this; +// } +// } +// +// public List Arguments { +// get { +// return arguments; +// } +// set { +// arguments = value ?? new List(); +// } +// } +// +// public InvocationExpression(Expression targetObject) { +// TargetObject = targetObject; +// arguments = new List(); +// } +// +// public InvocationExpression(Expression targetObject, List arguments) { +// TargetObject = targetObject; +// Arguments = arguments; +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitInvocationExpression(this, data); +// } +// +// public override string ToString() { +// return string.Format("[InvocationExpression TargetObject={0} Arguments={1}]", TargetObject, GetCollectionString(Arguments)); +// } +// } +// +// public class LabelStatement : Statement { +// +// string label; +// +// public string Label { +// get { +// return label; +// } +// set { +// label = value ?? ""; +// } +// } +// +// public LabelStatement(string label) { +// Label = label; +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitLabelStatement(this, data); +// } +// +// public override string ToString() { +// return string.Format("[LabelStatement Label={0}]", Label); +// } +// } +// +// public class LambdaExpression : Expression { +// +// List parameters; +// +// Statement statementBody; +// +// Expression expressionBody; +// +// TypeReference returnType; +// +// public List Parameters { +// get { +// return parameters; +// } +// set { +// parameters = value ?? new List(); +// } +// } +// +// public Statement StatementBody { +// get { +// return statementBody; +// } +// set { +// statementBody = value ?? Statement.Null; +// if (!statementBody.IsNull) statementBody.Parent = this; +// } +// } +// +// public Expression ExpressionBody { +// get { +// return expressionBody; +// } +// set { +// expressionBody = value ?? Expression.Null; +// if (!expressionBody.IsNull) expressionBody.Parent = this; +// } +// } +// +// public TypeReference ReturnType { +// get { +// return returnType; +// } +// set { +// returnType = value ?? TypeReference.Null; +// if (!returnType.IsNull) returnType.Parent = this; +// } +// } +// +// public LambdaExpression() { +// parameters = new List(); +// statementBody = Statement.Null; +// expressionBody = Expression.Null; +// returnType = TypeReference.Null; +// } +// +// public Location ExtendedEndLocation { get; set; } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitLambdaExpression(this, data); +// } +// +// public override string ToString() { +// return string.Format("[LambdaExpression Parameters={0} StatementBody={1} ExpressionBody={2} ReturnType=" + +// "{3}]", GetCollectionString(Parameters), StatementBody, ExpressionBody, ReturnType); +// } +// } +// +// public class LockStatement : StatementWithEmbeddedStatement { +// +// Expression lockExpression; +// +// public Expression LockExpression { +// get { +// return lockExpression; +// } +// set { +// lockExpression = value ?? Expression.Null; +// if (!lockExpression.IsNull) lockExpression.Parent = this; +// } +// } +// +// public LockStatement(Expression lockExpression, Statement embeddedStatement) { +// LockExpression = lockExpression; +// EmbeddedStatement = embeddedStatement; +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitLockStatement(this, data); +// } +// +// public override string ToString() { +// return string.Format("[LockStatement LockExpression={0} EmbeddedStatement={1}]", LockExpression, EmbeddedStatement); +// } +// } +// +// public class MemberInitializerExpression : Expression { +// +// string name; +// +// bool isKey; +// +// Expression expression; +// +// public string Name { +// get { +// return name; +// } +// set { +// name = value ?? ""; +// } +// } +// +// public bool IsKey { +// get { +// return isKey; +// } +// set { +// isKey = value; +// } +// } +// +// public Expression Expression { +// get { +// return expression; +// } +// set { +// expression = value ?? Expression.Null; +// if (!expression.IsNull) expression.Parent = this; +// } +// } +// +// public MemberInitializerExpression() { +// name = ""; +// expression = Expression.Null; +// } +// +// public MemberInitializerExpression(string name, Expression expression) { +// Name = name; +// Expression = expression; +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitMemberInitializerExpression(this, data); +// } +// +// public override string ToString() { +// return string.Format("[MemberInitializerExpression Name={0} IsKey={1} Expression={2}]", Name, IsKey, Expression); +// } +// } +// +// public abstract class MemberNode : ParametrizedNode { +// +// List interfaceImplementations; +// +// TypeReference typeReference; +// +// public List InterfaceImplementations { +// get { +// return interfaceImplementations; +// } +// set { +// interfaceImplementations = value ?? new List(); +// } +// } +// +// public TypeReference TypeReference { +// get { +// return typeReference; +// } +// set { +// typeReference = value ?? TypeReference.Null; +// if (!typeReference.IsNull) typeReference.Parent = this; +// } +// } +// +// protected MemberNode() { +// interfaceImplementations = new List(); +// typeReference = TypeReference.Null; +// } +// +// protected MemberNode(Modifiers modifier, List attributes, string name, List parameters) { +// Modifier = modifier; +// Attributes = attributes; +// Name = name; +// Parameters = parameters; +// interfaceImplementations = new List(); +// typeReference = TypeReference.Null; +// } +// } +// +// public class MemberReferenceExpression : Expression { +// +// Expression targetObject; +// +// string memberName; +// +// List typeArguments; +// +// public Expression TargetObject { +// get { +// return targetObject; +// } +// set { +// targetObject = value ?? Expression.Null; +// if (!targetObject.IsNull) targetObject.Parent = this; +// } +// } +// +// public string MemberName { +// get { +// return memberName; +// } +// set { +// memberName = value ?? ""; +// } +// } +// +// public List TypeArguments { +// get { +// return typeArguments; +// } +// set { +// typeArguments = value ?? new List(); +// } +// } +// +// public MemberReferenceExpression(Expression targetObject, string memberName) { +// TargetObject = targetObject; +// MemberName = memberName; +// typeArguments = new List(); +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitMemberReferenceExpression(this, data); +// } +// +// public override string ToString() { +// return string.Format("[MemberReferenceExpression TargetObject={0} MemberName={1} TypeArguments={2}]", TargetObject, MemberName, GetCollectionString(TypeArguments)); +// } +// } +// +// public class MethodDeclaration : MemberNode { +// +// BlockStatement body; +// +// List handlesClause; +// +// List templates; +// +// bool isExtensionMethod; +// +// public BlockStatement Body { +// get { +// return body; +// } +// set { +// body = value ?? BlockStatement.Null; +// if (!body.IsNull) body.Parent = this; +// } +// } +// +// public List HandlesClause { +// get { +// return handlesClause; +// } +// set { +// handlesClause = value ?? new List(); +// } +// } +// +// public List Templates { +// get { +// return templates; +// } +// set { +// templates = value ?? new List(); +// } +// } +// +// public bool IsExtensionMethod { +// get { +// return isExtensionMethod; +// } +// set { +// isExtensionMethod = value; +// } +// } +// +// public MethodDeclaration() { +// body = BlockStatement.Null; +// handlesClause = new List(); +// templates = new List(); +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitMethodDeclaration(this, data); +// } +// +// public override string ToString() { +// return string.Format("[MethodDeclaration Body={0} HandlesClause={1} Templates={2} IsExtensionMethod={3}" + +// " InterfaceImplementations={4} TypeReference={5} Name={6} Parameters={7} Attribut" + +// "es={8} Modifier={9}]", Body, GetCollectionString(HandlesClause), GetCollectionString(Templates), IsExtensionMethod, GetCollectionString(InterfaceImplementations), TypeReference, Name, GetCollectionString(Parameters), GetCollectionString(Attributes), Modifier); +// } +// } +// +// public class NamedArgumentExpression : Expression { +// +// string name; +// +// Expression expression; +// +// public string Name { +// get { +// return name; +// } +// set { +// name = value ?? ""; +// } +// } +// +// public Expression Expression { +// get { +// return expression; +// } +// set { +// expression = value ?? Expression.Null; +// if (!expression.IsNull) expression.Parent = this; +// } +// } +// +// public NamedArgumentExpression() { +// name = ""; +// expression = Expression.Null; +// } +// +// public NamedArgumentExpression(string name, Expression expression) { +// Name = name; +// Expression = expression; +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitNamedArgumentExpression(this, data); +// } +// +// public override string ToString() { +// return string.Format("[NamedArgumentExpression Name={0} Expression={1}]", Name, Expression); +// } +// } +// +// public class NamespaceDeclaration : AbstractNode { +// +// string name; +// +// public string Name { +// get { +// return name; +// } +// set { +// name = value ?? ""; +// } +// } +// +// public NamespaceDeclaration(string name) { +// Name = name; +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitNamespaceDeclaration(this, data); +// } +// +// public override string ToString() { +// return string.Format("[NamespaceDeclaration Name={0}]", Name); +// } +// } +// +// public class ObjectCreateExpression : Expression { +// +// TypeReference createType; +// +// List parameters; +// +// CollectionInitializerExpression objectInitializer; +// +// public TypeReference CreateType { +// get { +// return createType; +// } +// set { +// createType = value ?? TypeReference.Null; +// if (!createType.IsNull) createType.Parent = this; +// } +// } +// +// public List Parameters { +// get { +// return parameters; +// } +// set { +// parameters = value ?? new List(); +// } +// } +// +// public CollectionInitializerExpression ObjectInitializer { +// get { +// return objectInitializer; +// } +// set { +// objectInitializer = value ?? CollectionInitializerExpression.Null; +// if (!objectInitializer.IsNull) objectInitializer.Parent = this; +// } +// } +// +// public ObjectCreateExpression(TypeReference createType, List parameters) { +// CreateType = createType; +// Parameters = parameters; +// objectInitializer = CollectionInitializerExpression.Null; +// } +// +// public bool IsAnonymousType { +// get { +// return createType.IsNull || string.IsNullOrEmpty(createType.Type); +// } +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitObjectCreateExpression(this, data); +// } +// +// public override string ToString() { +// return string.Format("[ObjectCreateExpression CreateType={0} Parameters={1} ObjectInitializer={2}]", CreateType, GetCollectionString(Parameters), ObjectInitializer); +// } +// } +// +// public class OnErrorStatement : StatementWithEmbeddedStatement { +// +// public OnErrorStatement(Statement embeddedStatement) { +// EmbeddedStatement = embeddedStatement; +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitOnErrorStatement(this, data); +// } +// +// public override string ToString() { +// return string.Format("[OnErrorStatement EmbeddedStatement={0}]", EmbeddedStatement); +// } +// } +// +// public class OperatorDeclaration : MethodDeclaration { +// +// ConversionType conversionType; +// +// OverloadableOperatorType overloadableOperator; +// +// public ConversionType ConversionType { +// get { +// return conversionType; +// } +// set { +// conversionType = value; +// } +// } +// +// public OverloadableOperatorType OverloadableOperator { +// get { +// return overloadableOperator; +// } +// set { +// overloadableOperator = value; +// } +// } +// +// public OperatorDeclaration() { +// } +// +// public bool IsConversionOperator { +// get { +// return conversionType != ConversionType.None; +// } +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitOperatorDeclaration(this, data); +// } +// +// public override string ToString() { +// return string.Format("[OperatorDeclaration ConversionType={0} OverloadableOperator={1} Body={2} Handles" + +// "Clause={3} Templates={4} IsExtensionMethod={5} InterfaceImplementations={6} Type" + +// "Reference={7} Name={8} Parameters={9} Attributes={10} Modifier={11}]", ConversionType, OverloadableOperator, Body, GetCollectionString(HandlesClause), GetCollectionString(Templates), IsExtensionMethod, GetCollectionString(InterfaceImplementations), TypeReference, Name, GetCollectionString(Parameters), GetCollectionString(Attributes), Modifier); +// } +// } +// +// public class ParameterDeclarationExpression : Expression { +// +// List attributes; +// +// string parameterName; +// +// TypeReference typeReference; +// +// ParameterModifiers paramModifier; +// +// Expression defaultValue; +// +// public List Attributes { +// get { +// return attributes; +// } +// set { +// attributes = value ?? new List(); +// } +// } +// +// public string ParameterName { +// get { +// return parameterName; +// } +// set { +// parameterName = string.IsNullOrEmpty(value) ? "?" : value; +// } +// } +// +// public TypeReference TypeReference { +// get { +// return typeReference; +// } +// set { +// typeReference = value ?? TypeReference.Null; +// if (!typeReference.IsNull) typeReference.Parent = this; +// } +// } +// +// public ParameterModifiers ParamModifier { +// get { +// return paramModifier; +// } +// set { +// paramModifier = value; +// } +// } +// +// public Expression DefaultValue { +// get { +// return defaultValue; +// } +// set { +// defaultValue = value ?? Expression.Null; +// if (!defaultValue.IsNull) defaultValue.Parent = this; +// } +// } +// +// public ParameterDeclarationExpression(TypeReference typeReference, string parameterName) { +// TypeReference = typeReference; +// ParameterName = parameterName; +// attributes = new List(); +// defaultValue = Expression.Null; +// } +// +// public ParameterDeclarationExpression(TypeReference typeReference, string parameterName, ParameterModifiers paramModifier) { +// TypeReference = typeReference; +// ParameterName = parameterName; +// ParamModifier = paramModifier; +// attributes = new List(); +// defaultValue = Expression.Null; +// } +// +// public ParameterDeclarationExpression(TypeReference typeReference, string parameterName, ParameterModifiers paramModifier, Expression defaultValue) { +// TypeReference = typeReference; +// ParameterName = parameterName; +// ParamModifier = paramModifier; +// DefaultValue = defaultValue; +// attributes = new List(); +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitParameterDeclarationExpression(this, data); +// } +// +// public override string ToString() { +// return string.Format("[ParameterDeclarationExpression Attributes={0} ParameterName={1} TypeReference={2" + +// "} ParamModifier={3} DefaultValue={4}]", GetCollectionString(Attributes), ParameterName, TypeReference, ParamModifier, DefaultValue); +// } +// } +// +// public abstract class ParametrizedNode : AttributedNode { +// +// string name; +// +// List parameters; +// +// public string Name { +// get { +// return name; +// } +// set { +// name = value ?? ""; +// } +// } +// +// public List Parameters { +// get { +// return parameters; +// } +// set { +// parameters = value ?? new List(); +// } +// } +// +// protected ParametrizedNode() { +// name = ""; +// parameters = new List(); +// } +// +// protected ParametrizedNode(Modifiers modifier, List attributes, string name, List parameters) { +// Modifier = modifier; +// Attributes = attributes; +// Name = name; +// Parameters = parameters; +// } +// } +// +// public class ParenthesizedExpression : Expression { +// +// Expression expression; +// +// public Expression Expression { +// get { +// return expression; +// } +// set { +// expression = value ?? Expression.Null; +// if (!expression.IsNull) expression.Parent = this; +// } +// } +// +// public ParenthesizedExpression(Expression expression) { +// Expression = expression; +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitParenthesizedExpression(this, data); +// } +// +// public override string ToString() { +// return string.Format("[ParenthesizedExpression Expression={0}]", Expression); +// } +// } +// +// public class PropertyDeclaration : MemberNode { +// +// Location bodyStart; +// +// Location bodyEnd; +// +// PropertyGetRegion getRegion; +// +// PropertySetRegion setRegion; +// +// Expression initializer; +// +// public Location BodyStart { +// get { +// return bodyStart; +// } +// set { +// bodyStart = value; +// } +// } +// +// public Location BodyEnd { +// get { +// return bodyEnd; +// } +// set { +// bodyEnd = value; +// } +// } +// +// public PropertyGetRegion GetRegion { +// get { +// return getRegion; +// } +// set { +// getRegion = value ?? PropertyGetRegion.Null; +// if (!getRegion.IsNull) getRegion.Parent = this; +// } +// } +// +// public PropertySetRegion SetRegion { +// get { +// return setRegion; +// } +// set { +// setRegion = value ?? PropertySetRegion.Null; +// if (!setRegion.IsNull) setRegion.Parent = this; +// } +// } +// +// public Expression Initializer { +// get { +// return initializer; +// } +// set { +// initializer = value ?? Expression.Null; +// if (!initializer.IsNull) initializer.Parent = this; +// } +// } +// +// public PropertyDeclaration(Modifiers modifier, List attributes, string name, List parameters) { +// Modifier = modifier; +// Attributes = attributes; +// Name = name; +// Parameters = parameters; +// bodyStart = Location.Empty; +// bodyEnd = Location.Empty; +// getRegion = PropertyGetRegion.Null; +// setRegion = PropertySetRegion.Null; +// initializer = Expression.Null; +// } +// +// public bool IsReadOnly { +// get { +// return HasGetRegion && !HasSetRegion; +// } +// } +// +// public bool HasGetRegion { +// get { +// return !getRegion.IsNull; +// } +// } +// +// public bool IsWriteOnly { +// get { +// return !HasGetRegion && HasSetRegion; +// } +// } +// +// public bool IsIndexer { +// get { +// return (Modifier & Modifiers.Default) != 0; +// } +// } +// +// +// internal PropertyDeclaration(string name, TypeReference typeReference, Modifiers modifier, List attributes) : this(modifier, attributes, name, null) +// { +// this.TypeReference = typeReference; +// if ((modifier & Modifiers.ReadOnly) != Modifiers.ReadOnly) { +// this.SetRegion = new PropertySetRegion(null, null); +// } +// if ((modifier & Modifiers.WriteOnly) != Modifiers.WriteOnly) { +// this.GetRegion = new PropertyGetRegion(null, null); +// } +// } +// +// public bool HasSetRegion { +// get { +// return !setRegion.IsNull; +// } +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitPropertyDeclaration(this, data); +// } +// +// public override string ToString() { +// return string.Format("[PropertyDeclaration BodyStart={0} BodyEnd={1} GetRegion={2} SetRegion={3} Initia" + +// "lizer={4} InterfaceImplementations={5} TypeReference={6} Name={7} Parameters={8}" + +// " Attributes={9} Modifier={10}]", BodyStart, BodyEnd, GetRegion, SetRegion, Initializer, GetCollectionString(InterfaceImplementations), TypeReference, Name, GetCollectionString(Parameters), GetCollectionString(Attributes), Modifier); +// } +// } +// +// public class PropertyGetRegion : PropertyGetSetRegion { +// +// public PropertyGetRegion(BlockStatement block, List attributes) : +// base(block, attributes) { +// } +// +// public static PropertyGetRegion Null { +// get { +// return NullPropertyGetRegion.Instance; +// } +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitPropertyGetRegion(this, data); +// } +// +// public override string ToString() { +// return string.Format("[PropertyGetRegion Block={0} Attributes={1} Modifier={2}]", Block, GetCollectionString(Attributes), Modifier); +// } +// } +// +// internal sealed class NullPropertyGetRegion : PropertyGetRegion { +// +// private NullPropertyGetRegion() : +// base(null, null) { +// } +// +// internal static NullPropertyGetRegion Instance = new NullPropertyGetRegion(); +// +// public override bool IsNull { +// get { +// return true; +// } +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return null; +// } +// +// public override string ToString() { +// return "[NullPropertyGetRegion]"; +// } +// } +// +// public abstract class PropertyGetSetRegion : AttributedNode, INullable { +// +// BlockStatement block; +// +// public BlockStatement Block { +// get { +// return block; +// } +// set { +// block = value ?? BlockStatement.Null; +// if (!block.IsNull) block.Parent = this; +// } +// } +// +// protected PropertyGetSetRegion(BlockStatement block, List attributes) { +// Block = block; +// Attributes = attributes; +// } +// +// public virtual bool IsNull { +// get { +// return false; +// } +// } +// } +// +// public class PropertySetRegion : PropertyGetSetRegion { +// +// List parameters; +// +// public List Parameters { +// get { +// return parameters; +// } +// set { +// parameters = value ?? new List(); +// } +// } +// +// public PropertySetRegion(BlockStatement block, List attributes) : +// base(block, attributes) { +// parameters = new List(); +// } +// +// public static PropertySetRegion Null { +// get { +// return NullPropertySetRegion.Instance; +// } +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitPropertySetRegion(this, data); +// } +// +// public override string ToString() { +// return string.Format("[PropertySetRegion Parameters={0} Block={1} Attributes={2} Modifier={3}]", GetCollectionString(Parameters), Block, GetCollectionString(Attributes), Modifier); +// } +// } +// +// internal sealed class NullPropertySetRegion : PropertySetRegion { +// +// private NullPropertySetRegion() : +// base(null, null) { +// } +// +// internal static NullPropertySetRegion Instance = new NullPropertySetRegion(); +// +// public override bool IsNull { +// get { +// return true; +// } +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return null; +// } +// +// public override string ToString() { +// return "[NullPropertySetRegion]"; +// } +// } +// +// public class QueryExpression : Expression { +// +// List clauses; +// +// public List Clauses { +// get { +// return clauses; +// } +// set { +// clauses = value ?? new List(); +// } +// } +// +// public QueryExpression() { +// clauses = new List(); +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitQueryExpression(this, data); +// } +// +// public override string ToString() { +// return string.Format("[QueryExpression Clauses={0}]", GetCollectionString(Clauses)); +// } +// } +// +// public class QueryExpressionAggregateClause : QueryExpressionClause { +// +// CollectionRangeVariable source; +// +// List middleClauses; +// +// List intoVariables; +// +// public CollectionRangeVariable Source { +// get { +// return source; +// } +// set { +// source = value ?? CollectionRangeVariable.Null; +// if (!source.IsNull) source.Parent = this; +// } +// } +// +// public List MiddleClauses { +// get { +// return middleClauses; +// } +// set { +// middleClauses = value ?? new List(); +// } +// } +// +// public List IntoVariables { +// get { +// return intoVariables; +// } +// set { +// intoVariables = value ?? new List(); +// } +// } +// +// public QueryExpressionAggregateClause() { +// source = CollectionRangeVariable.Null; +// middleClauses = new List(); +// intoVariables = new List(); +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitQueryExpressionAggregateClause(this, data); +// } +// +// public override string ToString() { +// return string.Format("[QueryExpressionAggregateClause Source={0} MiddleClauses={1} IntoVariables={2}]", Source, GetCollectionString(MiddleClauses), GetCollectionString(IntoVariables)); +// } +// } +// +// public abstract class QueryExpressionClause : AbstractNode, INullable { +// +// protected QueryExpressionClause() { +// } +// +// public virtual bool IsNull { +// get { +// return false; +// } +// } +// +// public static QueryExpressionClause Null { +// get { +// return NullQueryExpressionClause.Instance; +// } +// } +// } +// +// internal sealed class NullQueryExpressionClause : QueryExpressionClause { +// +// internal static NullQueryExpressionClause Instance = new NullQueryExpressionClause(); +// +// public override bool IsNull { +// get { +// return true; +// } +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return null; +// } +// +// public override string ToString() { +// return "[NullQueryExpressionClause]"; +// } +// } +// +// public class QueryExpressionDistinctClause : QueryExpressionClause { +// +// public QueryExpressionDistinctClause() { +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitQueryExpressionDistinctClause(this, data); +// } +// +// public override string ToString() { +// return "[QueryExpressionDistinctClause]"; +// } +// } +// +// public class QueryExpressionFromClause : QueryExpressionClause { +// +// List sources; +// +// public List Sources { +// get { +// return sources; +// } +// set { +// sources = value ?? new List(); +// } +// } +// +// public QueryExpressionFromClause() { +// sources = new List(); +// } +// +// public new static QueryExpressionFromClause Null { +// get { +// return NullQueryExpressionFromClause.Instance; +// } +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitQueryExpressionFromClause(this, data); +// } +// +// public override string ToString() { +// return string.Format("[QueryExpressionFromClause Sources={0}]", GetCollectionString(Sources)); +// } +// } +// +// internal sealed class NullQueryExpressionFromClause : QueryExpressionFromClause { +// +// internal static NullQueryExpressionFromClause Instance = new NullQueryExpressionFromClause(); +// +// public override bool IsNull { +// get { +// return true; +// } +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return null; +// } +// +// public override string ToString() { +// return "[NullQueryExpressionFromClause]"; +// } +// } +// +// public class QueryExpressionGroupClause : QueryExpressionClause { +// +// Expression projection; +// +// Expression groupBy; +// +// public Expression Projection { +// get { +// return projection; +// } +// set { +// projection = value ?? Expression.Null; +// if (!projection.IsNull) projection.Parent = this; +// } +// } +// +// public Expression GroupBy { +// get { +// return groupBy; +// } +// set { +// groupBy = value ?? Expression.Null; +// if (!groupBy.IsNull) groupBy.Parent = this; +// } +// } +// +// public QueryExpressionGroupClause() { +// projection = Expression.Null; +// groupBy = Expression.Null; +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitQueryExpressionGroupClause(this, data); +// } +// +// public override string ToString() { +// return string.Format("[QueryExpressionGroupClause Projection={0} GroupBy={1}]", Projection, GroupBy); +// } +// } +// +// public class QueryExpressionGroupJoinVBClause : QueryExpressionClause { +// +// QueryExpressionJoinVBClause joinClause; +// +// List intoVariables; +// +// public QueryExpressionJoinVBClause JoinClause { +// get { +// return joinClause; +// } +// set { +// joinClause = value ?? QueryExpressionJoinVBClause.Null; +// if (!joinClause.IsNull) joinClause.Parent = this; +// } +// } +// +// public List IntoVariables { +// get { +// return intoVariables; +// } +// set { +// intoVariables = value ?? new List(); +// } +// } +// +// public QueryExpressionGroupJoinVBClause() { +// joinClause = QueryExpressionJoinVBClause.Null; +// intoVariables = new List(); +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitQueryExpressionGroupJoinVBClause(this, data); +// } +// +// public override string ToString() { +// return string.Format("[QueryExpressionGroupJoinVBClause JoinClause={0} IntoVariables={1}]", JoinClause, GetCollectionString(IntoVariables)); +// } +// } +// +// public class QueryExpressionGroupVBClause : QueryExpressionClause { +// +// List groupVariables; +// +// List byVariables; +// +// List intoVariables; +// +// public List GroupVariables { +// get { +// return groupVariables; +// } +// set { +// groupVariables = value ?? new List(); +// } +// } +// +// public List ByVariables { +// get { +// return byVariables; +// } +// set { +// byVariables = value ?? new List(); +// } +// } +// +// public List IntoVariables { +// get { +// return intoVariables; +// } +// set { +// intoVariables = value ?? new List(); +// } +// } +// +// public QueryExpressionGroupVBClause() { +// groupVariables = new List(); +// byVariables = new List(); +// intoVariables = new List(); +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitQueryExpressionGroupVBClause(this, data); +// } +// +// public override string ToString() { +// return string.Format("[QueryExpressionGroupVBClause GroupVariables={0} ByVariables={1} IntoVariables={2" + +// "}]", GetCollectionString(GroupVariables), GetCollectionString(ByVariables), GetCollectionString(IntoVariables)); +// } +// } +// +// public class QueryExpressionJoinClause : QueryExpressionClause { +// +// Expression onExpression; +// +// Expression equalsExpression; +// +// CollectionRangeVariable source; +// +// string intoIdentifier; +// +// public Expression OnExpression { +// get { +// return onExpression; +// } +// set { +// onExpression = value ?? Expression.Null; +// if (!onExpression.IsNull) onExpression.Parent = this; +// } +// } +// +// public Expression EqualsExpression { +// get { +// return equalsExpression; +// } +// set { +// equalsExpression = value ?? Expression.Null; +// if (!equalsExpression.IsNull) equalsExpression.Parent = this; +// } +// } +// +// public CollectionRangeVariable Source { +// get { +// return source; +// } +// set { +// source = value ?? CollectionRangeVariable.Null; +// if (!source.IsNull) source.Parent = this; +// } +// } +// +// public string IntoIdentifier { +// get { +// return intoIdentifier; +// } +// set { +// intoIdentifier = value ?? ""; +// } +// } +// +// public QueryExpressionJoinClause() { +// onExpression = Expression.Null; +// equalsExpression = Expression.Null; +// source = CollectionRangeVariable.Null; +// intoIdentifier = ""; +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitQueryExpressionJoinClause(this, data); +// } +// +// public override string ToString() { +// return string.Format("[QueryExpressionJoinClause OnExpression={0} EqualsExpression={1} Source={2} IntoI" + +// "dentifier={3}]", OnExpression, EqualsExpression, Source, IntoIdentifier); +// } +// } +// +// public class QueryExpressionJoinConditionVB : AbstractNode { +// +// Expression leftSide; +// +// Expression rightSide; +// +// public Expression LeftSide { +// get { +// return leftSide; +// } +// set { +// leftSide = value ?? Expression.Null; +// if (!leftSide.IsNull) leftSide.Parent = this; +// } +// } +// +// public Expression RightSide { +// get { +// return rightSide; +// } +// set { +// rightSide = value ?? Expression.Null; +// if (!rightSide.IsNull) rightSide.Parent = this; +// } +// } +// +// public QueryExpressionJoinConditionVB() { +// leftSide = Expression.Null; +// rightSide = Expression.Null; +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitQueryExpressionJoinConditionVB(this, data); +// } +// +// public override string ToString() { +// return string.Format("[QueryExpressionJoinConditionVB LeftSide={0} RightSide={1}]", LeftSide, RightSide); +// } +// } +// +// public class QueryExpressionJoinVBClause : QueryExpressionClause { +// +// CollectionRangeVariable joinVariable; +// +// QueryExpressionJoinVBClause subJoin; +// +// List conditions; +// +// public CollectionRangeVariable JoinVariable { +// get { +// return joinVariable; +// } +// set { +// joinVariable = value ?? CollectionRangeVariable.Null; +// if (!joinVariable.IsNull) joinVariable.Parent = this; +// } +// } +// +// public QueryExpressionJoinVBClause SubJoin { +// get { +// return subJoin; +// } +// set { +// subJoin = value ?? QueryExpressionJoinVBClause.Null; +// if (!subJoin.IsNull) subJoin.Parent = this; +// } +// } +// +// public List Conditions { +// get { +// return conditions; +// } +// set { +// conditions = value ?? new List(); +// } +// } +// +// public QueryExpressionJoinVBClause() { +// joinVariable = CollectionRangeVariable.Null; +// subJoin = QueryExpressionJoinVBClause.Null; +// conditions = new List(); +// } +// +// public new static QueryExpressionJoinVBClause Null { +// get { +// return NullQueryExpressionJoinVBClause.Instance; +// } +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitQueryExpressionJoinVBClause(this, data); +// } +// +// public override string ToString() { +// return string.Format("[QueryExpressionJoinVBClause JoinVariable={0} SubJoin={1} Conditions={2}]", JoinVariable, SubJoin, GetCollectionString(Conditions)); +// } +// } +// +// internal sealed class NullQueryExpressionJoinVBClause : QueryExpressionJoinVBClause { +// +// internal static NullQueryExpressionJoinVBClause Instance = new NullQueryExpressionJoinVBClause(); +// +// public override bool IsNull { +// get { +// return true; +// } +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return null; +// } +// +// public override string ToString() { +// return "[NullQueryExpressionJoinVBClause]"; +// } +// } +// +// public class QueryExpressionLetClause : QueryExpressionClause { +// +// List variables; +// +// public List Variables { +// get { +// return variables; +// } +// set { +// variables = value ?? new List(); +// } +// } +// +// public QueryExpressionLetClause() { +// variables = new List(); +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitQueryExpressionLetVBClause(this, data); +// } +// +// public override string ToString() { +// return string.Format("[QueryExpressionLetVBClause Variables={0}]", GetCollectionString(Variables)); +// } +// } +// +// public class QueryExpressionOrderClause : QueryExpressionClause { +// +// List orderings; +// +// public List Orderings { +// get { +// return orderings; +// } +// set { +// orderings = value ?? new List(); +// } +// } +// +// public QueryExpressionOrderClause() { +// orderings = new List(); +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitQueryExpressionOrderClause(this, data); +// } +// +// public override string ToString() { +// return string.Format("[QueryExpressionOrderClause Orderings={0}]", GetCollectionString(Orderings)); +// } +// } +// +// public class QueryExpressionOrdering : AbstractNode { +// +// Expression criteria; +// +// QueryExpressionOrderingDirection direction; +// +// public Expression Criteria { +// get { +// return criteria; +// } +// set { +// criteria = value ?? Expression.Null; +// if (!criteria.IsNull) criteria.Parent = this; +// } +// } +// +// public QueryExpressionOrderingDirection Direction { +// get { +// return direction; +// } +// set { +// direction = value; +// } +// } +// +// public QueryExpressionOrdering() { +// criteria = Expression.Null; +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitQueryExpressionOrdering(this, data); +// } +// +// public override string ToString() { +// return string.Format("[QueryExpressionOrdering Criteria={0} Direction={1}]", Criteria, Direction); +// } +// } +// +// public class QueryExpressionPartitionVBClause : QueryExpressionClause { +// +// Expression expression; +// +// QueryExpressionPartitionType partitionType; +// +// public Expression Expression { +// get { +// return expression; +// } +// set { +// expression = value ?? Expression.Null; +// if (!expression.IsNull) expression.Parent = this; +// } +// } +// +// public QueryExpressionPartitionType PartitionType { +// get { +// return partitionType; +// } +// set { +// partitionType = value; +// } +// } +// +// public QueryExpressionPartitionVBClause() { +// expression = Expression.Null; +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitQueryExpressionPartitionVBClause(this, data); +// } +// +// public override string ToString() { +// return string.Format("[QueryExpressionPartitionVBClause Expression={0} PartitionType={1}]", Expression, PartitionType); +// } +// } +// +// public class QueryExpressionSelectClause : QueryExpressionClause { +// +// Expression projection; +// +// public Expression Projection { +// get { +// return projection; +// } +// set { +// projection = value ?? Expression.Null; +// if (!projection.IsNull) projection.Parent = this; +// } +// } +// +// public QueryExpressionSelectClause() { +// projection = Expression.Null; +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitQueryExpressionSelectClause(this, data); +// } +// +// public override string ToString() { +// return string.Format("[QueryExpressionSelectClause Projection={0}]", Projection); +// } +// } +// +// public class QueryExpressionSelectVBClause : QueryExpressionClause { +// +// List variables; +// +// public List Variables { +// get { +// return variables; +// } +// set { +// variables = value ?? new List(); +// } +// } +// +// public QueryExpressionSelectVBClause() { +// variables = new List(); +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitQueryExpressionSelectVBClause(this, data); +// } +// +// public override string ToString() { +// return string.Format("[QueryExpressionSelectVBClause Variables={0}]", GetCollectionString(Variables)); +// } +// } +// +// public class QueryExpressionWhereClause : QueryExpressionClause { +// +// Expression condition; +// +// public Expression Condition { +// get { +// return condition; +// } +// set { +// condition = value ?? Expression.Null; +// if (!condition.IsNull) condition.Parent = this; +// } +// } +// +// public QueryExpressionWhereClause() { +// condition = Expression.Null; +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitQueryExpressionWhereClause(this, data); +// } +// +// public override string ToString() { +// return string.Format("[QueryExpressionWhereClause Condition={0}]", Condition); +// } +// } +// +// public class RaiseEventStatement : Statement { +// +// string eventName; +// +// List arguments; +// +// public string EventName { +// get { +// return eventName; +// } +// set { +// eventName = value ?? ""; +// } +// } +// +// public List Arguments { +// get { +// return arguments; +// } +// set { +// arguments = value ?? new List(); +// } +// } +// +// public RaiseEventStatement(string eventName, List arguments) { +// EventName = eventName; +// Arguments = arguments; +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitRaiseEventStatement(this, data); +// } +// +// public override string ToString() { +// return string.Format("[RaiseEventStatement EventName={0} Arguments={1}]", EventName, GetCollectionString(Arguments)); +// } +// } +// +// public class ReDimStatement : Statement { +// +// List reDimClauses; +// +// bool isPreserve; +// +// public List ReDimClauses { +// get { +// return reDimClauses; +// } +// set { +// reDimClauses = value ?? new List(); +// } +// } +// +// public bool IsPreserve { +// get { +// return isPreserve; +// } +// set { +// isPreserve = value; +// } +// } +// +// public ReDimStatement(bool isPreserve) { +// IsPreserve = isPreserve; +// reDimClauses = new List(); +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitReDimStatement(this, data); +// } +// +// public override string ToString() { +// return string.Format("[ReDimStatement ReDimClauses={0} IsPreserve={1}]", GetCollectionString(ReDimClauses), IsPreserve); +// } +// } +// +// public class RemoveHandlerStatement : Statement { +// +// Expression eventExpression; +// +// Expression handlerExpression; +// +// public Expression EventExpression { +// get { +// return eventExpression; +// } +// set { +// eventExpression = value ?? Expression.Null; +// if (!eventExpression.IsNull) eventExpression.Parent = this; +// } +// } +// +// public Expression HandlerExpression { +// get { +// return handlerExpression; +// } +// set { +// handlerExpression = value ?? Expression.Null; +// if (!handlerExpression.IsNull) handlerExpression.Parent = this; +// } +// } +// +// public RemoveHandlerStatement(Expression eventExpression, Expression handlerExpression) { +// EventExpression = eventExpression; +// HandlerExpression = handlerExpression; +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitRemoveHandlerStatement(this, data); +// } +// +// public override string ToString() { +// return string.Format("[RemoveHandlerStatement EventExpression={0} HandlerExpression={1}]", EventExpression, HandlerExpression); +// } +// } +// +// public class ResumeStatement : Statement { +// +// string labelName; +// +// bool isResumeNext; +// +// public string LabelName { +// get { +// return labelName; +// } +// set { +// labelName = value ?? ""; +// } +// } +// +// public bool IsResumeNext { +// get { +// return isResumeNext; +// } +// set { +// isResumeNext = value; +// } +// } +// +// public ResumeStatement(bool isResumeNext) { +// IsResumeNext = isResumeNext; +// labelName = ""; +// } +// +// public ResumeStatement(string labelName) { +// LabelName = labelName; +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitResumeStatement(this, data); +// } +// +// public override string ToString() { +// return string.Format("[ResumeStatement LabelName={0} IsResumeNext={1}]", LabelName, IsResumeNext); +// } +// } +// +// public class ReturnStatement : Statement { +// +// Expression expression; +// +// public Expression Expression { +// get { +// return expression; +// } +// set { +// expression = value ?? Expression.Null; +// if (!expression.IsNull) expression.Parent = this; +// } +// } +// +// public ReturnStatement(Expression expression) { +// Expression = expression; +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitReturnStatement(this, data); +// } +// +// public override string ToString() { +// return string.Format("[ReturnStatement Expression={0}]", Expression); +// } +// } +// +// public class StopStatement : Statement { +// +// public StopStatement() { +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitStopStatement(this, data); +// } +// +// public override string ToString() { +// return "[StopStatement]"; +// } +// } +// +// public class SwitchSection : BlockStatement { +// +// List switchLabels; +// +// public List SwitchLabels { +// get { +// return switchLabels; +// } +// set { +// switchLabels = value ?? new List(); +// } +// } +// +// public SwitchSection() { +// switchLabels = new List(); +// } +// +// public SwitchSection(List switchLabels) { +// SwitchLabels = switchLabels; +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitSwitchSection(this, data); +// } +// +// public override string ToString() { +// return string.Format("[SwitchSection SwitchLabels={0}]", GetCollectionString(SwitchLabels)); +// } +// } +// +// public class SwitchStatement : Statement { +// +// Expression switchExpression; +// +// List switchSections; +// +// public Expression SwitchExpression { +// get { +// return switchExpression; +// } +// set { +// switchExpression = value ?? Expression.Null; +// if (!switchExpression.IsNull) switchExpression.Parent = this; +// } +// } +// +// public List SwitchSections { +// get { +// return switchSections; +// } +// set { +// switchSections = value ?? new List(); +// } +// } +// +// public SwitchStatement(Expression switchExpression, List switchSections) { +// SwitchExpression = switchExpression; +// SwitchSections = switchSections; +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitSwitchStatement(this, data); +// } +// +// public override string ToString() { +// return string.Format("[SwitchStatement SwitchExpression={0} SwitchSections={1}]", SwitchExpression, GetCollectionString(SwitchSections)); +// } +// } +// +// public class TemplateDefinition : AttributedNode { +// +// string name; +// +// VarianceModifier varianceModifier; +// +// List bases; +// +// public string Name { +// get { +// return name; +// } +// set { +// name = string.IsNullOrEmpty(value) ? "?" : value; +// } +// } +// +// public VarianceModifier VarianceModifier { +// get { +// return varianceModifier; +// } +// set { +// varianceModifier = value; +// } +// } +// +// public List Bases { +// get { +// return bases; +// } +// set { +// bases = value ?? new List(); +// } +// } +// +// public TemplateDefinition() { +// name = "?"; +// bases = new List(); +// } +// +// public TemplateDefinition(string name, List attributes) { +// Name = name; +// Attributes = attributes; +// bases = new List(); +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitTemplateDefinition(this, data); +// } +// +// public override string ToString() { +// return string.Format("[TemplateDefinition Name={0} VarianceModifier={1} Bases={2} Attributes={3} Modifi" + +// "er={4}]", Name, VarianceModifier, GetCollectionString(Bases), GetCollectionString(Attributes), Modifier); +// } +// } +// +// public class ThisReferenceExpression : Expression { +// +// public ThisReferenceExpression() { +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitThisReferenceExpression(this, data); +// } +// +// public override string ToString() { +// return "[ThisReferenceExpression]"; +// } +// } +// +// public class ThrowStatement : Statement { +// +// Expression expression; +// +// public Expression Expression { +// get { +// return expression; +// } +// set { +// expression = value ?? Expression.Null; +// if (!expression.IsNull) expression.Parent = this; +// } +// } +// +// public ThrowStatement(Expression expression) { +// Expression = expression; +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitThrowStatement(this, data); +// } +// +// public override string ToString() { +// return string.Format("[ThrowStatement Expression={0}]", Expression); +// } +// } +// +// public class TryCatchStatement : Statement { +// +// Statement statementBlock; +// +// List catchClauses; +// +// Statement finallyBlock; +// +// public Statement StatementBlock { +// get { +// return statementBlock; +// } +// set { +// statementBlock = value ?? Statement.Null; +// if (!statementBlock.IsNull) statementBlock.Parent = this; +// } +// } +// +// public List CatchClauses { +// get { +// return catchClauses; +// } +// set { +// catchClauses = value ?? new List(); +// } +// } +// +// public Statement FinallyBlock { +// get { +// return finallyBlock; +// } +// set { +// finallyBlock = value ?? Statement.Null; +// if (!finallyBlock.IsNull) finallyBlock.Parent = this; +// } +// } +// +// public TryCatchStatement(Statement statementBlock, List catchClauses, Statement finallyBlock) { +// StatementBlock = statementBlock; +// CatchClauses = catchClauses; +// FinallyBlock = finallyBlock; +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitTryCatchStatement(this, data); +// } +// +// public override string ToString() { +// return string.Format("[TryCatchStatement StatementBlock={0} CatchClauses={1} FinallyBlock={2}]", StatementBlock, GetCollectionString(CatchClauses), FinallyBlock); +// } +// } +// +// public class TypeDeclaration : AttributedNode { +// +// string name; +// +// ClassType type; +// +// List baseTypes; +// +// List templates; +// +// Location bodyStartLocation; +// +// public string Name { +// get { +// return name; +// } +// set { +// name = value ?? ""; +// } +// } +// +// public ClassType Type { +// get { +// return type; +// } +// set { +// type = value; +// } +// } +// +// public List BaseTypes { +// get { +// return baseTypes; +// } +// set { +// baseTypes = value ?? new List(); +// } +// } +// +// public List Templates { +// get { +// return templates; +// } +// set { +// templates = value ?? new List(); +// } +// } +// +// public Location BodyStartLocation { +// get { +// return bodyStartLocation; +// } +// set { +// bodyStartLocation = value; +// } +// } +// +// public TypeDeclaration(Modifiers modifier, List attributes) { +// Modifier = modifier; +// Attributes = attributes; +// name = ""; +// baseTypes = new List(); +// templates = new List(); +// bodyStartLocation = Location.Empty; +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitTypeDeclaration(this, data); +// } +// +// public override string ToString() { +// return string.Format("[TypeDeclaration Name={0} Type={1} BaseTypes={2} Templates={3} BodyStartLocation=" + +// "{4} Attributes={5} Modifier={6}]", Name, Type, GetCollectionString(BaseTypes), GetCollectionString(Templates), BodyStartLocation, GetCollectionString(Attributes), Modifier); +// } +// } +// +// public class TypeOfExpression : Expression { +// +// TypeReference typeReference; +// +// public TypeReference TypeReference { +// get { +// return typeReference; +// } +// set { +// typeReference = value ?? TypeReference.Null; +// if (!typeReference.IsNull) typeReference.Parent = this; +// } +// } +// +// public TypeOfExpression(TypeReference typeReference) { +// TypeReference = typeReference; +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitTypeOfExpression(this, data); +// } +// +// public override string ToString() { +// return string.Format("[TypeOfExpression TypeReference={0}]", TypeReference); +// } +// } +// +// public class TypeOfIsExpression : Expression { +// +// Expression expression; +// +// TypeReference typeReference; +// +// public Expression Expression { +// get { +// return expression; +// } +// set { +// expression = value ?? Expression.Null; +// if (!expression.IsNull) expression.Parent = this; +// } +// } +// +// public TypeReference TypeReference { +// get { +// return typeReference; +// } +// set { +// typeReference = value ?? TypeReference.Null; +// if (!typeReference.IsNull) typeReference.Parent = this; +// } +// } +// +// public TypeOfIsExpression(Expression expression, TypeReference typeReference) { +// Expression = expression; +// TypeReference = typeReference; +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitTypeOfIsExpression(this, data); +// } +// +// public override string ToString() { +// return string.Format("[TypeOfIsExpression Expression={0} TypeReference={1}]", Expression, TypeReference); +// } +// } +// +// public class TypeReferenceExpression : Expression { +// +// TypeReference typeReference; +// +// public TypeReference TypeReference { +// get { +// return typeReference; +// } +// set { +// typeReference = value ?? TypeReference.Null; +// if (!typeReference.IsNull) typeReference.Parent = this; +// } +// } +// +// public TypeReferenceExpression(TypeReference typeReference) { +// TypeReference = typeReference; +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitTypeReferenceExpression(this, data); +// } +// +// public override string ToString() { +// return string.Format("[TypeReferenceExpression TypeReference={0}]", TypeReference); +// } +// } +// +// public class UnaryOperatorExpression : Expression { +// +// UnaryOperatorType op; +// +// Expression expression; +// +// public UnaryOperatorType Op { +// get { +// return op; +// } +// set { +// op = value; +// } +// } +// +// public Expression Expression { +// get { +// return expression; +// } +// set { +// expression = value ?? Expression.Null; +// if (!expression.IsNull) expression.Parent = this; +// } +// } +// +// public UnaryOperatorExpression(UnaryOperatorType op) { +// Op = op; +// expression = Expression.Null; +// } +// +// public UnaryOperatorExpression(Expression expression, UnaryOperatorType op) { +// Expression = expression; +// Op = op; +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitUnaryOperatorExpression(this, data); +// } +// +// public override string ToString() { +// return string.Format("[UnaryOperatorExpression Op={0} Expression={1}]", Op, Expression); +// } +// } +// +// public class UsingStatement : StatementWithEmbeddedStatement { +// +// Statement resourceAcquisition; +// +// public Statement ResourceAcquisition { +// get { +// return resourceAcquisition; +// } +// set { +// resourceAcquisition = value ?? Statement.Null; +// if (!resourceAcquisition.IsNull) resourceAcquisition.Parent = this; +// } +// } +// +// public UsingStatement(Statement resourceAcquisition, Statement embeddedStatement) { +// ResourceAcquisition = resourceAcquisition; +// EmbeddedStatement = embeddedStatement; +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitUsingStatement(this, data); +// } +// +// public override string ToString() { +// return string.Format("[UsingStatement ResourceAcquisition={0} EmbeddedStatement={1}]", ResourceAcquisition, EmbeddedStatement); +// } +// } +// +// public class VariableDeclaration : AbstractNode { +// +// string name; +// +// Expression initializer; +// +// TypeReference typeReference; +// +// Expression fixedArrayInitialization; +// +// public string Name { +// get { +// return name; +// } +// set { +// name = value ?? ""; +// } +// } +// +// public Expression Initializer { +// get { +// return initializer; +// } +// set { +// initializer = value ?? Expression.Null; +// if (!initializer.IsNull) initializer.Parent = this; +// } +// } +// +// public TypeReference TypeReference { +// get { +// return typeReference; +// } +// set { +// typeReference = value ?? TypeReference.Null; +// if (!typeReference.IsNull) typeReference.Parent = this; +// } +// } +// +// public Expression FixedArrayInitialization { +// get { +// return fixedArrayInitialization; +// } +// set { +// fixedArrayInitialization = value ?? Expression.Null; +// if (!fixedArrayInitialization.IsNull) fixedArrayInitialization.Parent = this; +// } +// } +// +// public VariableDeclaration(string name) { +// Name = name; +// initializer = Expression.Null; +// typeReference = TypeReference.Null; +// fixedArrayInitialization = Expression.Null; +// } +// +// public VariableDeclaration(string name, Expression initializer) { +// Name = name; +// Initializer = initializer; +// typeReference = TypeReference.Null; +// fixedArrayInitialization = Expression.Null; +// } +// +// public VariableDeclaration(string name, Expression initializer, TypeReference typeReference) { +// Name = name; +// Initializer = initializer; +// TypeReference = typeReference; +// fixedArrayInitialization = Expression.Null; +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitVariableDeclaration(this, data); +// } +// +// public override string ToString() { +// return string.Format("[VariableDeclaration Name={0} Initializer={1} TypeReference={2} FixedArrayInitial" + +// "ization={3}]", Name, Initializer, TypeReference, FixedArrayInitialization); +// } +// } +// +// public class WithStatement : Statement { +// +// Expression expression; +// +// BlockStatement body; +// +// public Expression Expression { +// get { +// return expression; +// } +// set { +// expression = value ?? Expression.Null; +// if (!expression.IsNull) expression.Parent = this; +// } +// } +// +// public BlockStatement Body { +// get { +// return body; +// } +// set { +// body = value ?? BlockStatement.Null; +// if (!body.IsNull) body.Parent = this; +// } +// } +// +// public WithStatement(Expression expression) { +// Expression = expression; +// body = BlockStatement.Null; +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitWithStatement(this, data); +// } +// +// public override string ToString() { +// return string.Format("[WithStatement Expression={0} Body={1}]", Expression, Body); +// } +// } +// +// public class XmlAttributeExpression : XmlExpression { +// +// string name; +// +// string literalValue; +// +// bool useDoubleQuotes; +// +// Expression expressionValue; +// +// public string Name { +// get { +// return name; +// } +// set { +// name = value ?? ""; +// } +// } +// +// public string LiteralValue { +// get { +// return literalValue; +// } +// set { +// literalValue = value ?? ""; +// } +// } +// +// public bool UseDoubleQuotes { +// get { +// return useDoubleQuotes; +// } +// set { +// useDoubleQuotes = value; +// } +// } +// +// public Expression ExpressionValue { +// get { +// return expressionValue; +// } +// set { +// expressionValue = value ?? Expression.Null; +// if (!expressionValue.IsNull) expressionValue.Parent = this; +// } +// } +// +// public XmlAttributeExpression() { +// name = ""; +// literalValue = ""; +// expressionValue = Expression.Null; +// } +// +// public bool IsLiteralValue { +// get { +// return expressionValue.IsNull; +// } +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitXmlAttributeExpression(this, data); +// } +// +// public override string ToString() { +// return string.Format("[XmlAttributeExpression Name={0} LiteralValue={1} UseDoubleQuotes={2} ExpressionV" + +// "alue={3}]", Name, LiteralValue, UseDoubleQuotes, ExpressionValue); +// } +// } +// +// public class XmlContentExpression : XmlExpression { +// +// string content; +// +// XmlContentType type; +// +// public string Content { +// get { +// return content; +// } +// set { +// content = value ?? ""; +// } +// } +// +// public XmlContentType Type { +// get { +// return type; +// } +// set { +// type = value; +// } +// } +// +// public XmlContentExpression(string content, XmlContentType type) { +// Content = content; +// Type = type; +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitXmlContentExpression(this, data); +// } +// +// public override string ToString() { +// return string.Format("[XmlContentExpression Content={0} Type={1}]", Content, Type); +// } +// } +// +// public class XmlDocumentExpression : XmlExpression { +// +// List expressions; +// +// public List Expressions { +// get { +// return expressions; +// } +// set { +// expressions = value ?? new List(); +// } +// } +// +// public XmlDocumentExpression() { +// expressions = new List(); +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitXmlDocumentExpression(this, data); +// } +// +// public override string ToString() { +// return string.Format("[XmlDocumentExpression Expressions={0}]", GetCollectionString(Expressions)); +// } +// } +// +// public class XmlElementExpression : XmlExpression { +// +// Expression content; +// +// Expression nameExpression; +// +// string xmlName; +// +// List attributes; +// +// public Expression Content { +// get { +// return content; +// } +// set { +// content = value ?? Expression.Null; +// if (!content.IsNull) content.Parent = this; +// } +// } +// +// public Expression NameExpression { +// get { +// return nameExpression; +// } +// set { +// nameExpression = value ?? Expression.Null; +// if (!nameExpression.IsNull) nameExpression.Parent = this; +// } +// } +// +// public string XmlName { +// get { +// return xmlName; +// } +// set { +// xmlName = value ?? ""; +// } +// } +// +// public List Attributes { +// get { +// return attributes; +// } +// set { +// attributes = value ?? new List(); +// } +// } +// +// public XmlElementExpression() { +// content = Expression.Null; +// nameExpression = Expression.Null; +// xmlName = ""; +// attributes = new List(); +// } +// +// public bool IsExpression { +// get { +// return !content.IsNull; +// } +// } +// +// public bool NameIsExpression { +// get { +// return !nameExpression.IsNull; +// } +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitXmlElementExpression(this, data); +// } +// +// public override string ToString() { +// return string.Format("[XmlElementExpression Content={0} NameExpression={1} XmlName={2} Attributes={3}]", Content, NameExpression, XmlName, GetCollectionString(Attributes)); +// } +// } +// +// public class XmlEmbeddedExpression : XmlExpression { +// +// Expression inlineVBExpression; +// +// public Expression InlineVBExpression { +// get { +// return inlineVBExpression; +// } +// set { +// inlineVBExpression = value ?? Expression.Null; +// if (!inlineVBExpression.IsNull) inlineVBExpression.Parent = this; +// } +// } +// +// public XmlEmbeddedExpression() { +// inlineVBExpression = Expression.Null; +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitXmlEmbeddedExpression(this, data); +// } +// +// public override string ToString() { +// return string.Format("[XmlEmbeddedExpression InlineVBExpression={0}]", InlineVBExpression); +// } +// } +// +// public abstract class XmlExpression : Expression { +// +// protected XmlExpression() { +// } +// } +// +// public class XmlMemberAccessExpression : Expression { +// +// Expression targetObject; +// +// XmlAxisType axisType; +// +// bool isXmlIdentifier; +// +// string identifier; +// +// public Expression TargetObject { +// get { +// return targetObject; +// } +// set { +// targetObject = value ?? Expression.Null; +// if (!targetObject.IsNull) targetObject.Parent = this; +// } +// } +// +// public XmlAxisType AxisType { +// get { +// return axisType; +// } +// set { +// axisType = value; +// } +// } +// +// public bool IsXmlIdentifier { +// get { +// return isXmlIdentifier; +// } +// set { +// isXmlIdentifier = value; +// } +// } +// +// public string Identifier { +// get { +// return identifier; +// } +// set { +// identifier = value ?? ""; +// } +// } +// +// public XmlMemberAccessExpression(Expression targetObject, XmlAxisType axisType, string identifier, bool isXmlIdentifier) { +// TargetObject = targetObject; +// AxisType = axisType; +// Identifier = identifier; +// IsXmlIdentifier = isXmlIdentifier; +// } +// +// public override object AcceptVisitor(IAstVisitor visitor, object data) { +// return visitor.VisitXmlMemberAccessExpression(this, data); +// } +// +// public override string ToString() { +// return string.Format("[XmlMemberAccessExpression TargetObject={0} AxisType={1} IsXmlIdentifier={2} Iden" + +// "tifier={3}]", TargetObject, AxisType, IsXmlIdentifier, Identifier); +// } +// } +//} diff --git a/ICSharpCode.NRefactory.VB/Ast/GlobalScope/DelegateDeclaration.cs b/ICSharpCode.NRefactory.VB/Ast/GlobalScope/DelegateDeclaration.cs new file mode 100644 index 000000000..bc2d06ca0 --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/GlobalScope/DelegateDeclaration.cs @@ -0,0 +1,52 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + public class DelegateDeclaration : AttributedNode + { + public bool IsSub { get; set; } + + public AstNodeCollection TypeParameters { + get { return GetChildrenByRole(Roles.TypeParameter); } + } + + public Identifier Name { + get { return GetChildByRole(Roles.Identifier); } + set { SetChildByRole(Roles.Identifier, value); } + } + + public AstNodeCollection Parameters { + get { return GetChildrenByRole(Roles.Parameter); } + } + + public AstNodeCollection ReturnTypeAttributes { + get { return GetChildrenByRole(AttributeBlock.ReturnTypeAttributeBlockRole); } + } + + public AstType ReturnType { + get { return GetChildByRole(Roles.Type); } + set { SetChildByRole(Roles.Type, value); } + } + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + var o = other as DelegateDeclaration; + return o != null && + MatchAttributesAndModifiers(o, match) && + IsSub == o.IsSub && + TypeParameters.DoMatch(o.TypeParameters, match) && + Name.DoMatch(o.Name, match) && + Parameters.DoMatch(o.Parameters, match) && + ReturnTypeAttributes.DoMatch(o.ReturnTypeAttributes, match) && + ReturnType.DoMatch(o.ReturnType, match); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitDelegateDeclaration(this, data); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/GlobalScope/EnumDeclaration.cs b/ICSharpCode.NRefactory.VB/Ast/GlobalScope/EnumDeclaration.cs new file mode 100644 index 000000000..49fe3f239 --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/GlobalScope/EnumDeclaration.cs @@ -0,0 +1,44 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; +using System.Collections.Generic; +using System.Linq; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + public class EnumDeclaration : AttributedNode + { + public readonly static Role MemberRole = new Role("Member"); + public readonly static Role UnderlyingTypeRole = new Role("UnderlyingType", AstType.Null); + + public Identifier Name { + get { return GetChildByRole(Roles.Identifier); } + set { SetChildByRole(Roles.Identifier, value); } + } + + public AstType UnderlyingType { + get { return GetChildByRole(UnderlyingTypeRole); } + set { SetChildByRole(UnderlyingTypeRole, value); } + } + + public AstNodeCollection Member { + get { return GetChildrenByRole(MemberRole); } + } + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + var decl = other as EnumDeclaration; + return decl != null && + MatchAttributesAndModifiers(decl, match) && + Name.DoMatch(decl.Name, match) && + UnderlyingType.DoMatch(decl.UnderlyingType, match) && + Member.DoMatch(decl.Member, match); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitEnumDeclaration(this, data); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/GlobalScope/EnumMemberDeclaration.cs b/ICSharpCode.NRefactory.VB/Ast/GlobalScope/EnumMemberDeclaration.cs new file mode 100644 index 000000000..476ec5636 --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/GlobalScope/EnumMemberDeclaration.cs @@ -0,0 +1,39 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; +using System.Collections.Generic; +using System.Linq; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + public class EnumMemberDeclaration : AstNode + { + public AstNodeCollection Attributes { + get { return GetChildrenByRole(AttributeBlock.AttributeBlockRole); } + } + + public Identifier Name { + get { return GetChildByRole(Roles.Identifier); } + set { SetChildByRole(Roles.Identifier, value); } + } + + public Expression Value { + get { return GetChildByRole(Roles.Expression); } + set { SetChildByRole(Roles.Expression, value); } + } + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + var member = other as EnumMemberDeclaration; + return Attributes.DoMatch(member.Attributes, match) && + Name.DoMatch(member.Name, match) && + Value.DoMatch(member.Value, match); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitEnumMemberDeclaration(this, data); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/GlobalScope/ImportsClause.cs b/ICSharpCode.NRefactory.VB/Ast/GlobalScope/ImportsClause.cs new file mode 100644 index 000000000..15730eab0 --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/GlobalScope/ImportsClause.cs @@ -0,0 +1,113 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +using System; +using System.Collections.Generic; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + public abstract class ImportsClause : AstNode + { + public new static readonly ImportsClause Null = new NullImportsClause(); + + class NullImportsClause : ImportsClause + { + public override bool IsNull { + get { return true; } + } + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + return other != null && other.IsNull; + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return default(S); + } + } + } + + public class AliasImportsClause : ImportsClause + { + public Identifier Name { + get { return GetChildByRole(Roles.Identifier); } + set { SetChildByRole(Roles.Identifier, value); } + } + + public AstType Alias { + get { return GetChildByRole(Roles.Type); } + set { SetChildByRole(Roles.Type, value); } + } + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + var clause = other as AliasImportsClause; + return clause != null + && Name.DoMatch(clause.Name, match) + && Alias.DoMatch(clause.Alias, match); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitAliasImportsClause(this, data); + } + + public override string ToString() { + return string.Format("[AliasImportsClause Name={0} Alias={1}]", Name, Alias); + } + } + + public class MemberImportsClause : ImportsClause + { + public AstType Member { + get { return GetChildByRole(Roles.Type); } + set { SetChildByRole(Roles.Type, value); } + } + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + var node = other as MemberImportsClause; + return node != null + && Member.DoMatch(node.Member, match); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitMembersImportsClause(this, data); + } + + public override string ToString() + { + return string.Format("[MemberImportsClause Member={0}]", Member); + } + } + + public class XmlNamespaceImportsClause : ImportsClause + { + public XmlIdentifier Prefix { + get { return GetChildByRole(Roles.XmlIdentifier); } + set { SetChildByRole(Roles.XmlIdentifier, value); } + } + + public XmlLiteralString Namespace { + get { return GetChildByRole(Roles.XmlLiteralString); } + set { SetChildByRole(Roles.XmlLiteralString, value); } + } + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + var clause = other as XmlNamespaceImportsClause; + return clause != null && Namespace.DoMatch(clause.Namespace, match) && Prefix.DoMatch(clause.Prefix, match); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitXmlNamespaceImportsClause(this, data); + } + + public override string ToString() + { + return string.Format("[XmlNamespaceImportsClause Prefix={0}, Namespace={1}]", Prefix, Namespace); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/GlobalScope/ImportsStatement.cs b/ICSharpCode.NRefactory.VB/Ast/GlobalScope/ImportsStatement.cs new file mode 100644 index 000000000..6691b852b --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/GlobalScope/ImportsStatement.cs @@ -0,0 +1,36 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +using System; +using System.Collections.Generic; +using ICSharpCode.NRefactory.PatternMatching; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + public class ImportsStatement : AstNode + { + public static readonly Role ImportsClauseRole = new Role("ImportsClause", ImportsClause.Null); + + public VBTokenNode Imports { + get { return GetChildByRole(Roles.Keyword); } + } + + public AstNodeCollection ImportsClauses { + get { return GetChildrenByRole(ImportsClauseRole); } + } + +// public override string ToString() { +// return string.Format("[ImportsStatement ImportsClauses={0}]", GetCollectionString(ImportsClauses)); +// } + + protected internal override bool DoMatch(AstNode other, Match match) + { + ImportsStatement stmt = other as ImportsStatement; + return stmt != null && stmt.ImportsClauses.DoMatch(ImportsClauses, match); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitImportsStatement(this, data); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/GlobalScope/NamespaceDeclaration.cs b/ICSharpCode.NRefactory.VB/Ast/GlobalScope/NamespaceDeclaration.cs new file mode 100644 index 000000000..b91a753e0 --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/GlobalScope/NamespaceDeclaration.cs @@ -0,0 +1,78 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +using ICSharpCode.NRefactory.PatternMatching; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + /// + /// Namespace Name + /// Members + /// End Namespace + /// + public class NamespaceDeclaration : AstNode + { + public static readonly Role MemberRole = CompilationUnit.MemberRole; + + public string Name { + get { + StringBuilder builder = new StringBuilder(); + foreach (Identifier identifier in GetChildrenByRole (Roles.Identifier)) { + if (builder.Length > 0) + builder.Append ('.'); + builder.Append (identifier.Name); + } + return builder.ToString (); + } + set { + GetChildrenByRole(Roles.Identifier).ReplaceWith(value.Split('.').Select(ident => new Identifier(ident, AstLocation.Empty))); + } + } + + public AstNodeCollection Identifiers { + get { return GetChildrenByRole (Roles.Identifier); } + } + + /// + /// Gets the full namespace name (including any parent namespaces) + /// + public string FullName { + get { + NamespaceDeclaration parentNamespace = Parent as NamespaceDeclaration; + if (parentNamespace != null) + return BuildQualifiedName (parentNamespace.FullName, Name); + return Name; + } + } + + public AstNodeCollection Members { + get { return GetChildrenByRole(MemberRole); } + } + + public static string BuildQualifiedName (string name1, string name2) + { + if (string.IsNullOrEmpty (name1)) + return name2; + if (string.IsNullOrEmpty (name2)) + return name1; + return name1 + "." + name2; + } + + + public override S AcceptVisitor (IAstVisitor visitor, T data) + { + return visitor.VisitNamespaceDeclaration(this, data); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + NamespaceDeclaration o = other as NamespaceDeclaration; + return o != null && MatchString(this.Name, o.Name) && this.Members.DoMatch(o.Members, match); + } + } +}; diff --git a/ICSharpCode.NRefactory.VB/Ast/GlobalScope/OptionStatement.cs b/ICSharpCode.NRefactory.VB/Ast/GlobalScope/OptionStatement.cs new file mode 100644 index 000000000..903439c89 --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/GlobalScope/OptionStatement.cs @@ -0,0 +1,60 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +using System; +using System.Collections.Generic; +using ICSharpCode.NRefactory.PatternMatching; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + public class OptionStatement : AstNode + { + public static readonly Role OptionTypeRole = new Role("OptionType"); + public static readonly Role OptionValueRole = new Role("OptionValue"); + + public VBTokenNode OptionKeyword { + get { return GetChildByRole(Roles.Keyword); } + } + + public VBTokenNode OptionTypeKeyword { + get { return GetChildByRole(OptionTypeRole); } + } + + public VBTokenNode OptionValueKeyword { + get { return GetChildByRole(OptionValueRole); } + } + + public OptionType OptionType { get; set; } + + public OptionValue OptionValue { get; set; } + + protected internal override bool DoMatch(AstNode other, Match match) + { + var stmt = other as OptionStatement; + return stmt != null && stmt.OptionType == this.OptionType + && stmt.OptionValue == this.OptionValue; + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitOptionStatement(this, data); + } + + public override string ToString() { + return string.Format("[OptionStatement OptionType={0} OptionValue={1}]", OptionType, OptionValue); + } + } + + public enum OptionType + { + Explicit, + Strict, + Compare, + Infer + } + + public enum OptionValue + { + On, Off, + Text, Binary + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/GlobalScope/TypeDeclaration.cs b/ICSharpCode.NRefactory.VB/Ast/GlobalScope/TypeDeclaration.cs new file mode 100644 index 000000000..28b669d9c --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/GlobalScope/TypeDeclaration.cs @@ -0,0 +1,58 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; +using System.Collections.Generic; +using System.Linq; +using ICSharpCode.NRefactory.TypeSystem; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + public class TypeDeclaration : AttributedNode + { + public readonly static Role MemberRole = new Role("Member"); + public readonly static Role InheritsTypeRole = new Role("InheritsType", AstType.Null); + public readonly static Role ImplementsTypesRole = new Role("ImplementsTypes", AstType.Null); + + public AstNodeCollection Members { + get { return base.GetChildrenByRole(MemberRole); } + } + + public ClassType ClassType { get; set; } + + public Identifier Name { + get { return GetChildByRole(Roles.Identifier); } + set { SetChildByRole(Roles.Identifier, value); } + } + + public AstNodeCollection TypeParameters { + get { return GetChildrenByRole(Roles.TypeParameter); } + } + + public AstType InheritsType { + get { return GetChildByRole(InheritsTypeRole); } + } + + public AstNodeCollection ImplementsTypes { + get { return GetChildrenByRole(ImplementsTypesRole); } + } + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + TypeDeclaration t = other as TypeDeclaration; + return t != null && + MatchAttributesAndModifiers(t, match) && + Members.DoMatch(t.Members, match) && + ClassType == t.ClassType && + Name.DoMatch(t.Name, match) && + TypeParameters.DoMatch(t.TypeParameters, match) && + InheritsType.DoMatch(t.InheritsType, match) && + ImplementsTypes.DoMatch(t.ImplementsTypes, match); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitTypeDeclaration(this, data); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/INode.cs b/ICSharpCode.NRefactory.VB/Ast/INode.cs deleted file mode 100644 index f64420108..000000000 --- a/ICSharpCode.NRefactory.VB/Ast/INode.cs +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using System; -using System.Collections.Generic; - -namespace ICSharpCode.NRefactory.VB.Ast -{ - public interface INode - { - INode Parent { - get; - set; - } - - List Children { - get; - } - - Location StartLocation { - get; - set; - } - - Location EndLocation { - get; - set; - } - - object UserData { - get; - set; - } - - /// - /// Visits all children - /// - /// The visitor to accept - /// Additional data for the visitor - /// The paremeter - object AcceptChildren(IAstVisitor visitor, object data); - - /// - /// Accept the visitor - /// - /// The visitor to accept - /// Additional data for the visitor - /// The value the visitor returns after the visit - object AcceptVisitor(IAstVisitor visitor, object data); - } -} diff --git a/ICSharpCode.NRefactory.VB/Ast/Identifier.cs b/ICSharpCode.NRefactory.VB/Ast/Identifier.cs new file mode 100644 index 000000000..ea308b7f9 --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/Identifier.cs @@ -0,0 +1,91 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + /// + /// Represents an identifier in VB. + /// + public class Identifier : AstNode + { + public static readonly new Identifier Null = new NullIdentifier (); + class NullIdentifier : Identifier + { + public override bool IsNull { + get { + return true; + } + } + + public override S AcceptVisitor (IAstVisitor visitor, T data) + { + return default (S); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + return other == null || other.IsNull; + } + } + + string name; + + public string Name { + get { return name; } + set { + if (value == null) + throw new ArgumentNullException("value"); + name = value; + } + } + + public TypeCode TypeCharacter { get; set; } + + AstLocation startLocation; + public override AstLocation StartLocation { + get { + return startLocation; + } + } + + public override AstLocation EndLocation { + get { + return new AstLocation (StartLocation.Line, StartLocation.Column + Name.Length); + } + } + + private Identifier() + { + this.name = string.Empty; + } + + public Identifier (string name, AstLocation location) + { + if (name == null) + throw new ArgumentNullException("name"); + this.Name = name; + this.startLocation = location; + } + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + var node = other as Identifier; + return node != null + && MatchString(node.name, name) + && node.TypeCharacter == TypeCharacter; + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitIdentifier(this, data); + } + + public override string ToString() + { + return string.Format("[Identifier Name={0}, StartLocation={1}, TypeCharacter{4}]", + name, startLocation, TypeCharacter); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/Statements/BlockStatement.cs b/ICSharpCode.NRefactory.VB/Ast/Statements/BlockStatement.cs new file mode 100644 index 000000000..73610fe70 --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/Statements/BlockStatement.cs @@ -0,0 +1,125 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; +using System.Collections.Generic; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + /// + /// { Statements } + /// + public class BlockStatement : Statement, IEnumerable + { + public static readonly Role StatementRole = new Role("Statement", Statement.Null); + + #region Null + public static readonly new BlockStatement Null = new NullBlockStatement(); + sealed class NullBlockStatement : BlockStatement + { + public override bool IsNull { + get { + return true; + } + } + + public override S AcceptVisitor (IAstVisitor visitor, T data) + { + return default(S); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + return other == null || other.IsNull; + } + } + #endregion + + #region PatternPlaceholder + public static implicit operator BlockStatement(PatternMatching.Pattern pattern) + { + return pattern != null ? new PatternPlaceholder(pattern) : null; + } + + sealed class PatternPlaceholder : BlockStatement, PatternMatching.INode + { + readonly PatternMatching.Pattern child; + + public PatternPlaceholder(PatternMatching.Pattern child) + { + this.child = child; + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitPatternPlaceholder(this, child, data); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + return child.DoMatch(other, match); + } + + bool PatternMatching.INode.DoMatchCollection(Role role, PatternMatching.INode pos, PatternMatching.Match match, PatternMatching.BacktrackingInfo backtrackingInfo) + { + return child.DoMatchCollection(role, pos, match, backtrackingInfo); + } + } + #endregion + + public AstNodeCollection Statements { + get { return GetChildrenByRole (StatementRole); } + } + + public override S AcceptVisitor (IAstVisitor visitor, T data) + { + return visitor.VisitBlockStatement (this, data); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + BlockStatement o = other as BlockStatement; + return o != null && !o.IsNull && this.Statements.DoMatch(o.Statements, match); + } + + #region Builder methods + public void Add(Statement statement) + { + AddChild(statement, StatementRole); + } + + // TODO : uncomment + +// public void Add(Expression expression) +// { +// AddChild(new ExpressionStatement { Expression = expression }, StatementRole); +// } +// + public void AddRange(IEnumerable statements) + { + foreach (Statement st in statements) + AddChild(st, StatementRole); + } + +// public void AddAssignment(Expression left, Expression right) +// { +// Add(new AssignmentExpression { Left = left, Operator = AssignmentOperatorType.Assign, Right = right }); +// } +// +// public void AddReturnStatement(Expression expression) +// { +// Add(new ReturnStatement { Expression = expression }); +// } + #endregion + + IEnumerator IEnumerable.GetEnumerator() + { + return this.Statements.GetEnumerator(); + } + + System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() + { + return this.Statements.GetEnumerator(); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/Statements/Statement.cs b/ICSharpCode.NRefactory.VB/Ast/Statements/Statement.cs new file mode 100644 index 000000000..c20407051 --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/Statements/Statement.cs @@ -0,0 +1,132 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) + +using System; +using System.IO; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + /// + /// Base class for statements. + /// + /// + /// This class is useful even though it doesn't provide any additional functionality: + /// It can be used to communicate more information in APIs, e.g. "this subnode will always be a statement" + /// + public abstract class Statement : AstNode + { + #region Null + public new static readonly Statement Null = new NullStatement (); + + sealed class NullStatement : Statement + { + public override bool IsNull { + get { + return true; + } + } + + public override S AcceptVisitor (IAstVisitor visitor, T data) + { + return default (S); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + return other == null || other.IsNull; + } + } + #endregion + + #region PatternPlaceholder + public static implicit operator Statement(PatternMatching.Pattern pattern) + { + return pattern != null ? new PatternPlaceholder(pattern) : null; + } + + sealed class PatternPlaceholder : Statement, PatternMatching.INode + { + readonly PatternMatching.Pattern child; + + public PatternPlaceholder(PatternMatching.Pattern child) + { + this.child = child; + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitPatternPlaceholder(this, child, data); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + return child.DoMatch(other, match); + } + + bool PatternMatching.INode.DoMatchCollection(Role role, PatternMatching.INode pos, PatternMatching.Match match, PatternMatching.BacktrackingInfo backtrackingInfo) + { + return child.DoMatchCollection(role, pos, match, backtrackingInfo); + } + } + #endregion + + /// + /// Gets the previous statement within the current block. + /// This is usually equivalent to , but will skip any non-statements (e.g. comments) + /// + public Statement PreviousStatement { + get { + AstNode node = this; + while ((node = node.PrevSibling) != null) { + Statement stmt = node as Statement; + if (stmt != null) + return stmt; + } + return null; + } + } + + /// + /// Gets the next statement within the current block. + /// This is usually equivalent to , but will skip any non-statements (e.g. comments) + /// + public Statement NextStatement { + get { + AstNode node = this; + while ((node = node.NextSibling) != null) { + Statement stmt = node as Statement; + if (stmt != null) + return stmt; + } + return null; + } + } + + public new Statement Clone() + { + return (Statement)base.Clone(); + } + + public Statement ReplaceWith(Func replaceFunction) + { + if (replaceFunction == null) + throw new ArgumentNullException("replaceFunction"); + return (Statement)base.ReplaceWith(node => replaceFunction((Statement)node)); + } + + // Make debugging easier by giving Statements a ToString() implementation + public override string ToString() + { +// if (IsNull) +// return "Null"; +// StringWriter w = new StringWriter(); +// AcceptVisitor(new OutputVisitor(w, new CSharpFormattingOptions()), null); +// string text = w.ToString().TrimEnd().Replace("\t", "").Replace(w.NewLine, " "); +// if (text.Length > 100) +// return text.Substring(0, 97) + "..."; +// else +// return text; + throw new NotImplementedException(); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/TypeName/AstType.cs b/ICSharpCode.NRefactory.VB/Ast/TypeName/AstType.cs new file mode 100644 index 000000000..13ba3ee97 --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/TypeName/AstType.cs @@ -0,0 +1,145 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +using System; +using System.Collections.Generic; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + /// + /// A type reference in the VB AST. + /// + public abstract class AstType : AstNode + { + #region Null + public new static readonly AstType Null = new NullAstType(); + + sealed class NullAstType : AstType + { + public override bool IsNull { + get { + return true; + } + } + + public override S AcceptVisitor (IAstVisitor visitor, T data) + { + return default (S); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + return other == null || other.IsNull; + } + } + #endregion + + #region PatternPlaceholder + public static implicit operator AstType(PatternMatching.Pattern pattern) + { + return pattern != null ? new PatternPlaceholder(pattern) : null; + } + + sealed class PatternPlaceholder : AstType, PatternMatching.INode + { + readonly PatternMatching.Pattern child; + + public PatternPlaceholder(PatternMatching.Pattern child) + { + this.child = child; + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitPatternPlaceholder(this, child, data); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + return child.DoMatch(other, match); + } + + bool PatternMatching.INode.DoMatchCollection(Role role, PatternMatching.INode pos, PatternMatching.Match match, PatternMatching.BacktrackingInfo backtrackingInfo) + { + return child.DoMatchCollection(role, pos, match, backtrackingInfo); + } + } + #endregion + + public virtual AstType MakeArrayType(int rank = 1) + { + return new ComposedType { BaseType = this }.MakeArrayType(rank); + } + + // TODO : reimplement this +// /// +// /// Builds an expression that can be used to access a static member on this type. +// /// +// public MemberReferenceExpression Member(string memberName) +// { +// return new TypeReferenceExpression { Type = this }.Member(memberName); +// } +// +// /// +// /// Builds an invocation expression using this type as target. +// /// +// public InvocationExpression Invoke(string methodName, IEnumerable arguments) +// { +// return new TypeReferenceExpression { Type = this }.Invoke(methodName, arguments); +// } +// +// /// +// /// Builds an invocation expression using this type as target. +// /// +// public InvocationExpression Invoke(string methodName, params Expression[] arguments) +// { +// return new TypeReferenceExpression { Type = this }.Invoke(methodName, arguments); +// } +// +// /// +// /// Builds an invocation expression using this type as target. +// /// +// public InvocationExpression Invoke(string methodName, IEnumerable typeArguments, IEnumerable arguments) +// { +// return new TypeReferenceExpression { Type = this }.Invoke(methodName, typeArguments, arguments); +// } + + public static AstType Create(Type type) + { + switch (Type.GetTypeCode(type)) { + case TypeCode.Object: + return new PrimitiveType("Object"); + case TypeCode.Boolean: + return new PrimitiveType("Boolean"); + case TypeCode.Char: + return new PrimitiveType("Char"); + case TypeCode.SByte: + return new PrimitiveType("SByte"); + case TypeCode.Byte: + return new PrimitiveType("Byte"); + case TypeCode.Int16: + return new PrimitiveType("Short"); + case TypeCode.UInt16: + return new PrimitiveType("UShort"); + case TypeCode.Int32: + return new PrimitiveType("Integer"); + case TypeCode.UInt32: + return new PrimitiveType("UInteger"); + case TypeCode.Int64: + return new PrimitiveType("Long"); + case TypeCode.UInt64: + return new PrimitiveType("ULong"); + case TypeCode.Single: + return new PrimitiveType("Single"); + case TypeCode.Double: + return new PrimitiveType("Double"); + case TypeCode.Decimal: + return new PrimitiveType("Decimal"); + case TypeCode.String: + return new PrimitiveType("String"); + case TypeCode.DateTime: + return new PrimitiveType("Date"); + } + return new SimpleType(type.FullName); // TODO: implement this correctly + } + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/TypeName/ComposedType.cs b/ICSharpCode.NRefactory.VB/Ast/TypeName/ComposedType.cs new file mode 100644 index 000000000..e214a7e4b --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/TypeName/ComposedType.cs @@ -0,0 +1,119 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + public class ComposedType : AstType + { + public static readonly Role NullableRole = new Role("Nullable", VBTokenNode.Null); + public static readonly Role ArraySpecifierRole = new Role("ArraySpecifier"); + + public AstType BaseType { + get { return GetChildByRole(Roles.Type); } + set { SetChildByRole(Roles.Type, value); } + } + + public bool HasNullableSpecifier { + get { + return !GetChildByRole(NullableRole).IsNull; + } + set { + SetChildByRole(NullableRole, value ? new VBTokenNode(AstLocation.Empty, 1) : null); + } + } + + public AstNodeCollection ArraySpecifiers { + get { return GetChildrenByRole (ArraySpecifierRole); } + } + + public override S AcceptVisitor (IAstVisitor visitor, T data) + { + return visitor.VisitComposedType (this, data); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + ComposedType o = other as ComposedType; + return o != null && this.HasNullableSpecifier == o.HasNullableSpecifier && this.ArraySpecifiers.DoMatch(o.ArraySpecifiers, match); + } + + public override string ToString() + { + StringBuilder b = new StringBuilder(); + b.Append(this.BaseType.ToString()); + if (this.HasNullableSpecifier) + b.Append('?'); + foreach (var arraySpecifier in this.ArraySpecifiers) { + b.Append('('); + b.Append(',', arraySpecifier.Dimensions - 1); + b.Append(')'); + } + return b.ToString(); + } + + public override AstType MakeArrayType(int dimensions) + { + InsertChildBefore(this.ArraySpecifiers.FirstOrDefault(), new ArraySpecifier(dimensions), ArraySpecifierRole); + return this; + } + } + + /// + /// [,,,] + /// + public class ArraySpecifier : AstNode + { + public ArraySpecifier() + { + } + + public ArraySpecifier(int dimensions) + { + this.Dimensions = dimensions; + } + + public VBTokenNode LParToken { + get { return GetChildByRole (Roles.LPar); } + } + + public int Dimensions { + get { return 1 + GetChildrenByRole(Roles.Comma).Count(); } + set { + int d = this.Dimensions; + while (d > value) { + GetChildByRole(Roles.Comma).Remove(); + d--; + } + while (d < value) { + InsertChildBefore(GetChildByRole(Roles.Comma), new VBTokenNode(AstLocation.Empty, 1), Roles.Comma); + d++; + } + } + } + + public VBTokenNode RParToken { + get { return GetChildByRole (Roles.LPar); } + } + + public override S AcceptVisitor (IAstVisitor visitor, T data) + { + return visitor.VisitArraySpecifier(this, data); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + ArraySpecifier o = other as ArraySpecifier; + return o != null && this.Dimensions == o.Dimensions; + } + + public override string ToString() + { + return "(" + new string(',', this.Dimensions - 1) + ")"; + } + } +} + diff --git a/ICSharpCode.NRefactory.VB/Ast/TypeName/PrimitiveType.cs b/ICSharpCode.NRefactory.VB/Ast/TypeName/PrimitiveType.cs new file mode 100644 index 000000000..8d6badc8f --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/TypeName/PrimitiveType.cs @@ -0,0 +1,57 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +using System; +using System.Collections.Generic; +using System.Linq; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + public class PrimitiveType : AstType + { + public string Keyword { get; set; } + public AstLocation Location { get; set; } + + public PrimitiveType() + { + } + + public PrimitiveType(string keyword) + { + this.Keyword = keyword; + } + + public PrimitiveType(string keyword, AstLocation location) + { + this.Keyword = keyword; + this.Location = location; + } + + public override AstLocation StartLocation { + get { + return Location; + } + } + public override AstLocation EndLocation { + get { + return new AstLocation (Location.Line, Location.Column + (Keyword != null ? Keyword.Length : 0)); + } + } + + public override S AcceptVisitor (IAstVisitor visitor, T data) + { + return visitor.VisitPrimitiveType(this, data); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + PrimitiveType o = other as PrimitiveType; + return o != null && MatchString(this.Keyword, o.Keyword); + } + + public override string ToString() + { + return Keyword ?? base.ToString(); + } + } +} + diff --git a/ICSharpCode.NRefactory.VB/Ast/TypeName/QualifiedType.cs b/ICSharpCode.NRefactory.VB/Ast/TypeName/QualifiedType.cs new file mode 100644 index 000000000..2dbb28516 --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/TypeName/QualifiedType.cs @@ -0,0 +1,66 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; +using System.Linq; +using System.Text; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + /// + /// Description of QualifiedType. + /// + public class QualifiedType : AstType + { + public static readonly Role TargetRole = new Role("Target", AstType.Null); + + public AstType Target { + get { return GetChildByRole(TargetRole); } + set { SetChildByRole(TargetRole, value); } + } + + public string Name { + get { + return GetChildByRole (Roles.Identifier).Name; + } + set { + SetChildByRole (Roles.Identifier, new Identifier(value, AstLocation.Empty)); + } + } + + public QualifiedType(AstType target, Identifier name) + { + Target = target; + SetChildByRole(Roles.Identifier, name); + } + + public AstNodeCollection TypeArguments { + get { return GetChildrenByRole (Roles.TypeArgument); } + } + + public override S AcceptVisitor (IAstVisitor visitor, T data) + { + return visitor.VisitQualifiedType(this, data); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + var o = other as QualifiedType; + return o != null && MatchString(this.Name, o.Name) && this.Target.DoMatch(o.Target, match); + } + + public override string ToString() + { + StringBuilder b = new StringBuilder(); + b.Append(this.Target); + b.Append('.'); + b.Append(this.Name); + if (this.TypeArguments.Any()) { + b.Append('('); + b.Append(string.Join(", ", this.TypeArguments)); + b.Append(')'); + } + return b.ToString(); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/TypeName/SimpleType.cs b/ICSharpCode.NRefactory.VB/Ast/TypeName/SimpleType.cs new file mode 100644 index 000000000..6ddc198d7 --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/TypeName/SimpleType.cs @@ -0,0 +1,87 @@ +// +// FullTypeName.cs +// +// Author: +// Mike Krüger +// +// Copyright (c) 2010 Novell, Inc (http://www.novell.com) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + public class SimpleType : AstType + { + public SimpleType() + { + } + + public SimpleType(string identifier) + { + this.Identifier = identifier; + } + + public SimpleType(string identifier, AstLocation location) + { + SetChildByRole (Roles.Identifier, new Identifier(identifier, location)); + } + + public string Identifier { + get { + return GetChildByRole (Roles.Identifier).Name; + } + set { + SetChildByRole (Roles.Identifier, new Identifier(value, AstLocation.Empty)); + } + } + + public AstNodeCollection TypeArguments { + get { return GetChildrenByRole (Roles.TypeArgument); } + } + + public override S AcceptVisitor (IAstVisitor visitor, T data) + { + return visitor.VisitSimpleType(this, data); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + SimpleType o = other as SimpleType; + return o != null && MatchString(this.Identifier, o.Identifier) && this.TypeArguments.DoMatch(o.TypeArguments, match); + } + + public override string ToString() + { + StringBuilder b = new StringBuilder(this.Identifier); + if (this.TypeArguments.Any()) { + b.Append('('); + b.Append("Of "); + b.Append(string.Join(", ", this.TypeArguments)); + b.Append(')'); + } + return b.ToString(); + } + } +} + diff --git a/ICSharpCode.NRefactory.VB/Ast/TypeReference.cs b/ICSharpCode.NRefactory.VB/Ast/TypeReference.cs deleted file mode 100644 index a0ab71390..000000000 --- a/ICSharpCode.NRefactory.VB/Ast/TypeReference.cs +++ /dev/null @@ -1,427 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Globalization; -using System.Runtime.InteropServices; -using System.Text; - -namespace ICSharpCode.NRefactory.VB.Ast -{ - public class TypeReference : AbstractNode, INullable, ICloneable - { - public static readonly TypeReference StructConstraint = new TypeReference("constraint: struct"); - public static readonly TypeReference ClassConstraint = new TypeReference("constraint: class"); - public static readonly TypeReference NewConstraint = new TypeReference("constraint: new"); - - string type = ""; - int pointerNestingLevel; - int[] rankSpecifier; - List genericTypes = new List(); - - #region Static primitive type list - static Dictionary types = new Dictionary(); - static Dictionary vbtypes = new Dictionary(StringComparer.InvariantCultureIgnoreCase); - static Dictionary typesReverse = new Dictionary(); - static Dictionary vbtypesReverse = new Dictionary(); - - static TypeReference() - { - // C# types - types.Add("bool", "System.Boolean"); - types.Add("byte", "System.Byte"); - types.Add("char", "System.Char"); - types.Add("decimal", "System.Decimal"); - types.Add("double", "System.Double"); - types.Add("float", "System.Single"); - types.Add("int", "System.Int32"); - types.Add("long", "System.Int64"); - types.Add("object", "System.Object"); - types.Add("sbyte", "System.SByte"); - types.Add("short", "System.Int16"); - types.Add("string", "System.String"); - types.Add("uint", "System.UInt32"); - types.Add("ulong", "System.UInt64"); - types.Add("ushort", "System.UInt16"); - types.Add("void", "System.Void"); - - // VB.NET types - vbtypes.Add("Boolean", "System.Boolean"); - vbtypes.Add("Byte", "System.Byte"); - vbtypes.Add("SByte", "System.SByte"); - vbtypes.Add("Date", "System.DateTime"); - vbtypes.Add("Char", "System.Char"); - vbtypes.Add("Decimal", "System.Decimal"); - vbtypes.Add("Double", "System.Double"); - vbtypes.Add("Single", "System.Single"); - vbtypes.Add("Integer", "System.Int32"); - vbtypes.Add("Long", "System.Int64"); - vbtypes.Add("UInteger","System.UInt32"); - vbtypes.Add("ULong", "System.UInt64"); - vbtypes.Add("Object", "System.Object"); - vbtypes.Add("Short", "System.Int16"); - vbtypes.Add("UShort", "System.UInt16"); - vbtypes.Add("String", "System.String"); - - foreach (KeyValuePair pair in types) { - typesReverse.Add(pair.Value, pair.Key); - } - foreach (KeyValuePair pair in vbtypes) { - vbtypesReverse.Add(pair.Value, pair.Key); - } - } - - /// - /// Gets a shortname=>full name dictionary of C# types. - /// - public static IDictionary PrimitiveTypesCSharp { - get { return types; } - } - - /// - /// Gets a shortname=>full name dictionary of VB types. - /// - public static IDictionary PrimitiveTypesVB { - get { return vbtypes; } - } - - /// - /// Gets a full name=>shortname dictionary of C# types. - /// - public static IDictionary PrimitiveTypesCSharpReverse { - get { return typesReverse; } - } - - /// - /// Gets a full name=>shortname dictionary of VB types. - /// - public static IDictionary PrimitiveTypesVBReverse { - get { return vbtypesReverse; } - } - - - static string GetSystemType(string type) - { - if (types == null) return type; - - string systemType; - if (types.TryGetValue(type, out systemType)) { - return systemType; - } - if (vbtypes.TryGetValue(type, out systemType)) { - return systemType; - } - return type; - } - #endregion - - object ICloneable.Clone() - { - return this.Clone(); - } - - public virtual TypeReference Clone() - { - TypeReference c = new TypeReference(type); - CopyFields(this, c); - return c; - } - - /// - /// Copies the pointerNestingLevel, RankSpecifier, GenericTypes and IsGlobal flag - /// from to . - /// - /// - /// If already contains generics, the new generics are appended to the list. - /// - 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; - } - - public string Type { - get { - return type; - } - set { - Debug.Assert(value != null); - type = value ?? "?"; - } - } - - /// - /// 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. - /// - 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; - } - } - - public int PointerNestingLevel { - get { - return pointerNestingLevel; - } - set { - Debug.Assert(this.IsNull == false); - pointerNestingLevel = value; - } - } - - /// - /// The rank of the array type. - /// For "object[]", this is { 0 }; for "object[,]", it is {1}. - /// For "object[,][,,][]", it is {1, 2, 0}. - /// For non-array types, this property is null or {}. - /// - public int[] RankSpecifier { - get { - return rankSpecifier; - } - set { - Debug.Assert(this.IsNull == false); - rankSpecifier = value; - } - } - - public List GenericTypes { - get { - return genericTypes; - } - } - - public bool IsArrayType { - get { - return rankSpecifier != null && rankSpecifier.Length > 0; - } - } - - public static TypeReference CheckNull(TypeReference typeReference) - { - return typeReference ?? NullTypeReference.Instance; - } - - public static TypeReference Null { - get { - return NullTypeReference.Instance; - } - } - - public virtual bool IsNull { - get { - return false; - } - } - - /// - /// Gets/Sets if the type reference had a "global::" prefix. - /// - public bool IsGlobal { - get; set; - } - - /// - /// Gets/Sets if the type reference was using a language keyword. - /// - public bool IsKeyword { - get; set; - } - - public TypeReference(string type) - { - this.Type = type; - } - - public TypeReference(string type, bool isKeyword) - { - this.Type = type; - this.IsKeyword = isKeyword; - } - - public TypeReference(string type, List genericTypes) : this(type) - { - if (genericTypes != null) { - this.genericTypes = genericTypes; - } - } - - public TypeReference(string type, int[] rankSpecifier) : this(type, 0, rankSpecifier) - { - } - - public TypeReference(string type, int pointerNestingLevel, int[] rankSpecifier) : this(type, pointerNestingLevel, rankSpecifier, null) - { - } - - public TypeReference(string type, int pointerNestingLevel, int[] rankSpecifier, List genericTypes) - { - Debug.Assert(type != null); - this.type = type; - this.pointerNestingLevel = pointerNestingLevel; - this.rankSpecifier = rankSpecifier; - if (genericTypes != null) { - this.genericTypes = genericTypes; - } - } - - protected TypeReference() - {} - - public override object AcceptVisitor(IAstVisitor visitor, object data) - { - return visitor.VisitTypeReference(this, data); - } - - public override string ToString() - { - StringBuilder b = new StringBuilder(type); - if (genericTypes != null && genericTypes.Count > 0) { - b.Append('<'); - for (int i = 0; i < genericTypes.Count; i++) { - if (i > 0) b.Append(','); - b.Append(genericTypes[i].ToString()); - } - b.Append('>'); - } - if (pointerNestingLevel > 0) { - b.Append('*', pointerNestingLevel); - } - if (IsArrayType) { - foreach (int rank in rankSpecifier) { - b.Append('['); - if (rank < 0) - b.Append('`', -rank); - else - b.Append(',', rank); - b.Append(']'); - } - } - return b.ToString(); - } - - 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; - } - } - - internal sealed class NullTypeReference : TypeReference - { - public static readonly NullTypeReference Instance = new NullTypeReference(); - public override bool IsNull { - get { - return true; - } - } - public override TypeReference Clone() - { - return this; - } - public override object AcceptVisitor(IAstVisitor visitor, object data) - { - return null; - } - - public override string ToString() - { - return String.Format("[NullTypeReference]"); - } - } - - /// - /// We need this special type reference for cases like - /// OuterClass(Of T1).InnerClass(Of T2) (in expression or type context) - /// or Dictionary(Of String, NamespaceStruct).KeyCollection (in type context, otherwise it's a - /// MemberReferenceExpression) - /// - public class InnerClassTypeReference: TypeReference - { - TypeReference baseType; - - public TypeReference BaseType { - get { return baseType; } - set { baseType = value; } - } - - public override TypeReference Clone() - { - InnerClassTypeReference c = new InnerClassTypeReference(baseType.Clone(), Type, new List()); - CopyFields(this, c); - return c; - } - - public InnerClassTypeReference(TypeReference outerClass, string innerType, List innerGenericTypes) - : base(innerType, innerGenericTypes) - { - this.baseType = outerClass; - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) - { - return visitor.VisitInnerClassTypeReference(this, data); - } - - /// - /// Creates a type reference where all type parameters are specified for the innermost class. - /// Namespace.OuterClass(of string).InnerClass(of integer).InnerInnerClass - /// becomes Namespace.OuterClass.InnerClass.InnerInnerClass(of string, integer) - /// - public TypeReference CombineToNormalTypeReference() - { - TypeReference tr = (baseType is InnerClassTypeReference) - ? ((InnerClassTypeReference)baseType).CombineToNormalTypeReference() - : baseType.Clone(); - CopyFields(this, tr); - tr.Type += "." + Type; - return tr; - } - - public override string ToString() - { - return baseType.ToString() + "+" + base.ToString(); - } - } -} diff --git a/ICSharpCode.NRefactory.VB/Ast/VBModifierToken.cs b/ICSharpCode.NRefactory.VB/Ast/VBModifierToken.cs new file mode 100644 index 000000000..05a22acc4 --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/VBModifierToken.cs @@ -0,0 +1,125 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; +using System.Collections.Generic; +using System.Linq; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + /// + /// Description of VBModifierToken. + /// + public class VBModifierToken : VBTokenNode + { + Modifiers modifier; + + public Modifiers Modifier { + get { return modifier; } + set { + for (int i = 0; i < lengthTable.Count; i++) { + if (lengthTable[i].Key == value) { + this.modifier = value; + this.tokenLength = lengthTable[i].Value; + return; + } + } + throw new ArgumentException ("Modifier " + value + " is invalid."); + } + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + VBModifierToken o = other as VBModifierToken; + return o != null && this.modifier == o.modifier; + } + + // Not worth using a dictionary for such few elements. + // This table is sorted in the order that modifiers should be output when generating code. + static readonly List> lengthTable = new List> () { + new KeyValuePair(Modifiers.Public, "Public".Length), + new KeyValuePair(Modifiers.Protected, "Protected".Length), + new KeyValuePair(Modifiers.Private, "Private".Length), + new KeyValuePair(Modifiers.Friend, "Friend".Length), + new KeyValuePair(Modifiers.MustInherit, "MustInherit".Length), + new KeyValuePair(Modifiers.MustOverride, "MustOverride".Length), + new KeyValuePair(Modifiers.Overridable, "Overridable".Length), + new KeyValuePair(Modifiers.NotInheritable, "NotInheritable".Length), + new KeyValuePair(Modifiers.NotOverridable, "NotOverridable".Length), + new KeyValuePair(Modifiers.Const, "Const".Length), + new KeyValuePair(Modifiers.Shared, "Shared".Length), + new KeyValuePair(Modifiers.Static, "Static".Length), + new KeyValuePair(Modifiers.Override, "Override".Length), + new KeyValuePair(Modifiers.ReadOnly, "ReadOnly".Length), + new KeyValuePair(Modifiers.WriteOnly, "WriteOnly".Length), + new KeyValuePair(Modifiers.Shadows, "Shadows".Length), + new KeyValuePair(Modifiers.Partial, "Partial".Length), + new KeyValuePair(Modifiers.Overloads, "Overloads".Length), + new KeyValuePair(Modifiers.WithEvents, "WithEvents".Length), + new KeyValuePair(Modifiers.Default, "Default".Length), + new KeyValuePair(Modifiers.Dim, "Dim".Length), + + // even though it's used for patterns only, it needs to be in this table to be usable in the AST + new KeyValuePair(Modifiers.Any, "Any".Length) + }; + + public static IEnumerable AllModifiers { + get { return lengthTable.Select(p => p.Key); } + } + + public VBModifierToken(AstLocation location, Modifiers modifier) : base (location, 0) + { + this.Modifier = modifier; + } + + public static string GetModifierName(Modifiers modifier) + { + switch (modifier) { + case Modifiers.Private: + return "Private"; + case Modifiers.Friend: + return "Friend"; + case Modifiers.Protected: + return "Protected"; + case Modifiers.Public: + return "Public"; + case Modifiers.MustInherit: + return "MustInherit"; + case Modifiers.MustOverride: + return "MustOverride"; + case Modifiers.Overridable: + return "Overridable"; + case Modifiers.NotInheritable: + return "NotInheritable"; + case Modifiers.NotOverridable: + return "NotOverridable"; + case Modifiers.Const: + return "Const"; + case Modifiers.Shared: + return "Shared"; + case Modifiers.Static: + return "Static"; + case Modifiers.Override: + return "Override"; + case Modifiers.ReadOnly: + return "ReadOnly"; + case Modifiers.Shadows: + return "Shadows"; + case Modifiers.Partial: + return "Partial"; + case Modifiers.Overloads: + return "Overloads"; + case Modifiers.WithEvents: + return "WithEvents"; + case Modifiers.Default: + return "Default"; + case Modifiers.Dim: + return "Dim"; + case Modifiers.WriteOnly: + return "WriteOnly"; + default: + throw new NotSupportedException("Invalid value for Modifiers"); + } + } + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/VBTokenNode.cs b/ICSharpCode.NRefactory.VB/Ast/VBTokenNode.cs new file mode 100644 index 000000000..225484e67 --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/VBTokenNode.cs @@ -0,0 +1,87 @@ +/* + * Created by SharpDevelop. + * User: Siegfried + * Date: 11.04.2011 + * Time: 20:44 + * + * To change this template use Tools | Options | Coding | Edit Standard Headers. + */ +using System; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + /// + /// Description of VBTokenNode. + /// + public class VBTokenNode : AstNode + { + public static new readonly VBTokenNode Null = new NullVBTokenNode(); + + class NullVBTokenNode : VBTokenNode + { + public override bool IsNull { + get { + return true; + } + } + + public NullVBTokenNode() : base (AstLocation.Empty, 0) + { + } + + public override S AcceptVisitor (IAstVisitor visitor, T data) + { + return default (S); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + return other == null || other.IsNull; + } + } + + AstLocation startLocation; + public override AstLocation StartLocation { + get { + return startLocation; + } + } + + protected int tokenLength = -1; + + AstLocation endLocation; + public override AstLocation EndLocation { + get { + return tokenLength < 0 ? endLocation : new AstLocation(startLocation.Line, startLocation.Column + tokenLength); + } + } + + public VBTokenNode(AstLocation location, int tokenLength) + { + this.startLocation = location; + this.tokenLength = tokenLength; + } + + public VBTokenNode(AstLocation startLocation, AstLocation endLocation) + { + this.startLocation = startLocation; + this.endLocation = endLocation; + } + + public override S AcceptVisitor (IAstVisitor visitor, T data) + { + return visitor.VisitVBTokenNode(this, data); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + var node = other as VBTokenNode; + return node != null && !node.IsNull; + } + + public override string ToString () + { + return string.Format ("[VBTokenNode: StartLocation={0}, EndLocation={1}, Role={2}]", StartLocation, EndLocation, Role); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/AstBuilder/ExpressionBuilder.cs b/ICSharpCode.NRefactory.VB/AstBuilder/ExpressionBuilder.cs index c2992e19c..402dc449f 100644 --- a/ICSharpCode.NRefactory.VB/AstBuilder/ExpressionBuilder.cs +++ b/ICSharpCode.NRefactory.VB/AstBuilder/ExpressionBuilder.cs @@ -11,10 +11,10 @@ namespace ICSharpCode.NRefactory.VB.AstBuilder /// Extension methods for NRefactory.Dom.Expression. /// public static class ExpressionBuilder - { - public static IdentifierExpression Identifier(string identifier) + {/* + public static SimpleNameExpression Identifier(string identifier) { - return new IdentifierExpression(identifier); + return new SimpleNameExpression(identifier); } public static MemberReferenceExpression Member(this Expression targetObject, string memberName) @@ -87,6 +87,6 @@ namespace ICSharpCode.NRefactory.VB.AstBuilder public static BinaryOperatorExpression Operator(this Expression left, BinaryOperatorType op, Expression right) { return new BinaryOperatorExpression(left, op, right); - } + }*/ } } diff --git a/ICSharpCode.NRefactory.VB/AstBuilder/StatementBuilder.cs b/ICSharpCode.NRefactory.VB/AstBuilder/StatementBuilder.cs index 807dfe8ab..1f3541f15 100644 --- a/ICSharpCode.NRefactory.VB/AstBuilder/StatementBuilder.cs +++ b/ICSharpCode.NRefactory.VB/AstBuilder/StatementBuilder.cs @@ -10,46 +10,46 @@ namespace ICSharpCode.NRefactory.VB.AstBuilder /// /// Extension methods for NRefactory.Dom.Expression. /// - public static class StatementBuilder - { - public static void AddStatement(this BlockStatement block, Statement statement) - { - if (block == null) - throw new ArgumentNullException("block"); - if (statement == null) - throw new ArgumentNullException("statement"); - block.AddChild(statement); - statement.Parent = block; - } - - public static void AddStatement(this BlockStatement block, Expression expressionStatement) - { - if (expressionStatement == null) - throw new ArgumentNullException("expressionStatement"); - AddStatement(block, new ExpressionStatement(expressionStatement)); - } - - public static void Throw(this BlockStatement block, Expression expression) - { - if (expression == null) - throw new ArgumentNullException("expression"); - AddStatement(block, new ThrowStatement(expression)); - } - - public static void Return(this BlockStatement block, Expression expression) - { - if (expression == null) - throw new ArgumentNullException("expression"); - AddStatement(block, new ReturnStatement(expression)); - } - - public static void Assign(this BlockStatement block, Expression left, Expression right) - { - if (left == null) - throw new ArgumentNullException("left"); - if (right == null) - throw new ArgumentNullException("right"); - AddStatement(block, new AssignmentExpression(left, AssignmentOperatorType.Assign, right)); - } - } +// public static class StatementBuilder +// { +// public static void AddStatement(this BlockStatement block, Statement statement) +// { +// if (block == null) +// throw new ArgumentNullException("block"); +// if (statement == null) +// throw new ArgumentNullException("statement"); +// block.AddChild(statement); +// statement.Parent = block; +// } +// +// public static void AddStatement(this BlockStatement block, Expression expressionStatement) +// { +// if (expressionStatement == null) +// throw new ArgumentNullException("expressionStatement"); +// AddStatement(block, new ExpressionStatement(expressionStatement)); +// } +// +// public static void Throw(this BlockStatement block, Expression expression) +// { +// if (expression == null) +// throw new ArgumentNullException("expression"); +// AddStatement(block, new ThrowStatement(expression)); +// } +// +// public static void Return(this BlockStatement block, Expression expression) +// { +// if (expression == null) +// throw new ArgumentNullException("expression"); +// AddStatement(block, new ReturnStatement(expression)); +// } +// +// public static void Assign(this BlockStatement block, Expression left, Expression right) +// { +// if (left == null) +// throw new ArgumentNullException("left"); +// if (right == null) +// throw new ArgumentNullException("right"); +// AddStatement(block, new AssignmentExpression(left, AssignmentOperatorType.Assign, right)); +// } +// } } diff --git a/ICSharpCode.NRefactory.VB/EnvironmentInformationProvider.cs b/ICSharpCode.NRefactory.VB/EnvironmentInformationProvider.cs deleted file mode 100644 index df393e9dc..000000000 --- a/ICSharpCode.NRefactory.VB/EnvironmentInformationProvider.cs +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using System; - -namespace ICSharpCode.NRefactory.VB -{ - public interface IEnvironmentInformationProvider - { - bool HasField(string reflectionTypeName, int typeParameterCount, string fieldName); - } - - sealed class DummyEnvironmentInformationProvider : IEnvironmentInformationProvider - { - internal static readonly IEnvironmentInformationProvider Instance = new DummyEnvironmentInformationProvider(); - - public bool HasField(string reflectionTypeName, int typeParameterCount, string fieldName) - { - return false; - } - } -} diff --git a/ICSharpCode.NRefactory.VB/IAstVisitor.cs b/ICSharpCode.NRefactory.VB/IAstVisitor.cs index 5e81a2be0..a2f8ac6c7 100644 --- a/ICSharpCode.NRefactory.VB/IAstVisitor.cs +++ b/ICSharpCode.NRefactory.VB/IAstVisitor.cs @@ -1,242 +1,46 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:4.0.30319.1 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) + +using System; +using ICSharpCode.NRefactory.VB.Ast; +using Attribute = ICSharpCode.NRefactory.VB.Ast.Attribute; namespace ICSharpCode.NRefactory.VB { - using System; - using ICSharpCode.NRefactory.VB.Ast; - - - public interface IAstVisitor { - - object VisitAddHandlerStatement(AddHandlerStatement addHandlerStatement, object data); - - object VisitAddressOfExpression(AddressOfExpression addressOfExpression, object data); - - object VisitArrayCreateExpression(ArrayCreateExpression arrayCreateExpression, object data); - - object VisitAssignmentExpression(AssignmentExpression assignmentExpression, object data); - - object VisitAttribute(ICSharpCode.NRefactory.VB.Ast.Attribute attribute, object data); - - object VisitAttributeSection(AttributeSection attributeSection, object data); - - object VisitBaseReferenceExpression(BaseReferenceExpression baseReferenceExpression, object data); - - object VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression, object data); - - object VisitBlockStatement(BlockStatement blockStatement, object data); - - object VisitCaseLabel(CaseLabel caseLabel, object data); - - object VisitCastExpression(CastExpression castExpression, object data); - - object VisitCatchClause(CatchClause catchClause, object data); - - object VisitClassReferenceExpression(ClassReferenceExpression classReferenceExpression, object data); - - object VisitCollectionInitializerExpression(CollectionInitializerExpression collectionInitializerExpression, object data); - - object VisitCollectionRangeVariable(CollectionRangeVariable collectionRangeVariable, object data); - - object VisitCompilationUnit(CompilationUnit compilationUnit, object data); - - object VisitConditionalExpression(ConditionalExpression conditionalExpression, object data); - - object VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration, object data); - - object VisitConstructorInitializer(ConstructorInitializer constructorInitializer, object data); - - object VisitContinueStatement(ContinueStatement continueStatement, object data); - - object VisitDeclareDeclaration(DeclareDeclaration declareDeclaration, object data); - - object VisitDefaultValueExpression(DefaultValueExpression defaultValueExpression, object data); - - object VisitDelegateDeclaration(DelegateDeclaration delegateDeclaration, object data); - - object VisitDirectionExpression(DirectionExpression directionExpression, object data); - - object VisitDoLoopStatement(DoLoopStatement doLoopStatement, object data); - - object VisitElseIfSection(ElseIfSection elseIfSection, object data); - - object VisitEndStatement(EndStatement endStatement, object data); - - object VisitEraseStatement(EraseStatement eraseStatement, object data); - - object VisitErrorStatement(ErrorStatement errorStatement, object data); - - object VisitEventAddRegion(EventAddRegion eventAddRegion, object data); - - object VisitEventDeclaration(EventDeclaration eventDeclaration, object data); - - object VisitEventRaiseRegion(EventRaiseRegion eventRaiseRegion, object data); - - object VisitEventRemoveRegion(EventRemoveRegion eventRemoveRegion, object data); - - object VisitExitStatement(ExitStatement exitStatement, object data); - - object VisitExpressionRangeVariable(ExpressionRangeVariable expressionRangeVariable, object data); - - object VisitExpressionStatement(ExpressionStatement expressionStatement, object data); - - object VisitExternAliasDirective(ExternAliasDirective externAliasDirective, object data); - - object VisitFieldDeclaration(FieldDeclaration fieldDeclaration, object data); - - object VisitForeachStatement(ForeachStatement foreachStatement, object data); - - object VisitForNextStatement(ForNextStatement forNextStatement, object data); - - object VisitGotoStatement(GotoStatement gotoStatement, object data); - - object VisitIdentifierExpression(IdentifierExpression identifierExpression, object data); - - object VisitIfElseStatement(IfElseStatement ifElseStatement, object data); - - object VisitInnerClassTypeReference(InnerClassTypeReference innerClassTypeReference, object data); - - object VisitInterfaceImplementation(InterfaceImplementation interfaceImplementation, object data); - - object VisitInvocationExpression(InvocationExpression invocationExpression, object data); - - object VisitLabelStatement(LabelStatement labelStatement, object data); - - object VisitLambdaExpression(LambdaExpression lambdaExpression, object data); - - object VisitLocalVariableDeclaration(LocalVariableDeclaration localVariableDeclaration, object data); - - object VisitLockStatement(LockStatement lockStatement, object data); - - object VisitMemberInitializerExpression(MemberInitializerExpression memberInitializerExpression, object data); - - object VisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression, object data); - - object VisitMethodDeclaration(MethodDeclaration methodDeclaration, object data); - - object VisitNamedArgumentExpression(NamedArgumentExpression namedArgumentExpression, object data); - - object VisitNamespaceDeclaration(NamespaceDeclaration namespaceDeclaration, object data); - - object VisitObjectCreateExpression(ObjectCreateExpression objectCreateExpression, object data); - - object VisitOnErrorStatement(OnErrorStatement onErrorStatement, object data); - - object VisitOperatorDeclaration(OperatorDeclaration operatorDeclaration, object data); - - object VisitOptionDeclaration(OptionDeclaration optionDeclaration, object data); - - object VisitParameterDeclarationExpression(ParameterDeclarationExpression parameterDeclarationExpression, object data); - - object VisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression, object data); - - object VisitPrimitiveExpression(PrimitiveExpression primitiveExpression, object data); - - object VisitPropertyDeclaration(PropertyDeclaration propertyDeclaration, object data); - - object VisitPropertyGetRegion(PropertyGetRegion propertyGetRegion, object data); - - object VisitPropertySetRegion(PropertySetRegion propertySetRegion, object data); - - object VisitQueryExpression(QueryExpression queryExpression, object data); - - object VisitQueryExpressionAggregateClause(QueryExpressionAggregateClause queryExpressionAggregateClause, object data); - - object VisitQueryExpressionDistinctClause(QueryExpressionDistinctClause queryExpressionDistinctClause, object data); - - object VisitQueryExpressionFromClause(QueryExpressionFromClause queryExpressionFromClause, object data); - - object VisitQueryExpressionGroupClause(QueryExpressionGroupClause queryExpressionGroupClause, object data); - - object VisitQueryExpressionGroupJoinVBClause(QueryExpressionGroupJoinVBClause queryExpressionGroupJoinVBClause, object data); - - object VisitQueryExpressionGroupVBClause(QueryExpressionGroupVBClause queryExpressionGroupVBClause, object data); - - object VisitQueryExpressionJoinClause(QueryExpressionJoinClause queryExpressionJoinClause, object data); - - object VisitQueryExpressionJoinConditionVB(QueryExpressionJoinConditionVB queryExpressionJoinConditionVB, object data); - - object VisitQueryExpressionJoinVBClause(QueryExpressionJoinVBClause queryExpressionJoinVBClause, object data); - - object VisitQueryExpressionLetClause(QueryExpressionLetClause queryExpressionLetClause, object data); - - object VisitQueryExpressionLetVBClause(QueryExpressionLetVBClause queryExpressionLetVBClause, object data); - - object VisitQueryExpressionOrderClause(QueryExpressionOrderClause queryExpressionOrderClause, object data); - - object VisitQueryExpressionOrdering(QueryExpressionOrdering queryExpressionOrdering, object data); - - object VisitQueryExpressionPartitionVBClause(QueryExpressionPartitionVBClause queryExpressionPartitionVBClause, object data); - - object VisitQueryExpressionSelectClause(QueryExpressionSelectClause queryExpressionSelectClause, object data); - - object VisitQueryExpressionSelectVBClause(QueryExpressionSelectVBClause queryExpressionSelectVBClause, object data); - - object VisitQueryExpressionWhereClause(QueryExpressionWhereClause queryExpressionWhereClause, object data); - - object VisitRaiseEventStatement(RaiseEventStatement raiseEventStatement, object data); - - object VisitReDimStatement(ReDimStatement reDimStatement, object data); - - object VisitRemoveHandlerStatement(RemoveHandlerStatement removeHandlerStatement, object data); - - object VisitResumeStatement(ResumeStatement resumeStatement, object data); - - object VisitReturnStatement(ReturnStatement returnStatement, object data); - - object VisitStopStatement(StopStatement stopStatement, object data); - - object VisitSwitchSection(SwitchSection switchSection, object data); - - object VisitSwitchStatement(SwitchStatement switchStatement, object data); - - object VisitTemplateDefinition(TemplateDefinition templateDefinition, object data); - - object VisitThisReferenceExpression(ThisReferenceExpression thisReferenceExpression, object data); - - object VisitThrowStatement(ThrowStatement throwStatement, object data); - - object VisitTryCatchStatement(TryCatchStatement tryCatchStatement, object data); - - object VisitTypeDeclaration(TypeDeclaration typeDeclaration, object data); - - object VisitTypeOfExpression(TypeOfExpression typeOfExpression, object data); - - object VisitTypeOfIsExpression(TypeOfIsExpression typeOfIsExpression, object data); - - object VisitTypeReference(TypeReference typeReference, object data); - - object VisitTypeReferenceExpression(TypeReferenceExpression typeReferenceExpression, object data); - - object VisitUnaryOperatorExpression(UnaryOperatorExpression unaryOperatorExpression, object data); - - object VisitUsing(Using @using, object data); - - object VisitUsingDeclaration(UsingDeclaration usingDeclaration, object data); - - object VisitUsingStatement(UsingStatement usingStatement, object data); - - object VisitVariableDeclaration(VariableDeclaration variableDeclaration, object data); - - object VisitWithStatement(WithStatement withStatement, object data); - - object VisitXmlAttributeExpression(XmlAttributeExpression xmlAttributeExpression, object data); - - object VisitXmlContentExpression(XmlContentExpression xmlContentExpression, object data); - - object VisitXmlDocumentExpression(XmlDocumentExpression xmlDocumentExpression, object data); - - object VisitXmlElementExpression(XmlElementExpression xmlElementExpression, object data); - - object VisitXmlEmbeddedExpression(XmlEmbeddedExpression xmlEmbeddedExpression, object data); - - object VisitXmlMemberAccessExpression(XmlMemberAccessExpression xmlMemberAccessExpression, object data); + public interface IAstVisitor + { + S VisitBlockStatement(BlockStatement blockStatement, T data); + S VisitCompilationUnit(CompilationUnit compilationUnit, T data); + S VisitPatternPlaceholder(AstNode placeholder, PatternMatching.Pattern pattern, T data); + S VisitTypeParameterDeclaration(TypeParameterDeclaration typeParameterDeclaration, T data); + S VisitParameterDeclaration(ParameterDeclaration parameterDeclaration, T data); + S VisitVBTokenNode(VBTokenNode vBTokenNode, T data); + + // Global scope + S VisitAliasImportsClause(AliasImportsClause aliasImportsClause, T data); + S VisitAttribute(Attribute attribute, T data); + S VisitAttributeBlock(AttributeBlock attributeBlock, T data); + S VisitImportsStatement(ImportsStatement importsStatement, T data); + S VisitMembersImportsClause(MemberImportsClause membersImportsClause, T data); + S VisitNamespaceDeclaration(NamespaceDeclaration namespaceDeclaration, T data); + S VisitOptionStatement(OptionStatement optionStatement, T data); + S VisitTypeDeclaration(TypeDeclaration typeDeclaration, T data); + S VisitXmlNamespaceImportsClause(XmlNamespaceImportsClause xmlNamespaceImportsClause, T data); + S VisitEnumDeclaration(EnumDeclaration enumDeclaration, T data); + S VisitEnumMemberDeclaration(EnumMemberDeclaration enumMemberDeclaration, T data); + S VisitDelegateDeclaration(DelegateDeclaration delegateDeclaration, T data); + + // Expression scope + S VisitIdentifier(Identifier identifier, T data); + S VisitXmlIdentifier(XmlIdentifier xmlIdentifier, T data); + S VisitXmlLiteralString(XmlLiteralString xmlLiteralString, T data); + S VisitSimpleNameExpression(SimpleNameExpression identifierExpression, T data); + S VisitPrimitiveExpression(PrimitiveExpression primitiveExpression, T data); + + // TypeName + S VisitPrimitiveType(PrimitiveType primitiveType, T data); + S VisitQualifiedType(QualifiedType qualifiedType, T data); + S VisitComposedType(ComposedType composedType, T data); + S VisitArraySpecifier(ArraySpecifier arraySpecifier, T data); + S VisitSimpleType(SimpleType simpleType, T data); } } diff --git a/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj b/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj index b8cc68148..1dac9e1d9 100644 --- a/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj +++ b/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj @@ -43,19 +43,41 @@ - + + + - + + + + + + + + - - - - + + - + + + + + + + + + - - + + + + + + + + + @@ -80,12 +102,11 @@ - - - + + + + - - vb.atg @@ -98,25 +119,22 @@ - + - - - - - - - - + + + + + diff --git a/ICSharpCode.NRefactory.VB/Lexer/Block.cs b/ICSharpCode.NRefactory.VB/Lexer/Block.cs index f7c104fce..c9ffba0d2 100644 --- a/ICSharpCode.NRefactory.VB/Lexer/Block.cs +++ b/ICSharpCode.NRefactory.VB/Lexer/Block.cs @@ -33,11 +33,11 @@ namespace ICSharpCode.NRefactory.VB.Parser { public static readonly Block Default = new Block() { context = Context.Global, - lastExpressionStart = Location.Empty + lastExpressionStart = AstLocation.Empty }; public Context context; - public Location lastExpressionStart; + public AstLocation lastExpressionStart; public bool isClosed; public override string ToString() diff --git a/ICSharpCode.NRefactory.VB/Lexer/ExpressionFinder.atg b/ICSharpCode.NRefactory.VB/Lexer/ExpressionFinder.atg index b0961d47f..b2768890d 100644 --- a/ICSharpCode.NRefactory.VB/Lexer/ExpressionFinder.atg +++ b/ICSharpCode.NRefactory.VB/Lexer/ExpressionFinder.atg @@ -281,6 +281,13 @@ ImportsStatement = ( "Global" | Identifier | PrimitiveTypeName ) { TypeSuffix } [ ( "." | "=" ) TypeName ] | XmlOpenTag Identifier "=" LiteralString XmlCloseTag ) + { "," + (. nextTokenIsStartOfImportsOrAccessExpression = true; .) + ( + ( "Global" | Identifier | PrimitiveTypeName ) { TypeSuffix } [ ( "." | "=" ) TypeName ] + | XmlOpenTag Identifier "=" LiteralString XmlCloseTag + ) + } (. PopContext(); .) StatementTerminator @@ -512,6 +519,7 @@ Parameter = (. PushContext(Context.Parameter, la, t); .) { AttributeBlock } { ParameterModifier } (. PushContext(Context.Identifier, la, t); .) (.OnEachPossiblePath: SetIdentifierExpected(la); .) Identifier (. PopContext(); .) + [ "?" ] { "(" { "," } ")" } [ "As" (. PushContext(Context.Type, la, t); .) TypeName (. PopContext(); .) ] [ "=" Expression ] (. PopContext(); .) diff --git a/ICSharpCode.NRefactory.VB/Lexer/ExpressionFinder.cs b/ICSharpCode.NRefactory.VB/Lexer/ExpressionFinder.cs index 9e5feef6e..15b9bdd6d 100644 --- a/ICSharpCode.NRefactory.VB/Lexer/ExpressionFinder.cs +++ b/ICSharpCode.NRefactory.VB/Lexer/ExpressionFinder.cs @@ -28,7 +28,7 @@ namespace ICSharpCode.NRefactory.VB.Parser void PushContext(Context context, Token la, Token t) { string indent = new string('\t', stack.Count); - Location l = la == null ? (t == null ? Location.Empty : t.EndLocation) : la.Location; + AstLocation l = la == null ? (t == null ? AstLocation.Empty : t.EndLocation) : la.Location; stack.Push(new Block() { context = context, lastExpressionStart = l }); Print(indent + "enter " + context); diff --git a/ICSharpCode.NRefactory.VB/Lexer/Parser.cs b/ICSharpCode.NRefactory.VB/Lexer/Parser.cs index 400c9a0f3..9fd64e952 100644 --- a/ICSharpCode.NRefactory.VB/Lexer/Parser.cs +++ b/ICSharpCode.NRefactory.VB/Lexer/Parser.cs @@ -27,7 +27,7 @@ partial class ExpressionFinder { case 6: case 88: case 264: - case 528: + case 530: { BitArray a = new BitArray(239); return a; @@ -53,22 +53,22 @@ partial class ExpressionFinder { case 295: case 399: case 405: - case 472: - case 518: - case 525: - case 533: - case 563: - case 599: - case 648: - case 662: - case 735: + case 474: + case 520: + case 527: + case 535: + case 565: + case 601: + case 650: + case 664: + case 743: return set[6]; case 12: case 13: - case 564: - case 565: - case 610: - case 620: + case 566: + case 567: + case 612: + case 622: { BitArray a = new BitArray(239); a.Set(1, true); @@ -96,27 +96,26 @@ partial class ExpressionFinder { case 373: case 396: case 423: - case 524: - case 530: - case 536: - case 540: - case 548: - case 556: - case 566: - case 575: - case 592: - case 597: - case 605: - case 611: - case 614: - case 621: - case 624: - case 643: - case 646: - case 670: - case 678: - case 714: - case 734: + case 526: + case 532: + case 538: + case 542: + case 550: + case 558: + case 568: + case 577: + case 594: + case 599: + case 607: + case 613: + case 616: + case 623: + case 626: + case 645: + case 648: + case 672: + case 680: + case 716: { BitArray a = new BitArray(239); a.Set(1, true); @@ -135,22 +134,22 @@ partial class ExpressionFinder { case 298: case 352: case 397: - case 452: - case 573: - case 593: - case 612: - case 616: - case 622: - case 644: - case 679: + case 454: + case 575: + case 595: + case 614: + case 618: + case 624: + case 646: + case 681: { BitArray a = new BitArray(239); a.Set(113, true); return a; } case 22: - case 541: - case 576: + case 543: + case 578: return set[9]; case 25: { @@ -162,7 +161,7 @@ partial class ExpressionFinder { case 27: return set[10]; case 28: - case 718: + case 720: return set[11]; case 29: return set[12]; @@ -176,30 +175,30 @@ partial class ExpressionFinder { case 265: case 276: case 277: - case 442: - case 443: - case 460: - case 461: + case 444: + case 445: case 462: case 463: - case 551: - case 552: - case 585: - case 586: - case 673: - case 674: - case 727: - case 728: + case 464: + case 465: + case 553: + case 554: + case 587: + case 588: + case 675: + case 676: + case 729: + case 730: return set[14]; case 33: case 34: - case 519: - case 520: - case 526: - case 527: - case 553: - case 554: - case 667: + case 521: + case 522: + case 528: + case 529: + case 555: + case 556: + case 669: return set[15]; case 35: case 37: @@ -212,25 +211,25 @@ partial class ExpressionFinder { case 307: case 332: case 422: - case 439: - case 475: - case 529: - case 547: - case 555: - case 627: - case 630: - case 652: - case 655: + case 440: + case 477: + case 531: + case 549: + case 557: + case 629: + case 632: + case 654: case 657: - case 669: - case 682: + case 659: + case 671: case 684: - case 707: - case 710: - case 713: - case 719: - case 722: - case 740: + case 686: + case 709: + case 712: + case 715: + case 721: + case 724: + case 742: return set[16]; case 38: case 41: @@ -242,7 +241,7 @@ partial class ExpressionFinder { case 101: case 163: case 388: - case 479: + case 481: return set[19]; case 42: case 177: @@ -250,12 +249,12 @@ partial class ExpressionFinder { case 189: case 253: case 424: - case 449: - case 471: - case 474: - case 587: - case 588: - case 640: + case 451: + case 473: + case 476: + case 589: + case 590: + case 642: { BitArray a = new BitArray(239); a.Set(37, true); @@ -272,15 +271,15 @@ partial class ExpressionFinder { case 188: case 392: case 427: - case 473: - case 476: - case 496: - case 559: - case 590: - case 642: - case 688: - case 717: - case 726: + case 475: + case 478: + case 498: + case 561: + case 592: + case 644: + case 690: + case 719: + case 728: { BitArray a = new BitArray(239); a.Set(38, true); @@ -308,10 +307,10 @@ partial class ExpressionFinder { case 413: case 419: case 420: - case 487: - case 488: - case 701: - case 702: + case 489: + case 490: + case 703: + case 704: return set[22]; case 53: case 169: @@ -321,16 +320,17 @@ partial class ExpressionFinder { case 414: case 421: case 429: - case 437: - case 483: - case 486: - case 490: + case 438: + case 442: + case 485: + case 488: case 492: - case 493: - case 503: - case 510: - case 517: - case 703: + case 494: + case 495: + case 505: + case 512: + case 519: + case 705: { BitArray a = new BitArray(239); a.Set(22, true); @@ -374,14 +374,14 @@ partial class ExpressionFinder { case 393: case 395: case 415: - case 438: - case 465: - case 481: - case 482: + case 439: + case 467: + case 483: case 484: - case 485: - case 546: - case 626: + case 486: + case 487: + case 548: + case 628: return set[23]; case 57: case 78: @@ -457,7 +457,7 @@ partial class ExpressionFinder { return a; } case 71: - case 441: + case 443: { BitArray a = new BitArray(239); a.Set(40, true); @@ -476,7 +476,7 @@ partial class ExpressionFinder { case 282: case 283: case 334: - case 736: + case 744: { BitArray a = new BitArray(239); a.Set(20, true); @@ -508,7 +508,7 @@ partial class ExpressionFinder { } case 84: case 100: - case 513: + case 515: { BitArray a = new BitArray(239); a.Set(22, true); @@ -555,7 +555,7 @@ partial class ExpressionFinder { return a; } case 96: - case 683: + case 685: { BitArray a = new BitArray(239); a.Set(26, true); @@ -612,7 +612,7 @@ partial class ExpressionFinder { return a; } case 111: - case 453: + case 455: { BitArray a = new BitArray(239); a.Set(210, true); @@ -644,8 +644,8 @@ partial class ExpressionFinder { return a; } case 116: - case 598: - case 617: + case 600: + case 619: { BitArray a = new BitArray(239); a.Set(186, true); @@ -766,7 +766,7 @@ partial class ExpressionFinder { return a; } case 135: - case 635: + case 637: { BitArray a = new BitArray(239); a.Set(98, true); @@ -845,8 +845,8 @@ partial class ExpressionFinder { return set[32]; case 161: case 162: - case 477: - case 478: + case 479: + case 480: return set[33]; case 164: return set[34]; @@ -856,7 +856,7 @@ partial class ExpressionFinder { case 328: return set[35]; case 175: - case 455: + case 457: return set[36]; case 176: case 375: @@ -965,10 +965,10 @@ partial class ExpressionFinder { case 245: return set[45]; case 252: - case 550: - case 661: - case 672: - case 680: + case 552: + case 663: + case 674: + case 682: { BitArray a = new BitArray(239); a.Set(127, true); @@ -992,16 +992,17 @@ partial class ExpressionFinder { case 270: case 275: case 365: - case 653: - case 654: + case 655: case 656: - case 691: - case 708: - case 709: + case 658: + case 693: + case 710: case 711: - case 720: - case 721: + case 713: + case 722: case 723: + case 725: + case 737: { BitArray a = new BitArray(239); a.Set(1, true); @@ -1175,8 +1176,8 @@ partial class ExpressionFinder { } case 379: case 380: - case 450: - case 451: + case 452: + case 453: return set[69]; case 383: case 384: @@ -1208,8 +1209,8 @@ partial class ExpressionFinder { case 410: case 416: case 417: - case 698: - case 699: + case 700: + case 701: return set[75]; case 425: case 426: @@ -1217,8 +1218,8 @@ partial class ExpressionFinder { case 428: case 430: case 431: - case 589: - case 641: + case 591: + case 643: return set[77]; case 432: case 433: @@ -1227,7 +1228,9 @@ partial class ExpressionFinder { case 435: return set[79]; case 436: - case 440: + return set[80]; + case 437: + case 441: { BitArray a = new BitArray(239); a.Set(20, true); @@ -1235,79 +1238,80 @@ partial class ExpressionFinder { a.Set(38, true); return a; } - case 444: - case 448: - return set[80]; - case 445: case 446: + case 450: return set[81]; case 447: + case 448: + return set[82]; + case 449: { BitArray a = new BitArray(239); a.Set(21, true); return a; } - case 454: - return set[82]; case 456: - case 469: return set[83]; - case 457: - case 470: - return set[84]; case 458: + case 471: + return set[84]; case 459: + case 472: + return set[85]; + case 460: + case 461: + case 736: { BitArray a = new BitArray(239); a.Set(10, true); return a; } - case 464: + case 466: { BitArray a = new BitArray(239); a.Set(12, true); return a; } - case 466: + case 468: { BitArray a = new BitArray(239); a.Set(13, true); return a; } - case 467: - return set[85]; - case 468: + case 469: return set[86]; - case 480: + case 470: return set[87]; - case 489: - case 491: + case 482: return set[88]; - case 494: - case 495: - case 557: - case 558: - case 686: - case 687: + case 491: + case 493: return set[89]; + case 496: case 497: - case 498: - case 499: - case 504: - case 505: + case 559: case 560: + case 688: case 689: - case 716: - case 725: return set[90]; + case 499: case 500: + case 501: case 506: - case 515: + case 507: + case 562: + case 691: + case 718: + case 727: return set[91]; - case 501: case 502: - case 507: case 508: + case 517: + return set[92]; + case 503: + case 504: + case 509: + case 510: { BitArray a = new BitArray(239); a.Set(22, true); @@ -1315,18 +1319,18 @@ partial class ExpressionFinder { a.Set(63, true); return a; } - case 509: case 511: - case 516: - return set[92]; - case 512: - case 514: + case 513: + case 518: return set[93]; - case 521: - case 534: - case 535: - case 591: - case 668: + case 514: + case 516: + return set[94]; + case 523: + case 536: + case 537: + case 593: + case 670: { BitArray a = new BitArray(239); a.Set(1, true); @@ -1334,28 +1338,28 @@ partial class ExpressionFinder { a.Set(63, true); return a; } - case 522: - case 523: - case 595: - case 596: - return set[94]; - case 531: - case 532: - case 539: + case 524: + case 525: + case 597: + case 598: + return set[95]; + case 533: + case 534: + case 541: { BitArray a = new BitArray(239); a.Set(115, true); return a; } - case 537: - case 538: - return set[95]; - case 542: - case 543: + case 539: + case 540: return set[96]; case 544: case 545: - case 604: + return set[97]; + case 546: + case 547: + case 606: { BitArray a = new BitArray(239); a.Set(1, true); @@ -1363,15 +1367,15 @@ partial class ExpressionFinder { a.Set(21, true); return a; } - case 549: + case 551: { BitArray a = new BitArray(239); a.Set(103, true); return a; } - case 561: - case 562: - case 574: + case 563: + case 564: + case 576: { BitArray a = new BitArray(239); a.Set(84, true); @@ -1379,84 +1383,84 @@ partial class ExpressionFinder { a.Set(209, true); return a; } - case 567: - case 568: - return set[97]; case 569: case 570: return set[98]; case 571: case 572: - case 583: return set[99]; - case 577: - case 578: + case 573: + case 574: + case 585: return set[100]; case 579: case 580: - case 705: return set[101]; case 581: - return set[102]; case 582: + case 707: + return set[102]; + case 583: return set[103]; case 584: - case 594: + return set[104]; + case 586: + case 596: { BitArray a = new BitArray(239); a.Set(172, true); return a; } - case 600: - case 601: - return set[104]; case 602: - return set[105]; case 603: - case 634: + return set[105]; + case 604: return set[106]; - case 606: - case 607: - case 608: - case 625: + case 605: + case 636: return set[107]; + case 608: case 609: - case 613: - case 623: + case 610: + case 627: + return set[108]; + case 611: + case 615: + case 625: { BitArray a = new BitArray(239); a.Set(128, true); a.Set(198, true); return a; } - case 615: - return set[108]; - case 618: + case 617: return set[109]; - case 619: + case 620: return set[110]; - case 628: - case 629: - case 631: - case 697: - case 700: + case 621: return set[111]; - case 632: + case 630: + case 631: case 633: + case 699: + case 702: return set[112]; - case 636: + case 634: + case 635: + return set[113]; case 638: - case 647: + case 640: + case 649: { BitArray a = new BitArray(239); a.Set(119, true); return a; } - case 637: - return set[113]; case 639: return set[114]; - case 645: + case 641: + return set[115]; + case 647: { BitArray a = new BitArray(239); a.Set(56, true); @@ -1464,11 +1468,11 @@ partial class ExpressionFinder { a.Set(193, true); return a; } - case 649: - case 650: - return set[115]; case 651: - case 658: + case 652: + return set[116]; + case 653: + case 660: { BitArray a = new BitArray(239); a.Set(1, true); @@ -1476,111 +1480,116 @@ partial class ExpressionFinder { a.Set(136, true); return a; } - case 659: + case 661: { BitArray a = new BitArray(239); a.Set(101, true); return a; } - case 660: - return set[116]; - case 663: - case 664: + case 662: + return set[117]; + case 665: + case 666: { BitArray a = new BitArray(239); a.Set(149, true); return a; } - case 665: - case 671: - case 737: - { + case 667: + case 673: + case 745: + { BitArray a = new BitArray(239); a.Set(3, true); return a; } - case 666: - return set[117]; - case 675: - case 676: + case 668: return set[118]; case 677: - case 685: + case 678: return set[119]; - case 681: + case 679: + case 687: return set[120]; - case 690: - case 692: + case 683: return set[121]; - case 693: - case 704: - return set[122]; + case 692: case 694: + return set[122]; case 695: + case 706: return set[123]; case 696: + case 697: return set[124]; - case 706: + case 698: + return set[125]; + case 708: { BitArray a = new BitArray(239); a.Set(136, true); return a; } - case 712: + case 714: { BitArray a = new BitArray(239); a.Set(140, true); return a; } - case 715: - case 724: + case 717: + case 726: { BitArray a = new BitArray(239); a.Set(169, true); return a; } - case 729: - return set[125]; - case 730: + case 731: + return set[126]; + case 732: { BitArray a = new BitArray(239); a.Set(160, true); return a; } - case 731: + case 733: { BitArray a = new BitArray(239); a.Set(137, true); return a; } - case 732: - case 733: - return set[126]; + case 734: + case 735: case 738: + case 739: + return set[127]; + case 740: + case 747: + return set[128]; + case 741: + return set[129]; + case 746: { BitArray a = new BitArray(239); a.Set(11, true); return a; } - case 739: - return set[127]; - case 741: + case 748: { BitArray a = new BitArray(239); a.Set(173, true); return a; } - case 742: - return set[128]; - case 743: + case 749: + return set[130]; + case 750: { BitArray a = new BitArray(239); a.Set(67, true); a.Set(213, true); return a; } - case 744: - return set[129]; + case 751: + return set[131]; default: throw new InvalidOperationException(); } } @@ -1636,7 +1645,7 @@ partial class ExpressionFinder { if (la == null) { currentState = 1; break; } if (la.kind == 173) { stateStack.Push(1); - goto case 741; + goto case 748; } else { goto case 2; } @@ -1645,7 +1654,7 @@ partial class ExpressionFinder { if (la == null) { currentState = 2; break; } if (la.kind == 137) { stateStack.Push(2); - goto case 731; + goto case 733; } else { goto case 3; } @@ -1654,7 +1663,7 @@ partial class ExpressionFinder { if (la == null) { currentState = 3; break; } if (la.kind == 40) { stateStack.Push(3); - goto case 441; + goto case 443; } else { goto case 4; } @@ -1673,7 +1682,7 @@ partial class ExpressionFinder { case 5: { if (la == null) { currentState = 5; break; } if (la.kind == 160) { - currentState = 727; + currentState = 729; break; } else { if (set[4].Get(la.kind)) { @@ -1692,26 +1701,26 @@ partial class ExpressionFinder { if (la == null) { currentState = 7; break; } if (la.kind == 40) { stateStack.Push(7); - goto case 441; + goto case 443; } else { goto case 8; } } case 8: { if (la == null) { currentState = 8; break; } - if (set[130].Get(la.kind)) { + if (set[132].Get(la.kind)) { currentState = 8; break; } else { if (la.kind == 84 || la.kind == 155 || la.kind == 209) { - goto case 561; + goto case 563; } else { if (la.kind == 103) { - currentState = 550; + currentState = 552; break; } else { if (la.kind == 115) { - goto case 531; + goto case 533; } else { if (la.kind == 142) { goto case 9; @@ -1746,7 +1755,7 @@ partial class ExpressionFinder { case 13: { if (la == null) { currentState = 13; break; } if (la.kind == 37) { - currentState = 724; + currentState = 726; break; } else { goto case 14; @@ -1763,7 +1772,7 @@ partial class ExpressionFinder { case 16: { if (la == null) { currentState = 16; break; } if (la.kind == 140) { - currentState = 719; + currentState = 721; break; } else { goto case 17; @@ -1833,7 +1842,7 @@ partial class ExpressionFinder { if (la == null) { currentState = 27; break; } if (la.kind == 40) { stateStack.Push(26); - goto case 441; + goto case 443; } else { isMissingModifier = true; goto case 28; @@ -1841,8 +1850,8 @@ partial class ExpressionFinder { } case 28: { if (la == null) { currentState = 28; break; } - if (set[131].Get(la.kind)) { - currentState = 718; + if (set[133].Get(la.kind)) { + currentState = 720; break; } else { isMissingModifier = false; @@ -1853,15 +1862,15 @@ partial class ExpressionFinder { if (la == null) { currentState = 29; break; } if (la.kind == 84 || la.kind == 155 || la.kind == 209) { stateStack.Push(17); - goto case 561; + goto case 563; } else { if (la.kind == 103) { stateStack.Push(17); - goto case 549; + goto case 551; } else { if (la.kind == 115) { stateStack.Push(17); - goto case 531; + goto case 533; } else { if (la.kind == 142) { stateStack.Push(17); @@ -1882,11 +1891,11 @@ partial class ExpressionFinder { case 30: { if (la == null) { currentState = 30; break; } if (la.kind == 119) { - currentState = 525; + currentState = 527; break; } else { if (la.kind == 186) { - currentState = 518; + currentState = 520; break; } else { if (la.kind == 127 || la.kind == 210) { @@ -1915,7 +1924,7 @@ partial class ExpressionFinder { case 34: { if (la == null) { currentState = 34; break; } if (la.kind == 37) { - currentState = 494; + currentState = 496; break; } else { if (la.kind == 63) { @@ -1945,7 +1954,7 @@ partial class ExpressionFinder { currentState = 38; break; } else { - if (set[132].Get(la.kind)) { + if (set[134].Get(la.kind)) { currentState = 38; break; } else { @@ -2006,7 +2015,7 @@ partial class ExpressionFinder { case 44: { if (la == null) { currentState = 44; break; } if (la.kind == 169) { - currentState = 489; + currentState = 491; break; } else { if (set[22].Get(la.kind)) { @@ -2040,7 +2049,7 @@ partial class ExpressionFinder { if (la == null) { currentState = 48; break; } if (set[23].Get(la.kind)) { activeArgument = 0; - goto case 485; + goto case 487; } else { if (la.kind == 22) { activeArgument = 0; @@ -2360,7 +2369,7 @@ partial class ExpressionFinder { } case 77: { if (la == null) { currentState = 77; break; } - if (set[133].Get(la.kind)) { + if (set[135].Get(la.kind)) { currentState = 76; break; } else { @@ -3723,7 +3732,7 @@ partial class ExpressionFinder { currentState = 165; break; } else { - if (set[134].Get(la.kind)) { + if (set[136].Get(la.kind)) { currentState = 161; break; } else { @@ -3820,39 +3829,39 @@ partial class ExpressionFinder { } case 174: { if (la == null) { currentState = 174; break; } - if (set[135].Get(la.kind)) { + if (set[137].Get(la.kind)) { currentState = 175; break; } else { if (la.kind == 37) { - currentState = 481; + currentState = 483; break; } else { - if (set[136].Get(la.kind)) { + if (set[138].Get(la.kind)) { currentState = 175; break; } else { - if (set[132].Get(la.kind)) { + if (set[134].Get(la.kind)) { currentState = 175; break; } else { - if (set[134].Get(la.kind)) { - currentState = 477; + if (set[136].Get(la.kind)) { + currentState = 479; break; } else { if (la.kind == 129) { - currentState = 474; + currentState = 476; break; } else { if (la.kind == 237) { - currentState = 471; + currentState = 473; break; } else { - if (set[82].Get(la.kind)) { + if (set[83].Get(la.kind)) { stateStack.Push(175); nextTokenIsPotentialStartOfExpression = true; PushContext(Context.Xml, la, t); - goto case 454; + goto case 456; } else { if (la.kind == 127 || la.kind == 210) { stateStack.Push(175); @@ -3932,7 +3941,7 @@ partial class ExpressionFinder { } case 183: { if (la == null) { currentState = 183; break; } - if (set[137].Get(la.kind)) { + if (set[139].Get(la.kind)) { currentState = 189; break; } else { @@ -4124,7 +4133,7 @@ partial class ExpressionFinder { } case 205: { if (la == null) { currentState = 205; break; } - if (set[122].Get(la.kind)) { + if (set[123].Get(la.kind)) { currentState = stateStack.Pop(); break; } else { @@ -4481,7 +4490,7 @@ partial class ExpressionFinder { case 252: { if (la == null) { currentState = 252; break; } if (la.kind == 210) { - currentState = 449; + currentState = 451; break; } else { if (la.kind == 127) { @@ -4547,7 +4556,7 @@ partial class ExpressionFinder { } case 262: { if (la == null) { currentState = 262; break; } - if (set[138].Get(la.kind)) { + if (set[140].Get(la.kind)) { if (set[69].Get(la.kind)) { if (set[50].Get(la.kind)) { stateStack.Push(260); @@ -4664,7 +4673,7 @@ partial class ExpressionFinder { currentState = 296; break; } else { - if (set[139].Get(la.kind)) { + if (set[141].Get(la.kind)) { if (la.kind == 132) { currentState = 293; break; @@ -4703,7 +4712,7 @@ partial class ExpressionFinder { currentState = 269; break; } else { - if (set[140].Get(la.kind)) { + if (set[142].Get(la.kind)) { if (la.kind == 73) { currentState = 55; break; @@ -5418,7 +5427,7 @@ partial class ExpressionFinder { } case 364: { if (la == null) { currentState = 364; break; } - if (set[141].Get(la.kind)) { + if (set[143].Get(la.kind)) { if (la.kind == 144) { currentState = 366; break; @@ -5933,7 +5942,7 @@ partial class ExpressionFinder { if (la == null) { currentState = 431; break; } if (la.kind == 40) { stateStack.Push(430); - goto case 441; + goto case 443; } else { goto case 432; } @@ -5944,7 +5953,7 @@ partial class ExpressionFinder { } case 433: { if (la == null) { currentState = 433; break; } - if (set[142].Get(la.kind)) { + if (set[144].Get(la.kind)) { currentState = 432; break; } else { @@ -5960,8 +5969,8 @@ partial class ExpressionFinder { } case 435: { if (la == null) { currentState = 435; break; } - if (la.kind == 63) { - currentState = 439; + if (la.kind == 33) { + currentState = 436; break; } else { goto case 436; @@ -5969,67 +5978,92 @@ partial class ExpressionFinder { } case 436: { if (la == null) { currentState = 436; break; } - if (la.kind == 20) { - currentState = 438; + if (la.kind == 37) { + currentState = 442; break; } else { - goto case 437; + if (la.kind == 63) { + currentState = 440; + break; + } else { + goto case 437; + } } } case 437: { + if (la == null) { currentState = 437; break; } + if (la.kind == 20) { + currentState = 439; + break; + } else { + goto case 438; + } + } + case 438: { PopContext(); currentState = stateStack.Pop(); goto switchlbl; } - case 438: { - stateStack.Push(437); + case 439: { + stateStack.Push(438); goto case 55; } - case 439: { + case 440: { PushContext(Context.Type, la, t); - stateStack.Push(440); + stateStack.Push(441); goto case 37; } - case 440: { + case 441: { PopContext(); - goto case 436; + goto case 437; } - case 441: { - if (la == null) { currentState = 441; break; } + case 442: { + if (la == null) { currentState = 442; break; } + if (la.kind == 22) { + currentState = 442; + break; + } else { + Expect(38, la); // ")" + currentState = 436; + break; + } + } + case 443: { + if (la == null) { currentState = 443; break; } Expect(40, la); // "<" - currentState = 442; + currentState = 444; break; } - case 442: { + case 444: { wasNormalAttribute = true; PushContext(Context.Attribute, la, t); - goto case 443; + goto case 445; } - case 443: { - if (la == null) { currentState = 443; break; } + case 445: { + if (la == null) { currentState = 445; break; } if (la.kind == 65 || la.kind == 155) { - currentState = 447; + currentState = 449; break; } else { - goto case 444; + goto case 446; } } - case 444: { - if (la == null) { currentState = 444; break; } - if (set[143].Get(la.kind)) { - currentState = 444; + case 446: { + if (la == null) { currentState = 446; break; } + if (set[145].Get(la.kind)) { + currentState = 446; break; } else { Expect(39, la); // ">" - currentState = 445; + currentState = 447; break; } } - case 445: { + case 447: { PopContext(); - goto case 446; + goto case 448; } - case 446: { - if (la == null) { currentState = 446; break; } + case 448: { + if (la == null) { currentState = 448; break; } if (la.kind == 1) { goto case 25; } else { @@ -6037,287 +6071,287 @@ partial class ExpressionFinder { goto switchlbl; } } - case 447: { - if (la == null) { currentState = 447; break; } + case 449: { + if (la == null) { currentState = 449; break; } Expect(21, la); // ":" - currentState = 448; + currentState = 450; break; } - case 448: { + case 450: { wasNormalAttribute = false; - goto case 444; + goto case 446; } - case 449: { - stateStack.Push(450); + case 451: { + stateStack.Push(452); goto case 424; } - case 450: { + case 452: { nextTokenIsPotentialStartOfExpression = true; - goto case 451; + goto case 453; } - case 451: { - if (la == null) { currentState = 451; break; } + case 453: { + if (la == null) { currentState = 453; break; } if (set[50].Get(la.kind)) { goto case 267; } else { if (la.kind == 1 || la.kind == 21) { - stateStack.Push(452); + stateStack.Push(454); goto case 259; } else { goto case 6; } } } - case 452: { - if (la == null) { currentState = 452; break; } + case 454: { + if (la == null) { currentState = 454; break; } Expect(113, la); // "End" - currentState = 453; + currentState = 455; break; } - case 453: { - if (la == null) { currentState = 453; break; } + case 455: { + if (la == null) { currentState = 455; break; } Expect(210, la); // "Sub" currentState = stateStack.Pop(); break; } - case 454: { - if (la == null) { currentState = 454; break; } + case 456: { + if (la == null) { currentState = 456; break; } if (la.kind == 17 || la.kind == 18 || la.kind == 19) { - currentState = 467; + currentState = 469; break; } else { if (la.kind == 10) { - stateStack.Push(456); - goto case 458; + stateStack.Push(458); + goto case 460; } else { Error(la); - goto case 455; + goto case 457; } } } - case 455: { + case 457: { PopContext(); currentState = stateStack.Pop(); goto switchlbl; } - case 456: { - if (la == null) { currentState = 456; break; } + case 458: { + if (la == null) { currentState = 458; break; } if (la.kind == 17) { - currentState = 457; + currentState = 459; break; } else { - goto case 455; + goto case 457; } } - case 457: { - if (la == null) { currentState = 457; break; } + case 459: { + if (la == null) { currentState = 459; break; } if (la.kind == 16) { - currentState = 456; + currentState = 458; break; } else { - goto case 456; + goto case 458; } } - case 458: { + case 460: { PushContext(Context.Xml, la, t); - goto case 459; + goto case 461; } - case 459: { - if (la == null) { currentState = 459; break; } + case 461: { + if (la == null) { currentState = 461; break; } Expect(10, la); // XmlOpenTag - currentState = 460; + currentState = 462; break; } - case 460: { - if (la == null) { currentState = 460; break; } - if (set[144].Get(la.kind)) { - if (set[145].Get(la.kind)) { - currentState = 460; + case 462: { + if (la == null) { currentState = 462; break; } + if (set[146].Get(la.kind)) { + if (set[147].Get(la.kind)) { + currentState = 462; break; } else { if (la.kind == 12) { - stateStack.Push(460); - goto case 464; + stateStack.Push(462); + goto case 466; } else { Error(la); - goto case 460; + goto case 462; } } } else { if (la.kind == 14) { - currentState = 461; + currentState = 463; break; } else { if (la.kind == 11) { - currentState = 462; + currentState = 464; break; } else { Error(la); - goto case 461; + goto case 463; } } } } - case 461: { + case 463: { PopContext(); currentState = stateStack.Pop(); goto switchlbl; } - case 462: { - if (la == null) { currentState = 462; break; } - if (set[146].Get(la.kind)) { - if (set[147].Get(la.kind)) { - currentState = 462; + case 464: { + if (la == null) { currentState = 464; break; } + if (set[148].Get(la.kind)) { + if (set[149].Get(la.kind)) { + currentState = 464; break; } else { if (la.kind == 12) { - stateStack.Push(462); - goto case 464; + stateStack.Push(464); + goto case 466; } else { if (la.kind == 10) { - stateStack.Push(462); - goto case 458; + stateStack.Push(464); + goto case 460; } else { Error(la); - goto case 462; + goto case 464; } } } } else { Expect(15, la); // XmlOpenEndTag - currentState = 463; + currentState = 465; break; } } - case 463: { - if (la == null) { currentState = 463; break; } - if (set[148].Get(la.kind)) { - if (set[149].Get(la.kind)) { - currentState = 463; + case 465: { + if (la == null) { currentState = 465; break; } + if (set[150].Get(la.kind)) { + if (set[151].Get(la.kind)) { + currentState = 465; break; } else { if (la.kind == 12) { - stateStack.Push(463); - goto case 464; + stateStack.Push(465); + goto case 466; } else { Error(la); - goto case 463; + goto case 465; } } } else { Expect(11, la); // XmlCloseTag - currentState = 461; + currentState = 463; break; } } - case 464: { - if (la == null) { currentState = 464; break; } + case 466: { + if (la == null) { currentState = 466; break; } Expect(12, la); // XmlStartInlineVB - currentState = 465; + currentState = 467; break; } - case 465: { - stateStack.Push(466); + case 467: { + stateStack.Push(468); goto case 55; } - case 466: { - if (la == null) { currentState = 466; break; } + case 468: { + if (la == null) { currentState = 468; break; } Expect(13, la); // XmlEndInlineVB currentState = stateStack.Pop(); break; } - case 467: { - if (la == null) { currentState = 467; break; } + case 469: { + if (la == null) { currentState = 469; break; } if (la.kind == 16) { - currentState = 468; + currentState = 470; break; } else { - goto case 468; + goto case 470; } } - case 468: { - if (la == null) { currentState = 468; break; } + case 470: { + if (la == null) { currentState = 470; break; } if (la.kind == 17 || la.kind == 19) { - currentState = 467; + currentState = 469; break; } else { if (la.kind == 10) { - stateStack.Push(469); - goto case 458; + stateStack.Push(471); + goto case 460; } else { - goto case 455; + goto case 457; } } } - case 469: { - if (la == null) { currentState = 469; break; } + case 471: { + if (la == null) { currentState = 471; break; } if (la.kind == 17) { - currentState = 470; + currentState = 472; break; } else { - goto case 455; + goto case 457; } } - case 470: { - if (la == null) { currentState = 470; break; } + case 472: { + if (la == null) { currentState = 472; break; } if (la.kind == 16) { - currentState = 469; + currentState = 471; break; } else { - goto case 469; + goto case 471; } } - case 471: { - if (la == null) { currentState = 471; break; } + case 473: { + if (la == null) { currentState = 473; break; } Expect(37, la); // "(" - currentState = 472; + currentState = 474; break; } - case 472: { + case 474: { readXmlIdentifier = true; - stateStack.Push(473); + stateStack.Push(475); goto case 205; } - case 473: { - if (la == null) { currentState = 473; break; } + case 475: { + if (la == null) { currentState = 475; break; } Expect(38, la); // ")" currentState = 175; break; } - case 474: { - if (la == null) { currentState = 474; break; } + case 476: { + if (la == null) { currentState = 476; break; } Expect(37, la); // "(" - currentState = 475; + currentState = 477; break; } - case 475: { + case 477: { PushContext(Context.Type, la, t); - stateStack.Push(476); + stateStack.Push(478); goto case 37; } - case 476: { + case 478: { PopContext(); - goto case 473; + goto case 475; } - case 477: { + case 479: { nextTokenIsStartOfImportsOrAccessExpression = true; wasQualifierTokenAtStart = true; - goto case 478; + goto case 480; } - case 478: { - if (la == null) { currentState = 478; break; } + case 480: { + if (la == null) { currentState = 480; break; } if (la.kind == 10) { - currentState = 479; + currentState = 481; break; } else { - goto case 479; + goto case 481; } } - case 479: { - stateStack.Push(480); + case 481: { + stateStack.Push(482); goto case 101; } - case 480: { - if (la == null) { currentState = 480; break; } + case 482: { + if (la == null) { currentState = 482; break; } if (la.kind == 11) { currentState = 175; break; @@ -6325,235 +6359,235 @@ partial class ExpressionFinder { goto case 175; } } - case 481: { + case 483: { activeArgument = 0; - goto case 482; + goto case 484; } - case 482: { - stateStack.Push(483); + case 484: { + stateStack.Push(485); goto case 55; } - case 483: { - if (la == null) { currentState = 483; break; } + case 485: { + if (la == null) { currentState = 485; break; } if (la.kind == 22) { - currentState = 484; + currentState = 486; break; } else { - goto case 473; + goto case 475; } } - case 484: { + case 486: { activeArgument++; - goto case 482; + goto case 484; } - case 485: { - stateStack.Push(486); + case 487: { + stateStack.Push(488); goto case 55; } - case 486: { - if (la == null) { currentState = 486; break; } + case 488: { + if (la == null) { currentState = 488; break; } if (la.kind == 22) { - currentState = 487; + currentState = 489; break; } else { currentState = stateStack.Pop(); goto switchlbl; } } - case 487: { + case 489: { activeArgument++; nextTokenIsPotentialStartOfExpression = true; - goto case 488; + goto case 490; } - case 488: { - if (la == null) { currentState = 488; break; } + case 490: { + if (la == null) { currentState = 490; break; } if (set[23].Get(la.kind)) { - goto case 485; + goto case 487; } else { - goto case 486; + goto case 488; } } - case 489: { - if (la == null) { currentState = 489; break; } + case 491: { + if (la == null) { currentState = 491; break; } if (set[16].Get(la.kind)) { PushContext(Context.Type, la, t); - stateStack.Push(493); + stateStack.Push(495); goto case 37; } else { - goto case 490; + goto case 492; } } - case 490: { - if (la == null) { currentState = 490; break; } + case 492: { + if (la == null) { currentState = 492; break; } if (la.kind == 22) { - currentState = 491; + currentState = 493; break; } else { goto case 45; } } - case 491: { - if (la == null) { currentState = 491; break; } + case 493: { + if (la == null) { currentState = 493; break; } if (set[16].Get(la.kind)) { PushContext(Context.Type, la, t); - stateStack.Push(492); + stateStack.Push(494); goto case 37; } else { - goto case 490; + goto case 492; } } - case 492: { + case 494: { PopContext(); - goto case 490; + goto case 492; } - case 493: { + case 495: { PopContext(); - goto case 490; + goto case 492; } - case 494: { + case 496: { SetIdentifierExpected(la); - goto case 495; + goto case 497; } - case 495: { - if (la == null) { currentState = 495; break; } - if (set[150].Get(la.kind)) { + case 497: { + if (la == null) { currentState = 497; break; } + if (set[152].Get(la.kind)) { if (la.kind == 169) { - currentState = 497; + currentState = 499; break; } else { if (set[77].Get(la.kind)) { - stateStack.Push(496); + stateStack.Push(498); goto case 428; } else { Error(la); - goto case 496; + goto case 498; } } } else { - goto case 496; + goto case 498; } } - case 496: { - if (la == null) { currentState = 496; break; } + case 498: { + if (la == null) { currentState = 498; break; } Expect(38, la); // ")" currentState = 34; break; } - case 497: { - stateStack.Push(496); - goto case 498; + case 499: { + stateStack.Push(498); + goto case 500; } - case 498: { + case 500: { SetIdentifierExpected(la); - goto case 499; + goto case 501; } - case 499: { - if (la == null) { currentState = 499; break; } + case 501: { + if (la == null) { currentState = 501; break; } if (la.kind == 138 || la.kind == 178) { - currentState = 500; + currentState = 502; break; } else { - goto case 500; + goto case 502; } } - case 500: { + case 502: { PushContext(Context.Identifier, la, t); SetIdentifierExpected(la); - stateStack.Push(501); - goto case 515; + stateStack.Push(503); + goto case 517; } - case 501: { + case 503: { PopContext(); - goto case 502; + goto case 504; } - case 502: { - if (la == null) { currentState = 502; break; } + case 504: { + if (la == null) { currentState = 504; break; } if (la.kind == 63) { - currentState = 516; + currentState = 518; break; } else { - goto case 503; + goto case 505; } } - case 503: { - if (la == null) { currentState = 503; break; } + case 505: { + if (la == null) { currentState = 505; break; } if (la.kind == 22) { - currentState = 504; + currentState = 506; break; } else { currentState = stateStack.Pop(); goto switchlbl; } } - case 504: { + case 506: { SetIdentifierExpected(la); - goto case 505; + goto case 507; } - case 505: { - if (la == null) { currentState = 505; break; } + case 507: { + if (la == null) { currentState = 507; break; } if (la.kind == 138 || la.kind == 178) { - currentState = 506; + currentState = 508; break; } else { - goto case 506; + goto case 508; } } - case 506: { + case 508: { PushContext(Context.Identifier, la, t); SetIdentifierExpected(la); - stateStack.Push(507); - goto case 515; + stateStack.Push(509); + goto case 517; } - case 507: { + case 509: { PopContext(); - goto case 508; + goto case 510; } - case 508: { - if (la == null) { currentState = 508; break; } + case 510: { + if (la == null) { currentState = 510; break; } if (la.kind == 63) { - currentState = 509; + currentState = 511; break; } else { - goto case 503; + goto case 505; } } - case 509: { + case 511: { PushContext(Context.Type, la, t); - stateStack.Push(510); - goto case 511; + stateStack.Push(512); + goto case 513; } - case 510: { + case 512: { PopContext(); - goto case 503; + goto case 505; } - case 511: { - if (la == null) { currentState = 511; break; } - if (set[93].Get(la.kind)) { - goto case 514; + case 513: { + if (la == null) { currentState = 513; break; } + if (set[94].Get(la.kind)) { + goto case 516; } else { if (la.kind == 35) { - currentState = 512; + currentState = 514; break; } else { goto case 6; } } } - case 512: { - stateStack.Push(513); - goto case 514; + case 514: { + stateStack.Push(515); + goto case 516; } - case 513: { - if (la == null) { currentState = 513; break; } + case 515: { + if (la == null) { currentState = 515; break; } if (la.kind == 22) { - currentState = 512; + currentState = 514; break; } else { goto case 82; } } - case 514: { - if (la == null) { currentState = 514; break; } + case 516: { + if (la == null) { currentState = 516; break; } if (set[16].Get(la.kind)) { currentState = 38; break; @@ -6573,8 +6607,8 @@ partial class ExpressionFinder { } } } - case 515: { - if (la == null) { currentState = 515; break; } + case 517: { + if (la == null) { currentState = 517; break; } if (la.kind == 2) { goto case 145; } else { @@ -6681,357 +6715,343 @@ partial class ExpressionFinder { } } } - case 516: { + case 518: { PushContext(Context.Type, la, t); - stateStack.Push(517); - goto case 511; + stateStack.Push(519); + goto case 513; } - case 517: { + case 519: { PopContext(); - goto case 503; + goto case 505; } - case 518: { + case 520: { PushContext(Context.Identifier, la, t); SetIdentifierExpected(la); - stateStack.Push(519); + stateStack.Push(521); goto case 205; } - case 519: { + case 521: { PopContext(); - goto case 520; + goto case 522; } - case 520: { - if (la == null) { currentState = 520; break; } + case 522: { + if (la == null) { currentState = 522; break; } if (la.kind == 37) { - stateStack.Push(521); + stateStack.Push(523); goto case 424; } else { - goto case 521; + goto case 523; } } - case 521: { - if (la == null) { currentState = 521; break; } + case 523: { + if (la == null) { currentState = 523; break; } if (la.kind == 63) { - currentState = 522; + currentState = 524; break; } else { goto case 23; } } - case 522: { + case 524: { PushContext(Context.Type, la, t); - goto case 523; + goto case 525; } - case 523: { - if (la == null) { currentState = 523; break; } + case 525: { + if (la == null) { currentState = 525; break; } if (la.kind == 40) { - stateStack.Push(523); - goto case 441; + stateStack.Push(525); + goto case 443; } else { - stateStack.Push(524); + stateStack.Push(526); goto case 37; } } - case 524: { + case 526: { PopContext(); goto case 23; } - case 525: { + case 527: { PushContext(Context.Identifier, la, t); SetIdentifierExpected(la); - stateStack.Push(526); + stateStack.Push(528); goto case 205; } - case 526: { + case 528: { PopContext(); - goto case 527; + goto case 529; } - case 527: { - if (la == null) { currentState = 527; break; } + case 529: { + if (la == null) { currentState = 529; break; } if (la.kind == 37 || la.kind == 63) { if (la.kind == 63) { - currentState = 529; + currentState = 531; break; } else { if (la.kind == 37) { stateStack.Push(23); goto case 424; } else { - goto case 528; + goto case 530; } } } else { goto case 23; } } - case 528: { + case 530: { Error(la); goto case 23; } - case 529: { + case 531: { PushContext(Context.Type, la, t); - stateStack.Push(530); + stateStack.Push(532); goto case 37; } - case 530: { + case 532: { PopContext(); goto case 23; } - case 531: { + case 533: { PushContext(Context.TypeDeclaration, la, t); - goto case 532; + goto case 534; } - case 532: { - if (la == null) { currentState = 532; break; } + case 534: { + if (la == null) { currentState = 534; break; } Expect(115, la); // "Enum" - currentState = 533; + currentState = 535; break; } - case 533: { + case 535: { PushContext(Context.Identifier, la, t); SetIdentifierExpected(la); - stateStack.Push(534); + stateStack.Push(536); goto case 205; } - case 534: { + case 536: { PopContext(); - goto case 535; + goto case 537; } - case 535: { - if (la == null) { currentState = 535; break; } + case 537: { + if (la == null) { currentState = 537; break; } if (la.kind == 63) { - currentState = 547; + currentState = 549; break; } else { - goto case 536; + goto case 538; } } - case 536: { - stateStack.Push(537); + case 538: { + stateStack.Push(539); goto case 23; } - case 537: { + case 539: { SetIdentifierExpected(la); - goto case 538; + goto case 540; } - case 538: { - if (la == null) { currentState = 538; break; } - if (set[96].Get(la.kind)) { - goto case 542; + case 540: { + if (la == null) { currentState = 540; break; } + if (set[97].Get(la.kind)) { + goto case 544; } else { Expect(113, la); // "End" - currentState = 539; + currentState = 541; break; } } - case 539: { - if (la == null) { currentState = 539; break; } + case 541: { + if (la == null) { currentState = 541; break; } Expect(115, la); // "Enum" - currentState = 540; + currentState = 542; break; } - case 540: { - stateStack.Push(541); + case 542: { + stateStack.Push(543); goto case 23; } - case 541: { + case 543: { PopContext(); currentState = stateStack.Pop(); goto switchlbl; } - case 542: { + case 544: { SetIdentifierExpected(la); - goto case 543; + goto case 545; } - case 543: { - if (la == null) { currentState = 543; break; } + case 545: { + if (la == null) { currentState = 545; break; } if (la.kind == 40) { - stateStack.Push(542); - goto case 441; + stateStack.Push(544); + goto case 443; } else { PushContext(Context.Identifier, la, t); SetIdentifierExpected(la); - stateStack.Push(544); + stateStack.Push(546); goto case 205; } } - case 544: { + case 546: { PopContext(); - goto case 545; + goto case 547; } - case 545: { - if (la == null) { currentState = 545; break; } + case 547: { + if (la == null) { currentState = 547; break; } if (la.kind == 20) { - currentState = 546; + currentState = 548; break; } else { - goto case 536; + goto case 538; } } - case 546: { - stateStack.Push(536); + case 548: { + stateStack.Push(538); goto case 55; } - case 547: { + case 549: { PushContext(Context.Type, la, t); - stateStack.Push(548); + stateStack.Push(550); goto case 37; } - case 548: { + case 550: { PopContext(); - goto case 536; + goto case 538; } - case 549: { - if (la == null) { currentState = 549; break; } + case 551: { + if (la == null) { currentState = 551; break; } Expect(103, la); // "Delegate" - currentState = 550; + currentState = 552; break; } - case 550: { - if (la == null) { currentState = 550; break; } + case 552: { + if (la == null) { currentState = 552; break; } if (la.kind == 210) { - currentState = 551; + currentState = 553; break; } else { if (la.kind == 127) { - currentState = 551; + currentState = 553; break; } else { Error(la); - goto case 551; + goto case 553; } } } - case 551: { + case 553: { PushContext(Context.Identifier, la, t); SetIdentifierExpected(la); - goto case 552; + goto case 554; } - case 552: { - if (la == null) { currentState = 552; break; } - currentState = 553; + case 554: { + if (la == null) { currentState = 554; break; } + currentState = 555; break; } - case 553: { + case 555: { PopContext(); - goto case 554; + goto case 556; } - case 554: { - if (la == null) { currentState = 554; break; } + case 556: { + if (la == null) { currentState = 556; break; } if (la.kind == 37) { - currentState = 557; + currentState = 559; break; } else { if (la.kind == 63) { - currentState = 555; + currentState = 557; break; } else { goto case 23; } } } - case 555: { + case 557: { PushContext(Context.Type, la, t); - stateStack.Push(556); + stateStack.Push(558); goto case 37; } - case 556: { + case 558: { PopContext(); goto case 23; } - case 557: { + case 559: { SetIdentifierExpected(la); - goto case 558; + goto case 560; } - case 558: { - if (la == null) { currentState = 558; break; } - if (set[150].Get(la.kind)) { + case 560: { + if (la == null) { currentState = 560; break; } + if (set[152].Get(la.kind)) { if (la.kind == 169) { - currentState = 560; + currentState = 562; break; } else { if (set[77].Get(la.kind)) { - stateStack.Push(559); + stateStack.Push(561); goto case 428; } else { Error(la); - goto case 559; + goto case 561; } } } else { - goto case 559; + goto case 561; } } - case 559: { - if (la == null) { currentState = 559; break; } + case 561: { + if (la == null) { currentState = 561; break; } Expect(38, la); // ")" - currentState = 554; + currentState = 556; break; } - case 560: { - stateStack.Push(559); - goto case 498; + case 562: { + stateStack.Push(561); + goto case 500; } - case 561: { + case 563: { PushContext(Context.TypeDeclaration, la, t); - goto case 562; + goto case 564; } - case 562: { - if (la == null) { currentState = 562; break; } + case 564: { + if (la == null) { currentState = 564; break; } if (la.kind == 155) { - currentState = 563; + currentState = 565; break; } else { if (la.kind == 84) { - currentState = 563; + currentState = 565; break; } else { if (la.kind == 209) { - currentState = 563; + currentState = 565; break; } else { Error(la); - goto case 563; + goto case 565; } } } } - case 563: { + case 565: { PushContext(Context.Identifier, la, t); SetIdentifierExpected(la); - stateStack.Push(564); + stateStack.Push(566); goto case 205; } - case 564: { + case 566: { PopContext(); - goto case 565; + goto case 567; } - case 565: { - if (la == null) { currentState = 565; break; } + case 567: { + if (la == null) { currentState = 567; break; } if (la.kind == 37) { - currentState = 715; + currentState = 717; break; } else { - goto case 566; + goto case 568; } } - case 566: { - stateStack.Push(567); - goto case 23; - } - case 567: { - SetIdentifierExpected(la); - isMissingModifier = true; - goto case 568; - } case 568: { - if (la == null) { currentState = 568; break; } - if (la.kind == 140) { - isMissingModifier = false; - goto case 712; - } else { - goto case 569; - } + stateStack.Push(569); + goto case 23; } case 569: { SetIdentifierExpected(la); @@ -7040,9 +7060,9 @@ partial class ExpressionFinder { } case 570: { if (la == null) { currentState = 570; break; } - if (la.kind == 136) { + if (la.kind == 140) { isMissingModifier = false; - goto case 706; + goto case 714; } else { goto case 571; } @@ -7054,142 +7074,156 @@ partial class ExpressionFinder { } case 572: { if (la == null) { currentState = 572; break; } - if (set[100].Get(la.kind)) { - goto case 577; - } else { + if (la.kind == 136) { isMissingModifier = false; + goto case 708; + } else { goto case 573; } } case 573: { - if (la == null) { currentState = 573; break; } - Expect(113, la); // "End" - currentState = 574; - break; + SetIdentifierExpected(la); + isMissingModifier = true; + goto case 574; } case 574: { if (la == null) { currentState = 574; break; } + if (set[101].Get(la.kind)) { + goto case 579; + } else { + isMissingModifier = false; + goto case 575; + } + } + case 575: { + if (la == null) { currentState = 575; break; } + Expect(113, la); // "End" + currentState = 576; + break; + } + case 576: { + if (la == null) { currentState = 576; break; } if (la.kind == 155) { - currentState = 575; + currentState = 577; break; } else { if (la.kind == 84) { - currentState = 575; + currentState = 577; break; } else { if (la.kind == 209) { - currentState = 575; + currentState = 577; break; } else { Error(la); - goto case 575; + goto case 577; } } } } - case 575: { - stateStack.Push(576); + case 577: { + stateStack.Push(578); goto case 23; } - case 576: { + case 578: { PopContext(); currentState = stateStack.Pop(); goto switchlbl; } - case 577: { + case 579: { SetIdentifierExpected(la); isMissingModifier = true; - goto case 578; + goto case 580; } - case 578: { - if (la == null) { currentState = 578; break; } + case 580: { + if (la == null) { currentState = 580; break; } if (la.kind == 40) { - stateStack.Push(577); - goto case 441; + stateStack.Push(579); + goto case 443; } else { isMissingModifier = true; - goto case 579; + goto case 581; } } - case 579: { + case 581: { SetIdentifierExpected(la); - goto case 580; + goto case 582; } - case 580: { - if (la == null) { currentState = 580; break; } - if (set[131].Get(la.kind)) { - currentState = 705; + case 582: { + if (la == null) { currentState = 582; break; } + if (set[133].Get(la.kind)) { + currentState = 707; break; } else { isMissingModifier = false; SetIdentifierExpected(la); - goto case 581; + goto case 583; } } - case 581: { - if (la == null) { currentState = 581; break; } + case 583: { + if (la == null) { currentState = 583; break; } if (la.kind == 84 || la.kind == 155 || la.kind == 209) { - stateStack.Push(571); - goto case 561; + stateStack.Push(573); + goto case 563; } else { if (la.kind == 103) { - stateStack.Push(571); - goto case 549; + stateStack.Push(573); + goto case 551; } else { if (la.kind == 115) { - stateStack.Push(571); - goto case 531; + stateStack.Push(573); + goto case 533; } else { if (la.kind == 142) { - stateStack.Push(571); + stateStack.Push(573); goto case 9; } else { - if (set[103].Get(la.kind)) { - stateStack.Push(571); + if (set[104].Get(la.kind)) { + stateStack.Push(573); PushContext(Context.Member, la, t); SetIdentifierExpected(la); - goto case 582; + goto case 584; } else { Error(la); - goto case 571; + goto case 573; } } } } } } - case 582: { - if (la == null) { currentState = 582; break; } - if (set[121].Get(la.kind)) { - stateStack.Push(583); - goto case 690; + case 584: { + if (la == null) { currentState = 584; break; } + if (set[122].Get(la.kind)) { + stateStack.Push(585); + goto case 692; } else { if (la.kind == 127 || la.kind == 210) { - stateStack.Push(583); - goto case 672; + stateStack.Push(585); + goto case 674; } else { if (la.kind == 101) { - stateStack.Push(583); - goto case 659; + stateStack.Push(585); + goto case 661; } else { if (la.kind == 119) { - stateStack.Push(583); - goto case 647; + stateStack.Push(585); + goto case 649; } else { if (la.kind == 98) { - stateStack.Push(583); - goto case 635; + stateStack.Push(585); + goto case 637; } else { if (la.kind == 186) { - stateStack.Push(583); - goto case 598; + stateStack.Push(585); + goto case 600; } else { if (la.kind == 172) { - stateStack.Push(583); - goto case 584; + stateStack.Push(585); + goto case 586; } else { Error(la); - goto case 583; + goto case 585; } } } @@ -7198,716 +7232,716 @@ partial class ExpressionFinder { } } } - case 583: { + case 585: { PopContext(); currentState = stateStack.Pop(); goto switchlbl; } - case 584: { - if (la == null) { currentState = 584; break; } - Expect(172, la); // "Operator" - currentState = 585; - break; - } - case 585: { - PushContext(Context.Identifier, la, t); - SetIdentifierExpected(la); - goto case 586; - } case 586: { if (la == null) { currentState = 586; break; } + Expect(172, la); // "Operator" currentState = 587; break; } case 587: { - PopContext(); + PushContext(Context.Identifier, la, t); + SetIdentifierExpected(la); goto case 588; } case 588: { if (la == null) { currentState = 588; break; } - Expect(37, la); // "(" currentState = 589; break; } case 589: { - stateStack.Push(590); - goto case 428; + PopContext(); + goto case 590; } case 590: { if (la == null) { currentState = 590; break; } - Expect(38, la); // ")" + Expect(37, la); // "(" currentState = 591; break; } case 591: { - if (la == null) { currentState = 591; break; } + stateStack.Push(592); + goto case 428; + } + case 592: { + if (la == null) { currentState = 592; break; } + Expect(38, la); // ")" + currentState = 593; + break; + } + case 593: { + if (la == null) { currentState = 593; break; } if (la.kind == 63) { - currentState = 595; + currentState = 597; break; } else { - goto case 592; + goto case 594; } } - case 592: { - stateStack.Push(593); + case 594: { + stateStack.Push(595); goto case 259; } - case 593: { - if (la == null) { currentState = 593; break; } + case 595: { + if (la == null) { currentState = 595; break; } Expect(113, la); // "End" - currentState = 594; + currentState = 596; break; } - case 594: { - if (la == null) { currentState = 594; break; } + case 596: { + if (la == null) { currentState = 596; break; } Expect(172, la); // "Operator" currentState = 23; break; } - case 595: { + case 597: { PushContext(Context.Type, la, t); - goto case 596; + goto case 598; } - case 596: { - if (la == null) { currentState = 596; break; } + case 598: { + if (la == null) { currentState = 598; break; } if (la.kind == 40) { - stateStack.Push(596); - goto case 441; + stateStack.Push(598); + goto case 443; } else { - stateStack.Push(597); + stateStack.Push(599); goto case 37; } } - case 597: { + case 599: { PopContext(); - goto case 592; + goto case 594; } - case 598: { - if (la == null) { currentState = 598; break; } + case 600: { + if (la == null) { currentState = 600; break; } Expect(186, la); // "Property" - currentState = 599; + currentState = 601; break; } - case 599: { + case 601: { PushContext(Context.Identifier, la, t); SetIdentifierExpected(la); - stateStack.Push(600); + stateStack.Push(602); goto case 205; } - case 600: { + case 602: { PopContext(); - goto case 601; + goto case 603; } - case 601: { - if (la == null) { currentState = 601; break; } + case 603: { + if (la == null) { currentState = 603; break; } if (la.kind == 37) { - stateStack.Push(602); + stateStack.Push(604); goto case 424; } else { - goto case 602; + goto case 604; } } - case 602: { - if (la == null) { currentState = 602; break; } + case 604: { + if (la == null) { currentState = 604; break; } if (la.kind == 63) { - currentState = 632; + currentState = 634; break; } else { - goto case 603; + goto case 605; } } - case 603: { - if (la == null) { currentState = 603; break; } + case 605: { + if (la == null) { currentState = 605; break; } if (la.kind == 136) { - currentState = 627; + currentState = 629; break; } else { - goto case 604; + goto case 606; } } - case 604: { - if (la == null) { currentState = 604; break; } + case 606: { + if (la == null) { currentState = 606; break; } if (la.kind == 20) { - currentState = 626; + currentState = 628; break; } else { - goto case 605; + goto case 607; } } - case 605: { - stateStack.Push(606); + case 607: { + stateStack.Push(608); goto case 23; } - case 606: { + case 608: { PopContext(); - goto case 607; + goto case 609; } - case 607: { - if (la == null) { currentState = 607; break; } + case 609: { + if (la == null) { currentState = 609; break; } if (la.kind == 40) { - stateStack.Push(607); - goto case 441; + stateStack.Push(609); + goto case 443; } else { - goto case 608; + goto case 610; } } - case 608: { - if (la == null) { currentState = 608; break; } - if (set[151].Get(la.kind)) { - currentState = 625; + case 610: { + if (la == null) { currentState = 610; break; } + if (set[153].Get(la.kind)) { + currentState = 627; break; } else { if (la.kind == 128 || la.kind == 198) { PushContext(Context.Member, la, t); - goto case 609; + goto case 611; } else { currentState = stateStack.Pop(); goto switchlbl; } } } - case 609: { - if (la == null) { currentState = 609; break; } + case 611: { + if (la == null) { currentState = 611; break; } if (la.kind == 128) { - currentState = 610; + currentState = 612; break; } else { if (la.kind == 198) { - currentState = 610; + currentState = 612; break; } else { Error(la); - goto case 610; + goto case 612; } } } - case 610: { - if (la == null) { currentState = 610; break; } + case 612: { + if (la == null) { currentState = 612; break; } if (la.kind == 37) { - stateStack.Push(611); + stateStack.Push(613); goto case 424; } else { - goto case 611; + goto case 613; } } - case 611: { - stateStack.Push(612); + case 613: { + stateStack.Push(614); goto case 259; } - case 612: { - if (la == null) { currentState = 612; break; } + case 614: { + if (la == null) { currentState = 614; break; } Expect(113, la); // "End" - currentState = 613; + currentState = 615; break; } - case 613: { - if (la == null) { currentState = 613; break; } + case 615: { + if (la == null) { currentState = 615; break; } if (la.kind == 128) { - currentState = 614; + currentState = 616; break; } else { if (la.kind == 198) { - currentState = 614; + currentState = 616; break; } else { Error(la); - goto case 614; + goto case 616; } } } - case 614: { - stateStack.Push(615); + case 616: { + stateStack.Push(617); goto case 23; } - case 615: { - if (la == null) { currentState = 615; break; } - if (set[109].Get(la.kind)) { - goto case 618; + case 617: { + if (la == null) { currentState = 617; break; } + if (set[110].Get(la.kind)) { + goto case 620; } else { - goto case 616; + goto case 618; } } - case 616: { - if (la == null) { currentState = 616; break; } + case 618: { + if (la == null) { currentState = 618; break; } Expect(113, la); // "End" - currentState = 617; + currentState = 619; break; } - case 617: { - if (la == null) { currentState = 617; break; } + case 619: { + if (la == null) { currentState = 619; break; } Expect(186, la); // "Property" currentState = 23; break; } - case 618: { - if (la == null) { currentState = 618; break; } + case 620: { + if (la == null) { currentState = 620; break; } if (la.kind == 40) { - stateStack.Push(618); - goto case 441; + stateStack.Push(620); + goto case 443; } else { - goto case 619; + goto case 621; } } - case 619: { - if (la == null) { currentState = 619; break; } - if (set[151].Get(la.kind)) { - currentState = 619; + case 621: { + if (la == null) { currentState = 621; break; } + if (set[153].Get(la.kind)) { + currentState = 621; break; } else { if (la.kind == 128) { - currentState = 620; + currentState = 622; break; } else { if (la.kind == 198) { - currentState = 620; + currentState = 622; break; } else { Error(la); - goto case 620; + goto case 622; } } } } - case 620: { - if (la == null) { currentState = 620; break; } + case 622: { + if (la == null) { currentState = 622; break; } if (la.kind == 37) { - stateStack.Push(621); + stateStack.Push(623); goto case 424; } else { - goto case 621; + goto case 623; } } - case 621: { - stateStack.Push(622); + case 623: { + stateStack.Push(624); goto case 259; } - case 622: { - if (la == null) { currentState = 622; break; } + case 624: { + if (la == null) { currentState = 624; break; } Expect(113, la); // "End" - currentState = 623; + currentState = 625; break; } - case 623: { - if (la == null) { currentState = 623; break; } + case 625: { + if (la == null) { currentState = 625; break; } if (la.kind == 128) { - currentState = 624; + currentState = 626; break; } else { if (la.kind == 198) { - currentState = 624; + currentState = 626; break; } else { Error(la); - goto case 624; + goto case 626; } } } - case 624: { - stateStack.Push(616); + case 626: { + stateStack.Push(618); goto case 23; } - case 625: { + case 627: { SetIdentifierExpected(la); - goto case 608; + goto case 610; } - case 626: { - stateStack.Push(605); + case 628: { + stateStack.Push(607); goto case 55; } - case 627: { + case 629: { PushContext(Context.Type, la, t); - stateStack.Push(628); + stateStack.Push(630); goto case 37; } - case 628: { + case 630: { PopContext(); - goto case 629; + goto case 631; } - case 629: { - if (la == null) { currentState = 629; break; } + case 631: { + if (la == null) { currentState = 631; break; } if (la.kind == 22) { - currentState = 630; + currentState = 632; break; } else { - goto case 604; + goto case 606; } } - case 630: { + case 632: { PushContext(Context.Type, la, t); - stateStack.Push(631); + stateStack.Push(633); goto case 37; } - case 631: { + case 633: { PopContext(); - goto case 629; + goto case 631; } - case 632: { + case 634: { PushContext(Context.Type, la, t); - goto case 633; + goto case 635; } - case 633: { - if (la == null) { currentState = 633; break; } + case 635: { + if (la == null) { currentState = 635; break; } if (la.kind == 40) { - stateStack.Push(633); - goto case 441; + stateStack.Push(635); + goto case 443; } else { if (la.kind == 162) { - stateStack.Push(634); + stateStack.Push(636); goto case 85; } else { if (set[16].Get(la.kind)) { - stateStack.Push(634); + stateStack.Push(636); goto case 37; } else { Error(la); - goto case 634; + goto case 636; } } } } - case 634: { + case 636: { PopContext(); - goto case 603; + goto case 605; } - case 635: { - if (la == null) { currentState = 635; break; } + case 637: { + if (la == null) { currentState = 637; break; } Expect(98, la); // "Custom" - currentState = 636; + currentState = 638; break; } - case 636: { - stateStack.Push(637); - goto case 647; + case 638: { + stateStack.Push(639); + goto case 649; } - case 637: { - if (la == null) { currentState = 637; break; } - if (set[114].Get(la.kind)) { - goto case 639; + case 639: { + if (la == null) { currentState = 639; break; } + if (set[115].Get(la.kind)) { + goto case 641; } else { Expect(113, la); // "End" - currentState = 638; + currentState = 640; break; } } - case 638: { - if (la == null) { currentState = 638; break; } + case 640: { + if (la == null) { currentState = 640; break; } Expect(119, la); // "Event" currentState = 23; break; } - case 639: { - if (la == null) { currentState = 639; break; } + case 641: { + if (la == null) { currentState = 641; break; } if (la.kind == 40) { - stateStack.Push(639); - goto case 441; + stateStack.Push(641); + goto case 443; } else { if (la.kind == 56) { - currentState = 640; + currentState = 642; break; } else { if (la.kind == 193) { - currentState = 640; + currentState = 642; break; } else { if (la.kind == 189) { - currentState = 640; + currentState = 642; break; } else { Error(la); - goto case 640; + goto case 642; } } } } } - case 640: { - if (la == null) { currentState = 640; break; } - Expect(37, la); // "(" - currentState = 641; - break; - } - case 641: { - stateStack.Push(642); - goto case 428; - } case 642: { if (la == null) { currentState = 642; break; } - Expect(38, la); // ")" + Expect(37, la); // "(" currentState = 643; break; } case 643: { stateStack.Push(644); - goto case 259; + goto case 428; } case 644: { if (la == null) { currentState = 644; break; } - Expect(113, la); // "End" + Expect(38, la); // ")" currentState = 645; break; } case 645: { - if (la == null) { currentState = 645; break; } + stateStack.Push(646); + goto case 259; + } + case 646: { + if (la == null) { currentState = 646; break; } + Expect(113, la); // "End" + currentState = 647; + break; + } + case 647: { + if (la == null) { currentState = 647; break; } if (la.kind == 56) { - currentState = 646; + currentState = 648; break; } else { if (la.kind == 193) { - currentState = 646; + currentState = 648; break; } else { if (la.kind == 189) { - currentState = 646; + currentState = 648; break; } else { Error(la); - goto case 646; + goto case 648; } } } } - case 646: { - stateStack.Push(637); + case 648: { + stateStack.Push(639); goto case 23; } - case 647: { - if (la == null) { currentState = 647; break; } + case 649: { + if (la == null) { currentState = 649; break; } Expect(119, la); // "Event" - currentState = 648; + currentState = 650; break; } - case 648: { + case 650: { PushContext(Context.Identifier, la, t); SetIdentifierExpected(la); - stateStack.Push(649); + stateStack.Push(651); goto case 205; } - case 649: { + case 651: { PopContext(); - goto case 650; + goto case 652; } - case 650: { - if (la == null) { currentState = 650; break; } + case 652: { + if (la == null) { currentState = 652; break; } if (la.kind == 63) { - currentState = 657; + currentState = 659; break; } else { - if (set[152].Get(la.kind)) { + if (set[154].Get(la.kind)) { if (la.kind == 37) { - stateStack.Push(651); + stateStack.Push(653); goto case 424; } else { - goto case 651; + goto case 653; } } else { Error(la); - goto case 651; + goto case 653; } } } - case 651: { - if (la == null) { currentState = 651; break; } + case 653: { + if (la == null) { currentState = 653; break; } if (la.kind == 136) { - currentState = 652; + currentState = 654; break; } else { goto case 23; } } - case 652: { + case 654: { PushContext(Context.Type, la, t); - stateStack.Push(653); + stateStack.Push(655); goto case 37; } - case 653: { + case 655: { PopContext(); - goto case 654; + goto case 656; } - case 654: { - if (la == null) { currentState = 654; break; } + case 656: { + if (la == null) { currentState = 656; break; } if (la.kind == 22) { - currentState = 655; + currentState = 657; break; } else { goto case 23; } } - case 655: { + case 657: { PushContext(Context.Type, la, t); - stateStack.Push(656); + stateStack.Push(658); goto case 37; } - case 656: { + case 658: { PopContext(); - goto case 654; + goto case 656; } - case 657: { + case 659: { PushContext(Context.Type, la, t); - stateStack.Push(658); + stateStack.Push(660); goto case 37; } - case 658: { + case 660: { PopContext(); - goto case 651; + goto case 653; } - case 659: { - if (la == null) { currentState = 659; break; } + case 661: { + if (la == null) { currentState = 661; break; } Expect(101, la); // "Declare" - currentState = 660; + currentState = 662; break; } - case 660: { - if (la == null) { currentState = 660; break; } + case 662: { + if (la == null) { currentState = 662; break; } if (la.kind == 62 || la.kind == 66 || la.kind == 223) { - currentState = 661; + currentState = 663; break; } else { - goto case 661; + goto case 663; } } - case 661: { - if (la == null) { currentState = 661; break; } + case 663: { + if (la == null) { currentState = 663; break; } if (la.kind == 210) { - currentState = 662; + currentState = 664; break; } else { if (la.kind == 127) { - currentState = 662; + currentState = 664; break; } else { Error(la); - goto case 662; + goto case 664; } } } - case 662: { + case 664: { PushContext(Context.Identifier, la, t); SetIdentifierExpected(la); - stateStack.Push(663); + stateStack.Push(665); goto case 205; } - case 663: { + case 665: { PopContext(); - goto case 664; + goto case 666; } - case 664: { - if (la == null) { currentState = 664; break; } + case 666: { + if (la == null) { currentState = 666; break; } Expect(149, la); // "Lib" - currentState = 665; + currentState = 667; break; } - case 665: { - if (la == null) { currentState = 665; break; } + case 667: { + if (la == null) { currentState = 667; break; } Expect(3, la); // LiteralString - currentState = 666; + currentState = 668; break; } - case 666: { - if (la == null) { currentState = 666; break; } + case 668: { + if (la == null) { currentState = 668; break; } if (la.kind == 59) { - currentState = 671; + currentState = 673; break; } else { - goto case 667; + goto case 669; } } - case 667: { - if (la == null) { currentState = 667; break; } + case 669: { + if (la == null) { currentState = 669; break; } if (la.kind == 37) { - stateStack.Push(668); + stateStack.Push(670); goto case 424; } else { - goto case 668; + goto case 670; } } - case 668: { - if (la == null) { currentState = 668; break; } + case 670: { + if (la == null) { currentState = 670; break; } if (la.kind == 63) { - currentState = 669; + currentState = 671; break; } else { goto case 23; } } - case 669: { + case 671: { PushContext(Context.Type, la, t); - stateStack.Push(670); + stateStack.Push(672); goto case 37; } - case 670: { + case 672: { PopContext(); goto case 23; } - case 671: { - if (la == null) { currentState = 671; break; } + case 673: { + if (la == null) { currentState = 673; break; } Expect(3, la); // LiteralString - currentState = 667; + currentState = 669; break; } - case 672: { - if (la == null) { currentState = 672; break; } + case 674: { + if (la == null) { currentState = 674; break; } if (la.kind == 210) { - currentState = 673; + currentState = 675; break; } else { if (la.kind == 127) { - currentState = 673; + currentState = 675; break; } else { Error(la); - goto case 673; + goto case 675; } } } - case 673: { + case 675: { PushContext(Context.Identifier, la, t); SetIdentifierExpected(la); - goto case 674; + goto case 676; } - case 674: { - if (la == null) { currentState = 674; break; } - currentState = 675; + case 676: { + if (la == null) { currentState = 676; break; } + currentState = 677; break; } - case 675: { + case 677: { PopContext(); - goto case 676; + goto case 678; } - case 676: { - if (la == null) { currentState = 676; break; } + case 678: { + if (la == null) { currentState = 678; break; } if (la.kind == 37) { - currentState = 686; + currentState = 688; break; } else { if (la.kind == 63) { - currentState = 684; + currentState = 686; break; } else { - goto case 677; + goto case 679; } } } - case 677: { - if (la == null) { currentState = 677; break; } + case 679: { + if (la == null) { currentState = 679; break; } if (la.kind == 134 || la.kind == 136) { - currentState = 681; + currentState = 683; break; } else { - goto case 678; + goto case 680; } } - case 678: { - stateStack.Push(679); + case 680: { + stateStack.Push(681); goto case 259; } - case 679: { - if (la == null) { currentState = 679; break; } + case 681: { + if (la == null) { currentState = 681; break; } Expect(113, la); // "End" - currentState = 680; + currentState = 682; break; } - case 680: { - if (la == null) { currentState = 680; break; } + case 682: { + if (la == null) { currentState = 682; break; } if (la.kind == 210) { currentState = 23; break; @@ -7916,129 +7950,129 @@ partial class ExpressionFinder { currentState = 23; break; } else { - goto case 528; + goto case 530; } } } - case 681: { - if (la == null) { currentState = 681; break; } + case 683: { + if (la == null) { currentState = 683; break; } if (la.kind == 153 || la.kind == 158 || la.kind == 159) { - currentState = 683; + currentState = 685; break; } else { - goto case 682; + goto case 684; } } - case 682: { - stateStack.Push(678); + case 684: { + stateStack.Push(680); goto case 37; } - case 683: { - if (la == null) { currentState = 683; break; } + case 685: { + if (la == null) { currentState = 685; break; } Expect(26, la); // "." - currentState = 682; + currentState = 684; break; } - case 684: { + case 686: { PushContext(Context.Type, la, t); - stateStack.Push(685); + stateStack.Push(687); goto case 37; } - case 685: { + case 687: { PopContext(); - goto case 677; + goto case 679; } - case 686: { + case 688: { SetIdentifierExpected(la); - goto case 687; + goto case 689; } - case 687: { - if (la == null) { currentState = 687; break; } - if (set[150].Get(la.kind)) { + case 689: { + if (la == null) { currentState = 689; break; } + if (set[152].Get(la.kind)) { if (la.kind == 169) { - currentState = 689; + currentState = 691; break; } else { if (set[77].Get(la.kind)) { - stateStack.Push(688); + stateStack.Push(690); goto case 428; } else { Error(la); - goto case 688; + goto case 690; } } } else { - goto case 688; + goto case 690; } } - case 688: { - if (la == null) { currentState = 688; break; } + case 690: { + if (la == null) { currentState = 690; break; } Expect(38, la); // ")" - currentState = 676; + currentState = 678; break; } - case 689: { - stateStack.Push(688); - goto case 498; + case 691: { + stateStack.Push(690); + goto case 500; } - case 690: { - stateStack.Push(691); + case 692: { + stateStack.Push(693); SetIdentifierExpected(la); - goto case 692; + goto case 694; } - case 691: { - if (la == null) { currentState = 691; break; } + case 693: { + if (la == null) { currentState = 693; break; } if (la.kind == 22) { - currentState = 690; + currentState = 692; break; } else { goto case 23; } } - case 692: { - if (la == null) { currentState = 692; break; } + case 694: { + if (la == null) { currentState = 694; break; } if (la.kind == 88) { - currentState = 693; + currentState = 695; break; } else { - goto case 693; + goto case 695; } } - case 693: { + case 695: { PushContext(Context.Identifier, la, t); SetIdentifierExpected(la); - stateStack.Push(694); - goto case 704; + stateStack.Push(696); + goto case 706; } - case 694: { + case 696: { PopContext(); - goto case 695; + goto case 697; } - case 695: { - if (la == null) { currentState = 695; break; } + case 697: { + if (la == null) { currentState = 697; break; } if (la.kind == 33) { - currentState = 696; + currentState = 698; break; } else { - goto case 696; + goto case 698; } } - case 696: { - if (la == null) { currentState = 696; break; } + case 698: { + if (la == null) { currentState = 698; break; } if (la.kind == 37) { - currentState = 701; + currentState = 703; break; } else { if (la.kind == 63) { - currentState = 698; + currentState = 700; break; } else { - goto case 697; + goto case 699; } } } - case 697: { - if (la == null) { currentState = 697; break; } + case 699: { + if (la == null) { currentState = 699; break; } if (la.kind == 20) { currentState = 55; break; @@ -8047,56 +8081,56 @@ partial class ExpressionFinder { goto switchlbl; } } - case 698: { + case 700: { PushContext(Context.Type, la, t); - goto case 699; + goto case 701; } - case 699: { - if (la == null) { currentState = 699; break; } + case 701: { + if (la == null) { currentState = 701; break; } if (la.kind == 162) { - stateStack.Push(700); + stateStack.Push(702); goto case 85; } else { if (set[16].Get(la.kind)) { - stateStack.Push(700); + stateStack.Push(702); goto case 37; } else { Error(la); - goto case 700; + goto case 702; } } } - case 700: { + case 702: { PopContext(); - goto case 697; + goto case 699; } - case 701: { + case 703: { nextTokenIsPotentialStartOfExpression = true; - goto case 702; + goto case 704; } - case 702: { - if (la == null) { currentState = 702; break; } + case 704: { + if (la == null) { currentState = 704; break; } if (set[23].Get(la.kind)) { - stateStack.Push(703); + stateStack.Push(705); goto case 55; } else { - goto case 703; + goto case 705; } } - case 703: { - if (la == null) { currentState = 703; break; } + case 705: { + if (la == null) { currentState = 705; break; } if (la.kind == 22) { - currentState = 701; + currentState = 703; break; } else { Expect(38, la); // ")" - currentState = 696; + currentState = 698; break; } } - case 704: { - if (la == null) { currentState = 704; break; } - if (set[136].Get(la.kind)) { + case 706: { + if (la == null) { currentState = 706; break; } + if (set[138].Get(la.kind)) { currentState = stateStack.Pop(); break; } else { @@ -8111,249 +8145,285 @@ partial class ExpressionFinder { } } } - case 705: { + case 707: { isMissingModifier = false; - goto case 579; + goto case 581; } - case 706: { - if (la == null) { currentState = 706; break; } + case 708: { + if (la == null) { currentState = 708; break; } Expect(136, la); // "Implements" - currentState = 707; + currentState = 709; break; } - case 707: { + case 709: { PushContext(Context.Type, la, t); - stateStack.Push(708); + stateStack.Push(710); goto case 37; } - case 708: { + case 710: { PopContext(); - goto case 709; + goto case 711; } - case 709: { - if (la == null) { currentState = 709; break; } + case 711: { + if (la == null) { currentState = 711; break; } if (la.kind == 22) { - currentState = 710; + currentState = 712; break; } else { - stateStack.Push(571); + stateStack.Push(573); goto case 23; } } - case 710: { + case 712: { PushContext(Context.Type, la, t); - stateStack.Push(711); + stateStack.Push(713); goto case 37; } - case 711: { + case 713: { PopContext(); - goto case 709; + goto case 711; } - case 712: { - if (la == null) { currentState = 712; break; } + case 714: { + if (la == null) { currentState = 714; break; } Expect(140, la); // "Inherits" - currentState = 713; + currentState = 715; break; } - case 713: { + case 715: { PushContext(Context.Type, la, t); - stateStack.Push(714); + stateStack.Push(716); goto case 37; } - case 714: { + case 716: { PopContext(); - stateStack.Push(569); + stateStack.Push(571); goto case 23; } - case 715: { - if (la == null) { currentState = 715; break; } + case 717: { + if (la == null) { currentState = 717; break; } Expect(169, la); // "Of" - currentState = 716; + currentState = 718; break; } - case 716: { - stateStack.Push(717); - goto case 498; + case 718: { + stateStack.Push(719); + goto case 500; } - case 717: { - if (la == null) { currentState = 717; break; } + case 719: { + if (la == null) { currentState = 719; break; } Expect(38, la); // ")" - currentState = 566; + currentState = 568; break; } - case 718: { + case 720: { isMissingModifier = false; goto case 28; } - case 719: { + case 721: { PushContext(Context.Type, la, t); - stateStack.Push(720); + stateStack.Push(722); goto case 37; } - case 720: { + case 722: { PopContext(); - goto case 721; + goto case 723; } - case 721: { - if (la == null) { currentState = 721; break; } + case 723: { + if (la == null) { currentState = 723; break; } if (la.kind == 22) { - currentState = 722; + currentState = 724; break; } else { stateStack.Push(17); goto case 23; } } - case 722: { + case 724: { PushContext(Context.Type, la, t); - stateStack.Push(723); + stateStack.Push(725); goto case 37; } - case 723: { + case 725: { PopContext(); - goto case 721; + goto case 723; } - case 724: { - if (la == null) { currentState = 724; break; } + case 726: { + if (la == null) { currentState = 726; break; } Expect(169, la); // "Of" - currentState = 725; + currentState = 727; break; } - case 725: { - stateStack.Push(726); - goto case 498; + case 727: { + stateStack.Push(728); + goto case 500; } - case 726: { - if (la == null) { currentState = 726; break; } + case 728: { + if (la == null) { currentState = 728; break; } Expect(38, la); // ")" currentState = 14; break; } - case 727: { + case 729: { PushContext(Context.Identifier, la, t); SetIdentifierExpected(la); - goto case 728; + goto case 730; } - case 728: { - if (la == null) { currentState = 728; break; } + case 730: { + if (la == null) { currentState = 730; break; } if (set[49].Get(la.kind)) { - currentState = 728; + currentState = 730; break; } else { PopContext(); - stateStack.Push(729); + stateStack.Push(731); goto case 23; } } - case 729: { - if (la == null) { currentState = 729; break; } + case 731: { + if (la == null) { currentState = 731; break; } if (set[3].Get(la.kind)) { - stateStack.Push(729); + stateStack.Push(731); goto case 5; } else { Expect(113, la); // "End" - currentState = 730; + currentState = 732; break; } } - case 730: { - if (la == null) { currentState = 730; break; } + case 732: { + if (la == null) { currentState = 732; break; } Expect(160, la); // "Namespace" currentState = 23; break; } - case 731: { - if (la == null) { currentState = 731; break; } + case 733: { + if (la == null) { currentState = 733; break; } Expect(137, la); // "Imports" - currentState = 732; + currentState = 734; break; } - case 732: { + case 734: { PushContext(Context.Importable, la, t); nextTokenIsStartOfImportsOrAccessExpression = true; - goto case 733; + goto case 735; } - case 733: { - if (la == null) { currentState = 733; break; } - if (set[153].Get(la.kind)) { - currentState = 739; + case 735: { + if (la == null) { currentState = 735; break; } + if (set[155].Get(la.kind)) { + currentState = 747; break; } else { - if (la.kind == 10) { - currentState = 735; - break; - } else { - Error(la); - goto case 734; - } + goto case 736; } } - case 734: { - PopContext(); - goto case 23; - } - case 735: { - stateStack.Push(736); - goto case 205; - } case 736: { if (la == null) { currentState = 736; break; } - Expect(20, la); // "=" - currentState = 737; - break; + if (la.kind == 10) { + currentState = 743; + break; + } else { + Error(la); + goto case 737; + } } case 737: { if (la == null) { currentState = 737; break; } - Expect(3, la); // LiteralString - currentState = 738; - break; + if (la.kind == 22) { + currentState = 738; + break; + } else { + PopContext(); + goto case 23; + } } case 738: { - if (la == null) { currentState = 738; break; } - Expect(11, la); // XmlCloseTag - currentState = 734; - break; + nextTokenIsStartOfImportsOrAccessExpression = true; + goto case 739; } case 739: { if (la == null) { currentState = 739; break; } - if (la.kind == 37) { - stateStack.Push(739); - goto case 42; + if (set[155].Get(la.kind)) { + currentState = 740; + break; } else { - if (la.kind == 20 || la.kind == 26) { - currentState = 740; - break; - } else { - goto case 734; - } + goto case 736; } } case 740: { - stateStack.Push(734); - goto case 37; + if (la == null) { currentState = 740; break; } + if (la.kind == 37) { + stateStack.Push(740); + goto case 42; + } else { + goto case 741; + } } case 741: { if (la == null) { currentState = 741; break; } + if (la.kind == 20 || la.kind == 26) { + currentState = 742; + break; + } else { + goto case 737; + } + } + case 742: { + stateStack.Push(737); + goto case 37; + } + case 743: { + stateStack.Push(744); + goto case 205; + } + case 744: { + if (la == null) { currentState = 744; break; } + Expect(20, la); // "=" + currentState = 745; + break; + } + case 745: { + if (la == null) { currentState = 745; break; } + Expect(3, la); // LiteralString + currentState = 746; + break; + } + case 746: { + if (la == null) { currentState = 746; break; } + Expect(11, la); // XmlCloseTag + currentState = 737; + break; + } + case 747: { + if (la == null) { currentState = 747; break; } + if (la.kind == 37) { + stateStack.Push(747); + goto case 42; + } else { + goto case 741; + } + } + case 748: { + if (la == null) { currentState = 748; break; } Expect(173, la); // "Option" - currentState = 742; + currentState = 749; break; } - case 742: { - if (la == null) { currentState = 742; break; } + case 749: { + if (la == null) { currentState = 749; break; } if (la.kind == 121 || la.kind == 139 || la.kind == 207) { - currentState = 744; + currentState = 751; break; } else { if (la.kind == 87) { - currentState = 743; + currentState = 750; break; } else { - goto case 528; + goto case 530; } } } - case 743: { - if (la == null) { currentState = 743; break; } + case 750: { + if (la == null) { currentState = 750; break; } if (la.kind == 213) { currentState = 23; break; @@ -8362,12 +8432,12 @@ partial class ExpressionFinder { currentState = 23; break; } else { - goto case 528; + goto case 530; } } } - case 744: { - if (la == null) { currentState = 744; break; } + case 751: { + if (la == null) { currentState = 751; break; } if (la.kind == 170 || la.kind == 171) { currentState = 23; break; @@ -8475,7 +8545,8 @@ partial class ExpressionFinder { new BitArray(new int[] {4, 1140851008, 8388975, 1108347140, 821280, 21316608, -2144335872, 65}), new BitArray(new int[] {4, 1140850944, 8388975, 1108347140, 821280, 21316608, -2144335872, 65}), new BitArray(new int[] {4, 1140850688, 8388975, 1108347140, 821280, 21316608, -2144335872, 65}), - new BitArray(new int[] {5242880, -2147483584, 0, 0, 0, 0, 0, 0}), + new BitArray(new int[] {5242880, -2147483550, 0, 0, 0, 0, 0, 0}), + new BitArray(new int[] {5242880, -2147483552, 0, 0, 0, 0, 0, 0}), new BitArray(new int[] {-2, -1, -3, -1, -134217729, -1, -1, -1}), new BitArray(new int[] {7, 1157628162, 26477055, -493212676, 948758565, 2147308999, -533262382, 3395}), new BitArray(new int[] {918528, 0, 0, 0, 0, 0, 0, 0}), @@ -8523,7 +8594,8 @@ partial class ExpressionFinder { new BitArray(new int[] {7340034, -2147483616, 0, 0, 0, 0, 0, 0}), new BitArray(new int[] {0, 256, 1048576, 537526400, 402669568, 444596289, 131200, 0}), new BitArray(new int[] {1028, 1140850688, 8650975, 1108355356, 9218084, 17106176, -533656048, 67}), - new BitArray(new int[] {70254594, 32, 0, 0, 0, 0, 0, 0}), + new BitArray(new int[] {74448898, 32, 0, 0, 0, 0, 0, 0}), + new BitArray(new int[] {74448898, 0, 0, 0, 0, 0, 0, 0}), new BitArray(new int[] {0, 0, 8388608, 33554432, 2048, 0, 32768, 0}), new BitArray(new int[] {2097154, 0, 0, 0, 0, 3072, 0, 0}), new BitArray(new int[] {0, 0, 0, 536870912, 268435456, 444596288, 128, 0}), diff --git a/ICSharpCode.NRefactory.VB/Lexer/SavepointEventArgs.cs b/ICSharpCode.NRefactory.VB/Lexer/SavepointEventArgs.cs index 4c9cc88cc..f3ee77a93 100644 --- a/ICSharpCode.NRefactory.VB/Lexer/SavepointEventArgs.cs +++ b/ICSharpCode.NRefactory.VB/Lexer/SavepointEventArgs.cs @@ -8,10 +8,10 @@ namespace ICSharpCode.NRefactory.VB.Parser { public class SavepointEventArgs : EventArgs { - public Location SavepointLocation { get; private set; } + public AstLocation SavepointLocation { get; private set; } public VBLexerMemento State { get; private set; } - public SavepointEventArgs(Location savepointLocation, VBLexerMemento state) + public SavepointEventArgs(AstLocation savepointLocation, VBLexerMemento state) { this.SavepointLocation = savepointLocation; this.State = state; diff --git a/ICSharpCode.NRefactory.VB/Lexer/Special/BlankLine.cs b/ICSharpCode.NRefactory.VB/Lexer/Special/BlankLine.cs index 67a85ec0a..5120bd765 100644 --- a/ICSharpCode.NRefactory.VB/Lexer/Special/BlankLine.cs +++ b/ICSharpCode.NRefactory.VB/Lexer/Special/BlankLine.cs @@ -5,15 +5,15 @@ using System; namespace ICSharpCode.NRefactory.VB { - public class BlankLine : AbstractSpecial - { - public BlankLine(Location point) : base(point) - { - } - - public override object AcceptVisitor(ISpecialVisitor visitor, object data) - { - return visitor.Visit(this, data); - } - } +// public class BlankLine : AbstractSpecial +// { +// public BlankLine(Location point) : base(point) +// { +// } +// +// public override object AcceptVisitor(ISpecialVisitor visitor, object data) +// { +// return visitor.Visit(this, data); +// } +// } } diff --git a/ICSharpCode.NRefactory.VB/Lexer/Special/Comment.cs b/ICSharpCode.NRefactory.VB/Lexer/Special/Comment.cs index 2bce0531c..82772f2d4 100644 --- a/ICSharpCode.NRefactory.VB/Lexer/Special/Comment.cs +++ b/ICSharpCode.NRefactory.VB/Lexer/Special/Comment.cs @@ -5,55 +5,55 @@ using System; namespace ICSharpCode.NRefactory.VB { - public class Comment : AbstractSpecial - { - CommentType commentType; - string comment; - - public CommentType CommentType { - get { - return commentType; - } - set { - commentType = value; - } - } - - public string CommentText { - get { - return comment; - } - set { - comment = value; - } - } - - /// - /// Is true, when the comment is at line start or only whitespaces - /// between line and comment start. - /// - public bool CommentStartsLine { - get; - set; - } - - public Comment(CommentType commentType, string comment, bool commentStartsLine, Location startPosition, Location endPosition) - : base(startPosition, endPosition) - { - this.commentType = commentType; - this.comment = comment; - this.CommentStartsLine = commentStartsLine; - } - - public override string ToString() - { - return String.Format("[{0}: Type = {1}, Text = {2}, Start = {3}, End = {4}]", - GetType().Name, CommentType, CommentText, StartPosition, EndPosition); - } - - public override object AcceptVisitor(ISpecialVisitor visitor, object data) - { - return visitor.Visit(this, data); - } - } +// public class Comment : AbstractSpecial +// { +// CommentType commentType; +// string comment; +// +// public CommentType CommentType { +// get { +// return commentType; +// } +// set { +// commentType = value; +// } +// } +// +// public string CommentText { +// get { +// return comment; +// } +// set { +// comment = value; +// } +// } +// +// /// +// /// Is true, when the comment is at line start or only whitespaces +// /// between line and comment start. +// /// +// public bool CommentStartsLine { +// get; +// set; +// } +// +// public Comment(CommentType commentType, string comment, bool commentStartsLine, Location startPosition, Location endPosition) +// : base(startPosition, endPosition) +// { +// this.commentType = commentType; +// this.comment = comment; +// this.CommentStartsLine = commentStartsLine; +// } +// +// public override string ToString() +// { +// return String.Format("[{0}: Type = {1}, Text = {2}, Start = {3}, End = {4}]", +// GetType().Name, CommentType, CommentText, StartPosition, EndPosition); +// } +// +// public override object AcceptVisitor(ISpecialVisitor visitor, object data) +// { +// return visitor.Visit(this, data); +// } +// } } diff --git a/ICSharpCode.NRefactory.VB/Lexer/Special/CommentType.cs b/ICSharpCode.NRefactory.VB/Lexer/Special/CommentType.cs index c06844a34..1c9bb63e9 100644 --- a/ICSharpCode.NRefactory.VB/Lexer/Special/CommentType.cs +++ b/ICSharpCode.NRefactory.VB/Lexer/Special/CommentType.cs @@ -5,10 +5,10 @@ using System; namespace ICSharpCode.NRefactory.VB { - public enum CommentType - { - Block, - SingleLine, - Documentation - } +// public enum CommentType +// { +// Block, +// SingleLine, +// Documentation +// } } diff --git a/ICSharpCode.NRefactory.VB/Lexer/Special/ISpecial.cs b/ICSharpCode.NRefactory.VB/Lexer/Special/ISpecial.cs index ee6f106cd..a58964211 100644 --- a/ICSharpCode.NRefactory.VB/Lexer/Special/ISpecial.cs +++ b/ICSharpCode.NRefactory.VB/Lexer/Special/ISpecial.cs @@ -5,48 +5,48 @@ using System; namespace ICSharpCode.NRefactory.VB { - /// - /// Interface for all specials. - /// - public interface ISpecial - { - Location StartPosition { get; } - Location EndPosition { get; } - - object AcceptVisitor(ISpecialVisitor visitor, object data); - } - - public interface ISpecialVisitor - { - object Visit(ISpecial special, object data); - object Visit(BlankLine special, object data); - object Visit(Comment special, object data); - object Visit(PreprocessingDirective special, object data); - } - - public abstract class AbstractSpecial : ISpecial - { - public abstract object AcceptVisitor(ISpecialVisitor visitor, object data); - - protected AbstractSpecial(Location position) - { - this.StartPosition = position; - this.EndPosition = position; - } - - protected AbstractSpecial(Location startPosition, Location endPosition) - { - this.StartPosition = startPosition; - this.EndPosition = endPosition; - } - - public Location StartPosition { get; set; } - public Location EndPosition { get; set; } - - public override string ToString() - { - return String.Format("[{0}: Start = {1}, End = {2}]", - GetType().Name, StartPosition, EndPosition); - } - } +// /// +// /// Interface for all specials. +// /// +// public interface ISpecial +// { +// Location StartPosition { get; } +// Location EndPosition { get; } +// +// object AcceptVisitor(ISpecialVisitor visitor, object data); +// } +// +// public interface ISpecialVisitor +// { +// object Visit(ISpecial special, object data); +// object Visit(BlankLine special, object data); +// object Visit(Comment special, object data); +// object Visit(PreprocessingDirective special, object data); +// } +// +// public abstract class AbstractSpecial : ISpecial +// { +// public abstract object AcceptVisitor(ISpecialVisitor visitor, object data); +// +// protected AbstractSpecial(Location position) +// { +// this.StartPosition = position; +// this.EndPosition = position; +// } +// +// protected AbstractSpecial(Location startPosition, Location endPosition) +// { +// this.StartPosition = startPosition; +// this.EndPosition = endPosition; +// } +// +// public Location StartPosition { get; set; } +// public Location EndPosition { get; set; } +// +// public override string ToString() +// { +// return String.Format("[{0}: Start = {1}, End = {2}]", +// GetType().Name, StartPosition, EndPosition); +// } +// } } diff --git a/ICSharpCode.NRefactory.VB/Lexer/Special/PreProcessingDirective.cs b/ICSharpCode.NRefactory.VB/Lexer/Special/PreProcessingDirective.cs index 9d244528c..97c0a7481 100644 --- a/ICSharpCode.NRefactory.VB/Lexer/Special/PreProcessingDirective.cs +++ b/ICSharpCode.NRefactory.VB/Lexer/Special/PreProcessingDirective.cs @@ -6,151 +6,151 @@ using System.Collections.Generic; namespace ICSharpCode.NRefactory.VB { - public class PreprocessingDirective : AbstractSpecial - { - #region Conversion C# <-> VB - public static void VBToCSharp(IList list) - { - for (int i = 0; i < list.Count; ++i) { - if (list[i] is PreprocessingDirective) - list[i] = VBToCSharp((PreprocessingDirective)list[i]); - } - } - - public static PreprocessingDirective VBToCSharp(PreprocessingDirective dir) - { - string cmd = dir.Cmd; - string arg = dir.Arg; - if (cmd.Equals("#End", StringComparison.InvariantCultureIgnoreCase)) { - if (arg.ToLowerInvariant().StartsWith("region")) { - cmd = "#endregion"; - arg = ""; - } else if ("if".Equals(arg, StringComparison.InvariantCultureIgnoreCase)) { - cmd = "#endif"; - arg = ""; - } - } else if (cmd.Equals("#Region", StringComparison.InvariantCultureIgnoreCase)) { - cmd = "#region"; - } else if (cmd.Equals("#If", StringComparison.InvariantCultureIgnoreCase)) { - cmd = "#if"; - if (arg.ToLowerInvariant().EndsWith(" then")) - arg = arg.Substring(0, arg.Length - 5); - } else if (cmd.Equals("#Else", StringComparison.InvariantCultureIgnoreCase)) { - if (dir.Expression != null) - cmd = "#elif"; - else - cmd = "#else"; - } else if (cmd.Equals("#ElseIf", StringComparison.InvariantCultureIgnoreCase)) { - cmd = "#elif"; - } - return new PreprocessingDirective(cmd, arg, dir.StartPosition, dir.EndPosition) { - Expression = dir.Expression - }; - } - - public static void CSharpToVB(List list) - { - for (int i = 0; i < list.Count; ++i) { - if (list[i] is PreprocessingDirective) - list[i] = CSharpToVB((PreprocessingDirective)list[i]); - } - } - - public static PreprocessingDirective CSharpToVB(PreprocessingDirective dir) - { - string cmd = dir.Cmd; - string arg = dir.Arg; - switch (cmd) { - case "#region": - cmd = "#Region"; - if (!arg.StartsWith("\"")) { - arg = "\"" + arg.Trim() + "\""; - } - break; - case "#endregion": - cmd = "#End"; - arg = "Region"; - break; - case "#endif": - cmd = "#End"; - arg = "If"; - break; - case "#if": - arg += " Then"; - break; - } - if (cmd.Length > 1) { - cmd = cmd.Substring(0, 2).ToUpperInvariant() + cmd.Substring(2); - } - return new PreprocessingDirective(cmd, arg, dir.StartPosition, dir.EndPosition) { - Expression = dir.Expression - }; - } - #endregion - - string cmd; - string arg; - Ast.Expression expression = Ast.Expression.Null; - - /// - /// Gets the directive name, including '#'. - /// - public string Cmd { - get { - return cmd; - } - set { - cmd = value ?? string.Empty; - } - } - - /// - /// Gets the directive argument. - /// - public string Arg { - get { - return arg; - } - set { - arg = value ?? string.Empty; - } - } - - /// - /// Gets/sets the expression (for directives that take an expression, e.g. #if and #elif). - /// - public Ast.Expression Expression { - get { return expression; } - set { expression = value ?? Ast.Expression.Null; } - } - - /// - /// The end position of the pre processor directive line. - /// May be != EndPosition. - /// - public Location LastLineEnd { - get; - set; - } - - - public override string ToString() - { - return String.Format("[PreProcessingDirective: Cmd = {0}, Arg = {1}]", - Cmd, - Arg); - } - - public PreprocessingDirective(string cmd, string arg, Location start, Location end) - : base(start, end) - { - this.Cmd = cmd; - this.Arg = arg; - } - - public override object AcceptVisitor(ISpecialVisitor visitor, object data) - { - return visitor.Visit(this, data); - } - } +// public class PreprocessingDirective : AbstractSpecial +// { +// #region Conversion C# <-> VB +// public static void VBToCSharp(IList list) +// { +// for (int i = 0; i < list.Count; ++i) { +// if (list[i] is PreprocessingDirective) +// list[i] = VBToCSharp((PreprocessingDirective)list[i]); +// } +// } +// +// public static PreprocessingDirective VBToCSharp(PreprocessingDirective dir) +// { +// string cmd = dir.Cmd; +// string arg = dir.Arg; +// if (cmd.Equals("#End", StringComparison.InvariantCultureIgnoreCase)) { +// if (arg.ToLowerInvariant().StartsWith("region")) { +// cmd = "#endregion"; +// arg = ""; +// } else if ("if".Equals(arg, StringComparison.InvariantCultureIgnoreCase)) { +// cmd = "#endif"; +// arg = ""; +// } +// } else if (cmd.Equals("#Region", StringComparison.InvariantCultureIgnoreCase)) { +// cmd = "#region"; +// } else if (cmd.Equals("#If", StringComparison.InvariantCultureIgnoreCase)) { +// cmd = "#if"; +// if (arg.ToLowerInvariant().EndsWith(" then")) +// arg = arg.Substring(0, arg.Length - 5); +// } else if (cmd.Equals("#Else", StringComparison.InvariantCultureIgnoreCase)) { +// if (dir.Expression != null) +// cmd = "#elif"; +// else +// cmd = "#else"; +// } else if (cmd.Equals("#ElseIf", StringComparison.InvariantCultureIgnoreCase)) { +// cmd = "#elif"; +// } +// return new PreprocessingDirective(cmd, arg, dir.StartPosition, dir.EndPosition) { +// Expression = dir.Expression +// }; +// } +// +// public static void CSharpToVB(List list) +// { +// for (int i = 0; i < list.Count; ++i) { +// if (list[i] is PreprocessingDirective) +// list[i] = CSharpToVB((PreprocessingDirective)list[i]); +// } +// } +// +// public static PreprocessingDirective CSharpToVB(PreprocessingDirective dir) +// { +// string cmd = dir.Cmd; +// string arg = dir.Arg; +// switch (cmd) { +// case "#region": +// cmd = "#Region"; +// if (!arg.StartsWith("\"")) { +// arg = "\"" + arg.Trim() + "\""; +// } +// break; +// case "#endregion": +// cmd = "#End"; +// arg = "Region"; +// break; +// case "#endif": +// cmd = "#End"; +// arg = "If"; +// break; +// case "#if": +// arg += " Then"; +// break; +// } +// if (cmd.Length > 1) { +// cmd = cmd.Substring(0, 2).ToUpperInvariant() + cmd.Substring(2); +// } +// return new PreprocessingDirective(cmd, arg, dir.StartPosition, dir.EndPosition) { +// Expression = dir.Expression +// }; +// } +// #endregion +// +// string cmd; +// string arg; +// Ast.Expression expression = Ast.Expression.Null; +// +// /// +// /// Gets the directive name, including '#'. +// /// +// public string Cmd { +// get { +// return cmd; +// } +// set { +// cmd = value ?? string.Empty; +// } +// } +// +// /// +// /// Gets the directive argument. +// /// +// public string Arg { +// get { +// return arg; +// } +// set { +// arg = value ?? string.Empty; +// } +// } +// +// /// +// /// Gets/sets the expression (for directives that take an expression, e.g. #if and #elif). +// /// +// public Ast.Expression Expression { +// get { return expression; } +// set { expression = value ?? Ast.Expression.Null; } +// } +// +// /// +// /// The end position of the pre processor directive line. +// /// May be != EndPosition. +// /// +// public Location LastLineEnd { +// get; +// set; +// } +// +// +// public override string ToString() +// { +// return String.Format("[PreProcessingDirective: Cmd = {0}, Arg = {1}]", +// Cmd, +// Arg); +// } +// +// public PreprocessingDirective(string cmd, string arg, Location start, Location end) +// : base(start, end) +// { +// this.Cmd = cmd; +// this.Arg = arg; +// } +// +// public override object AcceptVisitor(ISpecialVisitor visitor, object data) +// { +// return visitor.Visit(this, data); +// } +// } } diff --git a/ICSharpCode.NRefactory.VB/Lexer/Special/SpecialTracker.cs b/ICSharpCode.NRefactory.VB/Lexer/Special/SpecialTracker.cs index b59f8c095..2107163e4 100644 --- a/ICSharpCode.NRefactory.VB/Lexer/Special/SpecialTracker.cs +++ b/ICSharpCode.NRefactory.VB/Lexer/Special/SpecialTracker.cs @@ -7,65 +7,65 @@ using System.Text; namespace ICSharpCode.NRefactory.VB.Parser { - public class SpecialTracker - { - List currentSpecials = new List(); - - CommentType currentCommentType; - StringBuilder sb = new StringBuilder(); - Location startPosition; - bool commentStartsLine; - - public List CurrentSpecials { - get { - return currentSpecials; - } - } - - /// - /// Gets the specials from the SpecialTracker and resets the lists. - /// - public List RetrieveSpecials() - { - List tmp = currentSpecials; - currentSpecials = new List(); - return tmp; - } - - public void AddEndOfLine(Location point) - { - currentSpecials.Add(new BlankLine(point)); - } - - public void AddPreprocessingDirective(PreprocessingDirective directive) - { - if (directive == null) - throw new ArgumentNullException("directive"); - currentSpecials.Add(directive); - } - - // used for comment tracking - public void StartComment(CommentType commentType, bool commentStartsLine, Location startPosition) - { - this.currentCommentType = commentType; - this.startPosition = startPosition; - this.sb.Length = 0; - this.commentStartsLine = commentStartsLine; - } - - public void AddChar(char c) - { - sb.Append(c); - } - - public void AddString(string s) - { - sb.Append(s); - } - - public void FinishComment(Location endPosition) - { - currentSpecials.Add(new Comment(currentCommentType, sb.ToString(), commentStartsLine, startPosition, endPosition)); - } - } +// public class SpecialTracker +// { +// List currentSpecials = new List(); +// +// CommentType currentCommentType; +// StringBuilder sb = new StringBuilder(); +// Location startPosition; +// bool commentStartsLine; +// +// public List CurrentSpecials { +// get { +// return currentSpecials; +// } +// } +// +// /// +// /// Gets the specials from the SpecialTracker and resets the lists. +// /// +// public List RetrieveSpecials() +// { +// List tmp = currentSpecials; +// currentSpecials = new List(); +// return tmp; +// } +// +// public void AddEndOfLine(Location point) +// { +// currentSpecials.Add(new BlankLine(point)); +// } +// +// public void AddPreprocessingDirective(PreprocessingDirective directive) +// { +// if (directive == null) +// throw new ArgumentNullException("directive"); +// currentSpecials.Add(directive); +// } +// +// // used for comment tracking +// public void StartComment(CommentType commentType, bool commentStartsLine, Location startPosition) +// { +// this.currentCommentType = commentType; +// this.startPosition = startPosition; +// this.sb.Length = 0; +// this.commentStartsLine = commentStartsLine; +// } +// +// public void AddChar(char c) +// { +// sb.Append(c); +// } +// +// public void AddString(string s) +// { +// sb.Append(s); +// } +// +// public void FinishComment(Location endPosition) +// { +// currentSpecials.Add(new Comment(currentCommentType, sb.ToString(), commentStartsLine, startPosition, endPosition)); +// } +// } } diff --git a/ICSharpCode.NRefactory.VB/Lexer/Special/TagComment.cs b/ICSharpCode.NRefactory.VB/Lexer/Special/TagComment.cs index 7023c1c66..3209cf162 100644 --- a/ICSharpCode.NRefactory.VB/Lexer/Special/TagComment.cs +++ b/ICSharpCode.NRefactory.VB/Lexer/Special/TagComment.cs @@ -8,22 +8,22 @@ namespace ICSharpCode.NRefactory.VB.Parser /// /// Description of TagComment. /// - public class TagComment : Comment - { - string tag; - - public string Tag { - get { - return tag; - } - set { - tag = value; - } - } - - public TagComment(string tag, string comment, bool commentStartsLine, Location startPosition, Location endPosition) : base(CommentType.SingleLine, comment, commentStartsLine, startPosition, endPosition) - { - this.tag = tag; - } - } +// public class TagComment : Comment +// { +// string tag; +// +// public string Tag { +// get { +// return tag; +// } +// set { +// tag = value; +// } +// } +// +// public TagComment(string tag, string comment, bool commentStartsLine, Location startPosition, Location endPosition) : base(CommentType.SingleLine, comment, commentStartsLine, startPosition, endPosition) +// { +// this.tag = tag; +// } +// } } diff --git a/ICSharpCode.NRefactory.VB/Lexer/Token.cs b/ICSharpCode.NRefactory.VB/Lexer/Token.cs index a67002b32..ae4ed7d63 100644 --- a/ICSharpCode.NRefactory.VB/Lexer/Token.cs +++ b/ICSharpCode.NRefactory.VB/Lexer/Token.cs @@ -5,18 +5,6 @@ using System; namespace ICSharpCode.NRefactory.VB.Parser { - public enum LiteralFormat : byte - { - None, - DecimalNumber, - HexadecimalNumber, - OctalNumber, - StringLiteral, - VerbatimStringLiteral, - CharLiteral, - DateTimeLiteral - } - public class Token { internal readonly int kind; @@ -24,20 +12,15 @@ namespace ICSharpCode.NRefactory.VB.Parser internal readonly int col; internal readonly int line; - internal readonly LiteralFormat literalFormat; internal readonly object literalValue; internal readonly string val; internal Token next; - readonly Location endLocation; + readonly AstLocation endLocation; public int Kind { get { return kind; } } - public LiteralFormat LiteralFormat { - get { return literalFormat; } - } - public object LiteralValue { get { return literalValue; } } @@ -46,13 +29,13 @@ namespace ICSharpCode.NRefactory.VB.Parser get { return val; } } - public Location EndLocation { + public AstLocation EndLocation { get { return endLocation; } } - public Location Location { + public AstLocation Location { get { - return new Location(col, line); + return new AstLocation(line, col); } } @@ -65,7 +48,7 @@ namespace ICSharpCode.NRefactory.VB.Parser { } - public Token(int kind, Location startLocation, Location endLocation) : this(kind, startLocation, endLocation, "", null, LiteralFormat.None) + public Token(int kind, AstLocation startLocation, AstLocation endLocation) : this(kind, startLocation, endLocation, "", null) { } @@ -75,15 +58,15 @@ namespace ICSharpCode.NRefactory.VB.Parser this.col = col; this.line = line; this.val = val; - this.endLocation = new Location(col + (val == null ? 1 : val.Length), line); + this.endLocation = new AstLocation(line, col + (val == null ? 1 : val.Length)); } - internal Token(int kind, int x, int y, string val, object literalValue, LiteralFormat literalFormat) - : this(kind, new Location(x, y), new Location(x + val.Length, y), val, literalValue, literalFormat) + internal Token(int kind, int x, int y, string val, object literalValue) + : this(kind, new AstLocation(y, x), new AstLocation(y, x + val.Length), val, literalValue) { } - public Token(int kind, Location startLocation, Location endLocation, string val, object literalValue, LiteralFormat literalFormat) + public Token(int kind, AstLocation startLocation, AstLocation endLocation, string val, object literalValue) { this.kind = kind; this.col = startLocation.Column; @@ -91,7 +74,6 @@ namespace ICSharpCode.NRefactory.VB.Parser this.endLocation = endLocation; this.val = val; this.literalValue = literalValue; - this.literalFormat = literalFormat; } public override string ToString() diff --git a/ICSharpCode.NRefactory.VB/Lexer/VBLexer.cs b/ICSharpCode.NRefactory.VB/Lexer/VBLexer.cs index 3944ba7cd..6aac502c2 100644 --- a/ICSharpCode.NRefactory.VB/Lexer/VBLexer.cs +++ b/ICSharpCode.NRefactory.VB/Lexer/VBLexer.cs @@ -34,7 +34,7 @@ namespace ICSharpCode.NRefactory.VB.Parser public VBLexer(TextReader reader, VBLexerMemento state) : this(reader) { - SetInitialLocation(new Location(state.Column, state.Line)); + SetInitialLocation(new AstLocation(state.Line, state.Column)); lastToken = new Token(state.PrevTokenKind, 0, 0); ef = new ExpressionFinder(state.ExpressionFinder); lineEnd = state.LineEnd; @@ -54,7 +54,7 @@ namespace ICSharpCode.NRefactory.VB.Parser unchecked { while (true) { - Location startLocation = new Location(Col, Line); + AstLocation startLocation = new AstLocation(Line, Col); int nextChar = ReaderRead(); if (nextChar == -1) return new Token(Tokens.EOF, Col, Line, string.Empty); @@ -96,12 +96,12 @@ namespace ICSharpCode.NRefactory.VB.Parser if (ReaderPeek() == '/') { ReaderRead(); info.inXmlCloseTag = true; - return new Token(Tokens.XmlOpenEndTag, new Location(x, y), new Location(Col, Line)); + return new Token(Tokens.XmlOpenEndTag, new AstLocation(y, x), new AstLocation(Line, Col)); } if (ReaderPeek() == '%' && ReaderPeek(1) == '=') { inXmlMode = false; ReaderRead(); ReaderRead(); - return new Token(Tokens.XmlStartInlineVB, new Location(x, y), new Location(Col, Line)); + return new Token(Tokens.XmlStartInlineVB, new AstLocation(y, x), new AstLocation(Line, Col)); } if (ReaderPeek() == '?') { ReaderRead(); @@ -122,7 +122,7 @@ namespace ICSharpCode.NRefactory.VB.Parser ReaderRead(); info.inXmlTag = false; info.level--; - return new Token(Tokens.XmlCloseTagEmptyElement, new Location(x, y), new Location(Col, Line)); + return new Token(Tokens.XmlCloseTagEmptyElement, new AstLocation(y, x), new AstLocation(Line, Col)); } break; case '>': @@ -135,7 +135,7 @@ namespace ICSharpCode.NRefactory.VB.Parser case '\'': case '"': string s = ReadXmlString(ch); - return new Token(Tokens.LiteralString, x, y, ch + s + ch, s, LiteralFormat.StringLiteral); + return new Token(Tokens.LiteralString, x, y, ch + s + ch, s); default: if (info.inXmlCloseTag || info.inXmlTag) { if (XmlConvert.IsWhitespaceChar(ch)) @@ -143,7 +143,7 @@ namespace ICSharpCode.NRefactory.VB.Parser return new Token(Tokens.Identifier, x, y, ReadXmlIdent(ch)); } else { string content = ReadXmlContent(ch); - return new Token(Tokens.XmlContent, startLocation, new Location(Col, Line), content, null, LiteralFormat.None); + return new Token(Tokens.XmlContent, startLocation, new AstLocation(Line, Col), content, null); } } #endregion @@ -154,10 +154,10 @@ namespace ICSharpCode.NRefactory.VB.Parser if (lineEnd) { // second line end before getting to a token // -> here was a blank line - specialTracker.AddEndOfLine(startLocation); +// specialTracker.AddEndOfLine(startLocation); } else { lineEnd = true; - return new Token(Tokens.EOL, startLocation, new Location(Col, Line), null, null, LiteralFormat.None); + return new Token(Tokens.EOL, startLocation, new AstLocation(Line, Col), null, null); } } continue; @@ -212,7 +212,7 @@ namespace ICSharpCode.NRefactory.VB.Parser } catch (Exception e) { errors.Error(Line, Col, String.Format("Invalid date time {0}", e)); } - return new Token(Tokens.LiteralDate, x, y, s, time, LiteralFormat.DateTimeLiteral); + return new Token(Tokens.LiteralDate, x, y, s, time); } else { ReadPreprocessorDirective(); continue; @@ -305,16 +305,16 @@ namespace ICSharpCode.NRefactory.VB.Parser if (s.Length == 0) { s = "\0"; } - return new Token(Tokens.LiteralCharacter, x, y, '"' + s + "\"C", s[0], LiteralFormat.CharLiteral); + return new Token(Tokens.LiteralCharacter, x, y, '"' + s + "\"C", s[0]); } - return new Token(Tokens.LiteralString, x, y, '"' + s + '"', s, LiteralFormat.StringLiteral); + return new Token(Tokens.LiteralString, x, y, '"' + s + '"', s); } if (ch == '%' && ReaderPeek() == '>') { int x = Col - 1; int y = Line; inXmlMode = true; ReaderRead(); - return new Token(Tokens.XmlEndInlineVB, new Location(x, y), new Location(Col, Line)); + return new Token(Tokens.XmlEndInlineVB, new AstLocation(y, x), new AstLocation(Line, Col)); } #endregion if (ch == '<' && (ef.NextTokenIsPotentialStartOfExpression || ef.NextTokenIsStartOfImportsOrAccessExpression)) { @@ -326,13 +326,13 @@ namespace ICSharpCode.NRefactory.VB.Parser if (ReaderPeek() == '/') { ReaderRead(); info.inXmlCloseTag = true; - return new Token(Tokens.XmlOpenEndTag, new Location(x, y), new Location(Col, Line)); + return new Token(Tokens.XmlOpenEndTag, new AstLocation(y, x), new AstLocation(Line, Col)); } // should we allow <%= at start of an expression? not valid with vbc ... if (ReaderPeek() == '%' && ReaderPeek(1) == '=') { inXmlMode = false; ReaderRead(); ReaderRead(); - return new Token(Tokens.XmlStartInlineVB, new Location(x, y), new Location(Col, Line)); + return new Token(Tokens.XmlStartInlineVB, new AstLocation(y, x), new AstLocation(Line, Col)); } if (ReaderPeek() == '!') { ReaderRead(); @@ -361,7 +361,7 @@ namespace ICSharpCode.NRefactory.VB.Parser } } - void CheckXMLState(Location startLocation) + void CheckXMLState(AstLocation startLocation) { if (inXmlMode && !xmlModeStack.Any()) throw new InvalidOperationException("invalid XML stack state at " + startLocation); @@ -563,7 +563,7 @@ namespace ICSharpCode.NRefactory.VB.Parser if (ch == '&') { errors.Error(Line, Col, String.Format("digit expected")); } - return new Token(Tokens.LiteralInteger, x, y, sb.ToString() ,ch - '0', LiteralFormat.DecimalNumber); + return new Token(Tokens.LiteralInteger, x, y, sb.ToString() ,ch - '0'); } if (ch == '.') { if (Char.IsDigit((char)ReaderPeek())) { @@ -603,7 +603,7 @@ namespace ICSharpCode.NRefactory.VB.Parser if (digit.Length == 0) { errors.Error(Line, Col, String.Format("digit expected")); - return new Token(Tokens.LiteralInteger, x, y, sb.ToString(), 0, LiteralFormat.DecimalNumber); + return new Token(Tokens.LiteralInteger, x, y, sb.ToString(), 0); } if (ReaderPeek() != -1 && "%&SILU".IndexOf(PeekUpperChar()) != -1 || isHex || isOct) { @@ -632,60 +632,59 @@ namespace ICSharpCode.NRefactory.VB.Parser } if (ch == 'S') { if (unsigned) - return new Token(Tokens.LiteralInteger, x, y, sb.ToString(), (ushort)number, LiteralFormat.OctalNumber); + return new Token(Tokens.LiteralInteger, x, y, sb.ToString(), (ushort)number); else - return new Token(Tokens.LiteralInteger, x, y, sb.ToString(), (short)number, LiteralFormat.OctalNumber); + return new Token(Tokens.LiteralInteger, x, y, sb.ToString(), (short)number); } else if (ch == '%' || ch == 'I') { if (unsigned) - return new Token(Tokens.LiteralInteger, x, y, sb.ToString(), (uint)number, LiteralFormat.OctalNumber); + return new Token(Tokens.LiteralInteger, x, y, sb.ToString(), (uint)number); else - return new Token(Tokens.LiteralInteger, x, y, sb.ToString(), (int)number, LiteralFormat.OctalNumber); + return new Token(Tokens.LiteralInteger, x, y, sb.ToString(), (int)number); } else if (ch == '&' || ch == 'L') { if (unsigned) - return new Token(Tokens.LiteralInteger, x, y, sb.ToString(), (ulong)number, LiteralFormat.OctalNumber); + return new Token(Tokens.LiteralInteger, x, y, sb.ToString(), (ulong)number); else - return new Token(Tokens.LiteralInteger, x, y, sb.ToString(), (long)number, LiteralFormat.OctalNumber); + return new Token(Tokens.LiteralInteger, x, y, sb.ToString(), (long)number); } else { if (number > uint.MaxValue) { - return new Token(Tokens.LiteralInteger, x, y, sb.ToString(), unchecked((long)number), LiteralFormat.OctalNumber); + return new Token(Tokens.LiteralInteger, x, y, sb.ToString(), unchecked((long)number)); } else { - return new Token(Tokens.LiteralInteger, x, y, sb.ToString(), unchecked((int)number), LiteralFormat.OctalNumber); + return new Token(Tokens.LiteralInteger, x, y, sb.ToString(), unchecked((int)number)); } } } - LiteralFormat literalFormat = isHex ? LiteralFormat.HexadecimalNumber : LiteralFormat.DecimalNumber; if (ch == 'S') { ReaderRead(); if (unsigned) - return new Token(Tokens.LiteralInteger, x, y, sb.ToString(), UInt16.Parse(digit, isHex ? NumberStyles.HexNumber : NumberStyles.Number), literalFormat); + return new Token(Tokens.LiteralInteger, x, y, sb.ToString(), UInt16.Parse(digit, isHex ? NumberStyles.HexNumber : NumberStyles.Number)); else - return new Token(Tokens.LiteralInteger, x, y, sb.ToString(), Int16.Parse(digit, isHex ? NumberStyles.HexNumber : NumberStyles.Number), literalFormat); + return new Token(Tokens.LiteralInteger, x, y, sb.ToString(), Int16.Parse(digit, isHex ? NumberStyles.HexNumber : NumberStyles.Number)); } else if (ch == '%' || ch == 'I') { ReaderRead(); if (unsigned) - return new Token(Tokens.LiteralInteger, x, y, sb.ToString(), UInt32.Parse(digit, isHex ? NumberStyles.HexNumber : NumberStyles.Number), literalFormat); + return new Token(Tokens.LiteralInteger, x, y, sb.ToString(), UInt32.Parse(digit, isHex ? NumberStyles.HexNumber : NumberStyles.Number)); else - return new Token(Tokens.LiteralInteger, x, y, sb.ToString(), Int32.Parse(digit, isHex ? NumberStyles.HexNumber : NumberStyles.Number), literalFormat); + return new Token(Tokens.LiteralInteger, x, y, sb.ToString(), Int32.Parse(digit, isHex ? NumberStyles.HexNumber : NumberStyles.Number)); } else if (ch == '&' || ch == 'L') { ReaderRead(); if (unsigned) - return new Token(Tokens.LiteralInteger, x, y, sb.ToString(), UInt64.Parse(digit, isHex ? NumberStyles.HexNumber : NumberStyles.Number), literalFormat); + return new Token(Tokens.LiteralInteger, x, y, sb.ToString(), UInt64.Parse(digit, isHex ? NumberStyles.HexNumber : NumberStyles.Number)); else - return new Token(Tokens.LiteralInteger, x, y, sb.ToString(), Int64.Parse(digit, isHex ? NumberStyles.HexNumber : NumberStyles.Number), literalFormat); + return new Token(Tokens.LiteralInteger, x, y, sb.ToString(), Int64.Parse(digit, isHex ? NumberStyles.HexNumber : NumberStyles.Number)); } else if (isHex) { ulong number = UInt64.Parse(digit, NumberStyles.HexNumber); if (number > uint.MaxValue) { - return new Token(Tokens.LiteralInteger, x, y, sb.ToString(), unchecked((long)number), literalFormat); + return new Token(Tokens.LiteralInteger, x, y, sb.ToString(), unchecked((long)number)); } else { - return new Token(Tokens.LiteralInteger, x, y, sb.ToString(), unchecked((int)number), literalFormat); + return new Token(Tokens.LiteralInteger, x, y, sb.ToString(), unchecked((int)number)); } } } catch (OverflowException ex) { errors.Error(Line, Col, ex.Message); - return new Token(Tokens.LiteralInteger, x, y, sb.ToString(), 0, LiteralFormat.None); + return new Token(Tokens.LiteralInteger, x, y, sb.ToString(), 0); } catch (FormatException) { errors.Error(Line, Col, String.Format("{0} is not a parseable number", digit)); - return new Token(Tokens.LiteralInteger, x, y, sb.ToString(), 0, LiteralFormat.None); + return new Token(Tokens.LiteralInteger, x, y, sb.ToString(), 0); } } Token nextToken = null; // if we accidently read a 'dot' @@ -738,37 +737,37 @@ namespace ICSharpCode.NRefactory.VB.Parser try { if (isSingle) { - return new Token(Tokens.LiteralSingle, x, y, sb.ToString(), Single.Parse(digit, CultureInfo.InvariantCulture), LiteralFormat.DecimalNumber); + return new Token(Tokens.LiteralSingle, x, y, sb.ToString(), Single.Parse(digit, CultureInfo.InvariantCulture)); } if (isDecimal) { - return new Token(Tokens.LiteralDecimal, x, y, sb.ToString(), Decimal.Parse(digit, NumberStyles.Currency | NumberStyles.AllowExponent, CultureInfo.InvariantCulture), LiteralFormat.DecimalNumber); + return new Token(Tokens.LiteralDecimal, x, y, sb.ToString(), Decimal.Parse(digit, NumberStyles.Currency | NumberStyles.AllowExponent, CultureInfo.InvariantCulture)); } if (isDouble) { - return new Token(Tokens.LiteralDouble, x, y, sb.ToString(), Double.Parse(digit, CultureInfo.InvariantCulture), LiteralFormat.DecimalNumber); + return new Token(Tokens.LiteralDouble, x, y, sb.ToString(), Double.Parse(digit, CultureInfo.InvariantCulture)); } } catch (FormatException) { errors.Error(Line, Col, String.Format("{0} is not a parseable number", digit)); if (isSingle) - return new Token(Tokens.LiteralSingle, x, y, sb.ToString(), 0f, LiteralFormat.DecimalNumber); + return new Token(Tokens.LiteralSingle, x, y, sb.ToString(), 0f); if (isDecimal) - return new Token(Tokens.LiteralDecimal, x, y, sb.ToString(), 0m, LiteralFormat.DecimalNumber); + return new Token(Tokens.LiteralDecimal, x, y, sb.ToString(), 0m); if (isDouble) - return new Token(Tokens.LiteralDouble, x, y, sb.ToString(), 0.0, LiteralFormat.DecimalNumber); + return new Token(Tokens.LiteralDouble, x, y, sb.ToString(), 0.0); } Token token; try { - token = new Token(Tokens.LiteralInteger, x, y, sb.ToString(), Int32.Parse(digit, isHex ? NumberStyles.HexNumber : NumberStyles.Number), isHex ? LiteralFormat.HexadecimalNumber : LiteralFormat.DecimalNumber); + token = new Token(Tokens.LiteralInteger, x, y, sb.ToString(), Int32.Parse(digit, isHex ? NumberStyles.HexNumber : NumberStyles.Number)); } catch (Exception) { try { - token = new Token(Tokens.LiteralInteger, x, y, sb.ToString(), Int64.Parse(digit, isHex ? NumberStyles.HexNumber : NumberStyles.Number), isHex ? LiteralFormat.HexadecimalNumber : LiteralFormat.DecimalNumber); + token = new Token(Tokens.LiteralInteger, x, y, sb.ToString(), Int64.Parse(digit, isHex ? NumberStyles.HexNumber : NumberStyles.Number)); } catch (FormatException) { errors.Error(Line, Col, String.Format("{0} is not a parseable number", digit)); // fallback, when nothing helps :) - token = new Token(Tokens.LiteralInteger, x, y, sb.ToString(), 0, LiteralFormat.DecimalNumber); + token = new Token(Tokens.LiteralInteger, x, y, sb.ToString(), 0); } catch (OverflowException) { errors.Error(Line, Col, String.Format("{0} is too long for a integer literal", digit)); // fallback, when nothing helps :) - token = new Token(Tokens.LiteralInteger, x, y, sb.ToString(), 0, LiteralFormat.DecimalNumber); + token = new Token(Tokens.LiteralInteger, x, y, sb.ToString(), 0); } } token.next = nextToken; @@ -777,12 +776,12 @@ namespace ICSharpCode.NRefactory.VB.Parser void ReadPreprocessorDirective() { - Location start = new Location(Col - 1, Line); + AstLocation start = new AstLocation(Line, Col - 1); string directive = ReadIdent('#'); // TODO : expression parser for PP directives // needed for proper conversion to e. g. C# string argument = ReadToEndOfLine(); - this.specialTracker.AddPreprocessingDirective(new PreprocessingDirective(directive, argument.Trim(), start, new Location(start.Column + directive.Length + argument.Length, start.Line))); +// this.specialTracker.AddPreprocessingDirective(new PreprocessingDirective(directive, argument.Trim(), start, new AstLocation(start.Line, start.Column + directive.Length + argument.Length))); } string ReadDate() @@ -834,7 +833,7 @@ namespace ICSharpCode.NRefactory.VB.Parser void ReadComment() { - Location startPos = new Location(Col, Line); + AstLocation startPos = new AstLocation(Line, Col); sb.Length = 0; StringBuilder curWord = specialCommentHash != null ? new StringBuilder() : null; int missingApostrophes = 2; // no. of ' missing until it is a documentation comment @@ -851,11 +850,11 @@ namespace ICSharpCode.NRefactory.VB.Parser if (missingApostrophes > 0) { if (ch == '\'' || ch == '\u2018' || ch == '\u2019') { if (--missingApostrophes == 0) { - specialTracker.StartComment(CommentType.Documentation, isAtLineBegin, startPos); +// specialTracker.StartComment(CommentType.Documentation, isAtLineBegin, startPos); sb.Length = 0; } } else { - specialTracker.StartComment(CommentType.SingleLine, isAtLineBegin, startPos); +// specialTracker.StartComment(CommentType.SingleLine, isAtLineBegin, startPos); missingApostrophes = 0; } } @@ -867,20 +866,20 @@ namespace ICSharpCode.NRefactory.VB.Parser string tag = curWord.ToString(); curWord.Length = 0; if (specialCommentHash.ContainsKey(tag)) { - Location p = new Location(Col, Line); + AstLocation p = new AstLocation(Line, Col); string comment = ch + ReadToEndOfLine(); - this.TagComments.Add(new TagComment(tag, comment, isAtLineBegin, p, new Location(Col, Line))); +// this.TagComments.Add(new TagComment(tag, comment, isAtLineBegin, p, new Location(Col, Line))); sb.Append(comment); break; } } } } - if (missingApostrophes > 0) { - specialTracker.StartComment(CommentType.SingleLine, isAtLineBegin, startPos); - } - specialTracker.AddString(sb.ToString()); - specialTracker.FinishComment(new Location(Col, Line)); +// if (missingApostrophes > 0) { +// specialTracker.StartComment(CommentType.SingleLine, isAtLineBegin, startPos); +// } +// specialTracker.AddString(sb.ToString()); +// specialTracker.FinishComment(new Location(Col, Line)); } Token ReadOperator(char ch) @@ -1047,7 +1046,7 @@ namespace ICSharpCode.NRefactory.VB.Parser ReaderSkip("?>".Length); - return new Token(Tokens.XmlProcessingInstruction, new Location(x, y), new Location(Col, Line), sb.ToString(), null, LiteralFormat.None); + return new Token(Tokens.XmlProcessingInstruction, new AstLocation(y, x), new AstLocation(Line, Col), sb.ToString(), null); } Token ReadXmlCommentOrCData(int x, int y) @@ -1061,7 +1060,7 @@ namespace ICSharpCode.NRefactory.VB.Parser sb.Append((char)nextChar); if (string.CompareOrdinal(ReaderPeekString("-->".Length), "-->") == 0) { ReaderSkip("-->".Length); - return new Token(Tokens.XmlComment, new Location(x, y), new Location(Col, Line), sb.ToString(), null, LiteralFormat.None); + return new Token(Tokens.XmlComment, new AstLocation(y, x), new AstLocation(Line, Col), sb.ToString(), null); } } } @@ -1072,12 +1071,12 @@ namespace ICSharpCode.NRefactory.VB.Parser sb.Append((char)nextChar); if (string.CompareOrdinal(ReaderPeekString("]]>".Length), "]]>") == 0) { ReaderSkip("]]>".Length); - return new Token(Tokens.XmlCData, new Location(x, y), new Location(Col, Line), sb.ToString(), null, LiteralFormat.None); + return new Token(Tokens.XmlCData, new AstLocation(y, x), new AstLocation(Line, Col), sb.ToString(), null); } } } - return new Token(Tokens.XmlComment, new Location(x, y), new Location(Col, Line), sb.ToString(), null, LiteralFormat.None); + return new Token(Tokens.XmlComment, new AstLocation(y, x), new AstLocation(Line, Col), sb.ToString(), null); } string ReadXmlContent(char ch) @@ -1188,9 +1187,9 @@ namespace ICSharpCode.NRefactory.VB.Parser string[] specialCommentTags = null; protected Hashtable specialCommentHash = null; - List tagComments = new List(); +// List tagComments = new List(); protected StringBuilder sb = new StringBuilder(); - protected SpecialTracker specialTracker = new SpecialTracker(); +// protected SpecialTracker specialTracker = new SpecialTracker(); // used for the original value of strings (with escape sequences). protected StringBuilder originalValue = new StringBuilder(); @@ -1277,7 +1276,7 @@ namespace ICSharpCode.NRefactory.VB.Parser return builder.ToString(); } - public void SetInitialLocation(Location location) + public void SetInitialLocation(AstLocation location) { if (lastToken != null || curToken != null || peekToken != null) throw new InvalidOperationException(); @@ -1294,17 +1293,17 @@ namespace ICSharpCode.NRefactory.VB.Parser /// /// Returns the comments that had been read and containing tag key words. /// - public List TagComments { - get { - return tagComments; - } - } +// public List TagComments { +// get { +// return tagComments; +// } +// } - public SpecialTracker SpecialTracker { - get { - return specialTracker; - } - } +// public SpecialTracker SpecialTracker { +// get { +// return specialTracker; +// } +// } /// /// Special comment tags are tags like TODO, HACK or UNDONE which are read by the lexer and stored in . @@ -1353,7 +1352,6 @@ namespace ICSharpCode.NRefactory.VB.Parser errors = null; lastToken = curToken = peekToken = null; specialCommentHash = null; - tagComments = null; sb = originalValue = null; } #endregion @@ -1406,12 +1404,12 @@ namespace ICSharpCode.NRefactory.VB.Parser errors.Error(line, col, String.Format("Invalid hex number '" + digit + "'")); return 0; } - protected Location lastLineEnd = new Location (1, 1); - protected Location curLineEnd = new Location (1, 1); + protected AstLocation lastLineEnd = new AstLocation(1, 1); + protected AstLocation curLineEnd = new AstLocation(1, 1); protected void LineBreak () { lastLineEnd = curLineEnd; - curLineEnd = new Location (col - 1, line); + curLineEnd = new AstLocation (line, col - 1); } protected bool HandleLineEnd(char ch) { diff --git a/ICSharpCode.NRefactory.VB/Location.cs b/ICSharpCode.NRefactory.VB/Location.cs deleted file mode 100644 index 825207f05..000000000 --- a/ICSharpCode.NRefactory.VB/Location.cs +++ /dev/null @@ -1,121 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using System; - -namespace ICSharpCode.NRefactory.VB -{ - /// - /// A line/column position. - /// NRefactory lines/columns are counting from one. - /// - public struct Location : IComparable, IEquatable - { - public static readonly Location Empty = new Location(-1, -1); - - public Location(int column, int line) - { - x = column; - y = line; - } - - int x, y; - - public int X { - get { return x; } - set { x = value; } - } - - public int Y { - get { return y; } - set { y = value; } - } - - public int Line { - get { return y; } - set { y = value; } - } - - public int Column { - get { return x; } - set { x = value; } - } - - public bool IsEmpty { - get { - return x <= 0 && y <= 0; - } - } - - public override string ToString() - { - return string.Format("(Line {1}, Col {0})", this.x, this.y); - } - - public override int GetHashCode() - { - return unchecked (87 * x.GetHashCode() ^ y.GetHashCode()); - } - - public override bool Equals(object obj) - { - if (!(obj is Location)) return false; - return (Location)obj == this; - } - - public bool Equals(Location other) - { - return this == other; - } - - public static bool operator ==(Location a, Location b) - { - return a.x == b.x && a.y == b.y; - } - - public static bool operator !=(Location a, Location b) - { - return a.x != b.x || a.y != b.y; - } - - public static bool operator <(Location a, Location b) - { - if (a.y < b.y) - return true; - else if (a.y == b.y) - return a.x < b.x; - else - return false; - } - - public static bool operator >(Location a, Location b) - { - if (a.y > b.y) - return true; - else if (a.y == b.y) - return a.x > b.x; - else - return false; - } - - public static bool operator <=(Location a, Location b) - { - return !(a > b); - } - - public static bool operator >=(Location a, Location b) - { - return !(a < b); - } - - public int CompareTo(Location other) - { - if (this == other) - return 0; - if (this < other) - return -1; - else - return 1; - } - } -} diff --git a/ICSharpCode.NRefactory.VB/OperatorPrecedence.cs b/ICSharpCode.NRefactory.VB/OperatorPrecedence.cs deleted file mode 100644 index 833802ffd..000000000 --- a/ICSharpCode.NRefactory.VB/OperatorPrecedence.cs +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using System; -using System.Collections.Generic; -using ICSharpCode.NRefactory.VB.Ast; - -namespace ICSharpCode.NRefactory.VB -{ - /// - /// Stores the operator precedences for the output visitor. - /// - static class OperatorPrecedence - { - static readonly Dictionary vbDict = MakePrecedenceTable( - new BinaryOperatorType[] { BinaryOperatorType.Power }, - new BinaryOperatorType[] { BinaryOperatorType.Multiply, BinaryOperatorType.Divide }, - new BinaryOperatorType[] { BinaryOperatorType.DivideInteger }, - new BinaryOperatorType[] { BinaryOperatorType.Modulus }, - new BinaryOperatorType[] { BinaryOperatorType.Add, BinaryOperatorType.Subtract }, - new BinaryOperatorType[] { BinaryOperatorType.Concat }, - new BinaryOperatorType[] { BinaryOperatorType.ShiftLeft, BinaryOperatorType.ShiftRight }, - new BinaryOperatorType[] { - BinaryOperatorType.Equality, BinaryOperatorType.InEquality, - BinaryOperatorType.LessThan, BinaryOperatorType.LessThanOrEqual, - BinaryOperatorType.GreaterThan, BinaryOperatorType.GreaterThanOrEqual, - BinaryOperatorType.ReferenceEquality, BinaryOperatorType.ReferenceInequality, - BinaryOperatorType.Like - }, - new BinaryOperatorType[] { BinaryOperatorType.LogicalAnd, BinaryOperatorType.BitwiseAnd }, - new BinaryOperatorType[] { BinaryOperatorType.LogicalOr, BinaryOperatorType.BitwiseOr }, - new BinaryOperatorType[] { BinaryOperatorType.ExclusiveOr } - ); - - static readonly Dictionary csharpDict = MakePrecedenceTable( - new BinaryOperatorType[] { BinaryOperatorType.Multiply, BinaryOperatorType.Divide, BinaryOperatorType.Modulus }, - new BinaryOperatorType[] { BinaryOperatorType.Add, BinaryOperatorType.Subtract }, - new BinaryOperatorType[] { BinaryOperatorType.ShiftLeft, BinaryOperatorType.ShiftRight }, - new BinaryOperatorType[] { - BinaryOperatorType.LessThan, BinaryOperatorType.LessThanOrEqual, - BinaryOperatorType.GreaterThan, BinaryOperatorType.GreaterThanOrEqual, - }, - new BinaryOperatorType[] { BinaryOperatorType.Equality, BinaryOperatorType.InEquality }, - new BinaryOperatorType[] { BinaryOperatorType.BitwiseAnd }, - new BinaryOperatorType[] { BinaryOperatorType.ExclusiveOr }, - new BinaryOperatorType[] { BinaryOperatorType.BitwiseOr }, - new BinaryOperatorType[] { BinaryOperatorType.LogicalAnd, BinaryOperatorType.LogicalOr }, - new BinaryOperatorType[] { BinaryOperatorType.NullCoalescing } - ); - - // create a dictionary operator->precedence (higher value = higher precedence) - static Dictionary MakePrecedenceTable(params BinaryOperatorType[][] input) - { - Dictionary dict = new Dictionary(); - for (int i = 0; i < input.Length; i++) { - foreach (BinaryOperatorType op in input[i]) { - dict.Add(op, input.Length - i); - } - } - return dict; - } - - public static int ComparePrecedenceVB(BinaryOperatorType op1, BinaryOperatorType op2) - { - int p1 = GetOperatorPrecedence(vbDict, op1); - int p2 = GetOperatorPrecedence(vbDict, op2); - return p1.CompareTo(p2); - } - - public static int ComparePrecedenceCSharp(BinaryOperatorType op1, BinaryOperatorType op2) - { - int p1 = GetOperatorPrecedence(csharpDict, op1); - int p2 = GetOperatorPrecedence(csharpDict, op2); - return p1.CompareTo(p2); - } - - static int GetOperatorPrecedence(Dictionary dict, BinaryOperatorType op) - { - int p; - dict.TryGetValue(op, out p); - return p; - } - } -} diff --git a/ICSharpCode.NRefactory.VB/OutputVisitor/IOutputFormatter.cs b/ICSharpCode.NRefactory.VB/OutputVisitor/IOutputFormatter.cs new file mode 100644 index 000000000..a544eb0d0 --- /dev/null +++ b/ICSharpCode.NRefactory.VB/OutputVisitor/IOutputFormatter.cs @@ -0,0 +1,39 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) + +using System; + +namespace ICSharpCode.NRefactory.VB +{ + /// + /// Output formatter for the Output visitor. + /// + public interface IOutputFormatter + { + void StartNode(AstNode node); + void EndNode(AstNode node); + + /// + /// Writes an identifier. + /// If the identifier conflicts with a keyword, the output visitor will + /// call WriteToken("@") before calling WriteIdentifier(). + /// + void WriteIdentifier(string identifier); + + /// + /// Writes a keyword to the output. + /// + void WriteKeyword(string keyword); + + /// + /// Writes a token to the output. + /// + void WriteToken(string token); + void Space(); + + void Indent(); + void Unindent(); + + void NewLine(); + } +} diff --git a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs new file mode 100644 index 000000000..f4085b6bc --- /dev/null +++ b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs @@ -0,0 +1,222 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; +using System.Collections.Generic; +using System.IO; + +using ICSharpCode.NRefactory.PatternMatching; +using ICSharpCode.NRefactory.VB.Ast; + +namespace ICSharpCode.NRefactory.VB +{ + /// + /// Description of OutputVisitor. + /// + public class OutputVisitor : IAstVisitor, IPatternAstVisitor + { + readonly IOutputFormatter formatter; + readonly VBFormattingOptions policy; + + readonly Stack containerStack = new Stack(); + readonly Stack positionStack = new Stack(); + + public OutputVisitor(TextWriter textWriter, VBFormattingOptions formattingPolicy) + { + if (textWriter == null) + throw new ArgumentNullException("textWriter"); + if (formattingPolicy == null) + throw new ArgumentNullException("formattingPolicy"); + this.formatter = new TextWriterOutputFormatter(textWriter); + this.policy = formattingPolicy; + } + + public OutputVisitor(IOutputFormatter formatter, VBFormattingOptions formattingPolicy) + { + if (formatter == null) + throw new ArgumentNullException("formatter"); + if (formattingPolicy == null) + throw new ArgumentNullException("formattingPolicy"); + this.formatter = formatter; + this.policy = formattingPolicy; + } + + public object VisitCompilationUnit(ICSharpCode.NRefactory.VB.Ast.CompilationUnit compilationUnit, object data) + { + // don't do node tracking as we visit all children directly + foreach (AstNode node in compilationUnit.Children) + node.AcceptVisitor(this, data); + return null; + } + + public object VisitBlockStatement(BlockStatement blockStatement, object data) + { + throw new NotImplementedException(); + } + + public object VisitPatternPlaceholder(AstNode placeholder, Pattern pattern, object data) + { + throw new NotImplementedException(); + } + + public object VisitTypeParameterDeclaration(TypeParameterDeclaration typeParameterDeclaration, object data) + { + throw new NotImplementedException(); + } + + public object VisitParameterDeclaration(ParameterDeclaration parameterDeclaration, object data) + { + throw new NotImplementedException(); + } + + public object VisitVBTokenNode(VBTokenNode vBTokenNode, object data) + { + throw new NotImplementedException(); + } + + public object VisitAliasImportsClause(AliasImportsClause aliasImportsClause, object data) + { + throw new NotImplementedException(); + } + + public object VisitAttribute(ICSharpCode.NRefactory.VB.Ast.Attribute attribute, object data) + { + throw new NotImplementedException(); + } + + public object VisitAttributeBlock(AttributeBlock attributeBlock, object data) + { + throw new NotImplementedException(); + } + + public object VisitImportsStatement(ImportsStatement importsStatement, object data) + { + throw new NotImplementedException(); + } + + public object VisitMembersImportsClause(MemberImportsClause membersImportsClause, object data) + { + throw new NotImplementedException(); + } + + public object VisitNamespaceDeclaration(NamespaceDeclaration namespaceDeclaration, object data) + { + throw new NotImplementedException(); + } + + public object VisitOptionStatement(OptionStatement optionStatement, object data) + { + throw new NotImplementedException(); + } + + public object VisitTypeDeclaration(TypeDeclaration typeDeclaration, object data) + { + throw new NotImplementedException(); + } + + public object VisitXmlNamespaceImportsClause(XmlNamespaceImportsClause xmlNamespaceImportsClause, object data) + { + throw new NotImplementedException(); + } + + public object VisitEnumDeclaration(EnumDeclaration enumDeclaration, object data) + { + throw new NotImplementedException(); + } + + public object VisitEnumMemberDeclaration(EnumMemberDeclaration enumMemberDeclaration, object data) + { + throw new NotImplementedException(); + } + + public object VisitDelegateDeclaration(DelegateDeclaration delegateDeclaration, object data) + { + throw new NotImplementedException(); + } + + public object VisitIdentifier(Identifier identifier, object data) + { + throw new NotImplementedException(); + } + + public object VisitXmlIdentifier(XmlIdentifier xmlIdentifier, object data) + { + throw new NotImplementedException(); + } + + public object VisitXmlLiteralString(XmlLiteralString xmlLiteralString, object data) + { + throw new NotImplementedException(); + } + + public object VisitSimpleNameExpression(SimpleNameExpression identifierExpression, object data) + { + throw new NotImplementedException(); + } + + public object VisitPrimitiveExpression(PrimitiveExpression primitiveExpression, object data) + { + throw new NotImplementedException(); + } + + public object VisitPrimitiveType(PrimitiveType primitiveType, object data) + { + throw new NotImplementedException(); + } + + public object VisitQualifiedType(QualifiedType qualifiedType, object data) + { + throw new NotImplementedException(); + } + + public object VisitComposedType(ComposedType composedType, object data) + { + throw new NotImplementedException(); + } + + public object VisitArraySpecifier(ArraySpecifier arraySpecifier, object data) + { + throw new NotImplementedException(); + } + + public object VisitSimpleType(SimpleType simpleType, object data) + { + throw new NotImplementedException(); + } + + public object VisitAnyNode(AnyNode anyNode, object data) + { + throw new NotImplementedException(); + } + + public object VisitBackreference(Backreference backreference, object data) + { + throw new NotImplementedException(); + } + + public object VisitChoice(Choice choice, object data) + { + throw new NotImplementedException(); + } + + public object VisitNamedNode(NamedNode namedNode, object data) + { + throw new NotImplementedException(); + } + + public object VisitRepeat(Repeat repeat, object data) + { + throw new NotImplementedException(); + } + + public object VisitOptionalNode(OptionalNode optionalNode, object data) + { + throw new NotImplementedException(); + } + + public object VisitIdentifierExpressionBackreference(IdentifierExpressionBackreference identifierExpressionBackreference, object data) + { + throw new NotImplementedException(); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/OutputVisitor/TextWriterOutputFormatter.cs b/ICSharpCode.NRefactory.VB/OutputVisitor/TextWriterOutputFormatter.cs new file mode 100644 index 000000000..cc2df64ed --- /dev/null +++ b/ICSharpCode.NRefactory.VB/OutputVisitor/TextWriterOutputFormatter.cs @@ -0,0 +1,83 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) + +using System; +using System.IO; + +namespace ICSharpCode.NRefactory.VB +{ + /// + /// Writes VB code into a TextWriter. + /// + public class TextWriterOutputFormatter : IOutputFormatter + { + readonly TextWriter textWriter; + int indentation; + bool needsIndent = true; + + public TextWriterOutputFormatter(TextWriter textWriter) + { + if (textWriter == null) + throw new ArgumentNullException("textWriter"); + this.textWriter = textWriter; + } + + public void WriteIdentifier(string ident) + { + WriteIndentation(); + textWriter.Write(ident); + } + + public void WriteKeyword(string keyword) + { + WriteIndentation(); + textWriter.Write(keyword); + } + + public void WriteToken(string token) + { + WriteIndentation(); + textWriter.Write(token); + } + + public void Space() + { + WriteIndentation(); + textWriter.Write(' '); + } + + void WriteIndentation() + { + if (needsIndent) { + needsIndent = false; + for (int i = 0; i < indentation; i++) { + textWriter.Write('\t'); + } + } + } + + public void NewLine() + { + textWriter.WriteLine(); + needsIndent = true; + } + + public void Indent() + { + indentation++; + } + + public void Unindent() + { + indentation--; + } + + public virtual void StartNode(AstNode node) + { + } + + public virtual void EndNode(AstNode node) + { + } + } +} diff --git a/ICSharpCode.NRefactory.VB/OutputVisitor/VBFormattingOptions.cs b/ICSharpCode.NRefactory.VB/OutputVisitor/VBFormattingOptions.cs new file mode 100644 index 000000000..8888bf2ff --- /dev/null +++ b/ICSharpCode.NRefactory.VB/OutputVisitor/VBFormattingOptions.cs @@ -0,0 +1,17 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; + +namespace ICSharpCode.NRefactory.VB +{ + /// + /// Description of VBFormattingOptions. + /// + public class VBFormattingOptions + { + public VBFormattingOptions() + { + } + } +} diff --git a/ICSharpCode.NRefactory.VB/Parser/ModifierList.cs b/ICSharpCode.NRefactory.VB/Parser/ModifierList.cs deleted file mode 100644 index 7acfedbae..000000000 --- a/ICSharpCode.NRefactory.VB/Parser/ModifierList.cs +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using ICSharpCode.NRefactory.VB.Ast; - -namespace ICSharpCode.NRefactory.VB.Parser -{ - internal class ModifierList - { - Modifiers cur; - Location location = new Location(-1, -1); - - public Modifiers Modifier { - get { - return cur; - } - } - - public Location GetDeclarationLocation(Location keywordLocation) - { - if(location.IsEmpty) { - return keywordLocation; - } - return location; - } - -// public Location Location { -// get { -// return location; -// } -// set { -// location = value; -// } -// } - - public bool isNone { get { return cur == Modifiers.None; } } - - public bool Contains(Modifiers m) - { - return ((cur & m) != 0); - } - - public void Add(Modifiers m, Location tokenLocation) - { - if(location.IsEmpty) { - location = tokenLocation; - } - - if ((cur & m) == 0) { - cur |= m; - } else { -// parser.Error("modifier " + m + " already defined"); - } - } - -// public void Add(Modifiers m) -// { -// Add(m.cur, m.Location); -// } - - public void Check(Modifiers allowed) - { - Modifiers wrong = cur & ~allowed; - if (wrong != Modifiers.None) { -// parser.Error("modifier(s) " + wrong + " not allowed here"); - } - } - } -} diff --git a/ICSharpCode.NRefactory.VB/Parser/ParamModifierList.cs b/ICSharpCode.NRefactory.VB/Parser/ParamModifierList.cs deleted file mode 100644 index f9a6c6dd9..000000000 --- a/ICSharpCode.NRefactory.VB/Parser/ParamModifierList.cs +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using ICSharpCode.NRefactory.VB.Ast; - -namespace ICSharpCode.NRefactory.VB.Parser -{ - internal class ParamModifierList - { - ParameterModifiers cur; - VBParser parser; - - public ParameterModifiers Modifier { - get { - return cur; - } - } - - public ParamModifierList(VBParser parser) - { - this.parser = parser; - cur = ParameterModifiers.None; - } - - public bool isNone { get { return cur == ParameterModifiers.None; } } - - public void Add(ParameterModifiers m) - { - if ((cur & m) == 0) { - cur |= m; - } else { - parser.Error("param modifier " + m + " already defined"); - } - } - - public void Add(ParamModifierList m) - { - Add(m.cur); - } - - public void Check() - { - if((cur & ParameterModifiers.In) != 0 && - (cur & ParameterModifiers.Ref) != 0) { - parser.Error("ByRef and ByVal are not allowed at the same time."); - } - } - } -} diff --git a/ICSharpCode.NRefactory.VB/Parser/Parser.cs b/ICSharpCode.NRefactory.VB/Parser/Parser.cs index 88ff84b89..1b2b8d939 100644 --- a/ICSharpCode.NRefactory.VB/Parser/Parser.cs +++ b/ICSharpCode.NRefactory.VB/Parser/Parser.cs @@ -7,6 +7,7 @@ using System.Text; using ICSharpCode.NRefactory.VB.Ast; using ICSharpCode.NRefactory.VB.Parser; using ASTAttribute = ICSharpCode.NRefactory.VB.Ast.Attribute; +using Roles = ICSharpCode.NRefactory.VB.AstNode.Roles; @@ -41,7 +42,6 @@ partial class VBParser public const int _XmlCData = 18; public const int _XmlProcessingInstruction = 19; public const int maxT = 238; // usings = new List(); - + void ImportsStatement(Role role) { + var result = new ImportsStatement(); NodeStart(result); Expect(137); - Location startPos = t.Location; - Using u; - - ImportClause(out u); - if (u != null) { usings.Add(u); } + AddTerminal(Roles.Keyword); + ImportsClause(); while (la.kind == 22) { Get(); - ImportClause(out u); - if (u != null) { usings.Add(u); } - } - EndOfStmt(); - UsingDeclaration usingDeclaration = new UsingDeclaration(usings); - usingDeclaration.StartLocation = startPos; - usingDeclaration.EndLocation = t.Location; - AddChild(usingDeclaration); - - } - - void GlobalAttributeSection() { - Expect(40); - Location startPos = t.Location; - if (la.kind == 65) { - Get(); - } else if (la.kind == 155) { - Get(); - } else SynErr(243); - string attributeTarget = t.val != null ? t.val.ToLower(System.Globalization.CultureInfo.InvariantCulture) : null; - List attributes = new List(); - ASTAttribute attribute; - - Expect(21); - Attribute(out attribute); - attributes.Add(attribute); - while (NotFinalComma()) { - if (la.kind == 22) { - Get(); - if (la.kind == 65) { - Get(); - } else if (la.kind == 155) { - Get(); - } else SynErr(244); - Expect(21); - } - Attribute(out attribute); - attributes.Add(attribute); - } - if (la.kind == 22) { - Get(); - } - Expect(39); - EndOfStmt(); - AttributeSection section = new AttributeSection { - AttributeTarget = attributeTarget, - Attributes = attributes, - StartLocation = startPos, - EndLocation = t.EndLocation - }; - AddChild(section); - - } - - void NamespaceMemberDecl() { - ModifierList m = new ModifierList(); - AttributeSection section; - List attributes = new List(); - string qualident; - - if (la.kind == 160) { - Get(); - Location startPos = t.Location; - - Qualident(out qualident); - INode node = new NamespaceDeclaration(qualident); - node.StartLocation = startPos; - AddChild(node); - BlockStart(node); - - EndOfStmt(); - NamespaceBody(); - node.EndLocation = t.Location; - BlockEnd(); - - } else if (StartOf(3)) { - while (la.kind == 40) { - AttributeSection(out section); - attributes.Add(section); - } - while (StartOf(4)) { - TypeModifier(m); - } - NonModuleDeclaration(m, attributes); - } else SynErr(245); - } - - void OptionValue(ref bool val) { - if (la.kind == 171) { - Get(); - val = true; - } else if (la.kind == 170) { - Get(); - val = false; - } else SynErr(246); - } - - void ImportClause(out Using u) { - string qualident = null; - TypeReference aliasedType = null; - u = null; - - if (StartOf(5)) { - Qualident(out qualident); - if (la.kind == 20) { - Get(); - TypeName(out aliasedType); - } - if (qualident != null && qualident.Length > 0) { - if (aliasedType != null) { - u = new Using(qualident, aliasedType); - } else { - u = new Using(qualident); - } - } - - } else if (la.kind == 10) { - string prefix = null; - Get(); - Identifier(); - prefix = t.val; - Expect(20); - Expect(3); - u = new Using(t.literalValue as string, prefix); - Expect(11); - } else SynErr(247); - } - - void Qualident(out string qualident) { - string name; - qualidentBuilder.Length = 0; - - Identifier(); - qualidentBuilder.Append(t.val); - while (DotAndIdentOrKw()) { - Expect(26); - IdentifierOrKeyword(out name); - qualidentBuilder.Append('.'); qualidentBuilder.Append(name); + ImportsClause(); } - qualident = qualidentBuilder.ToString(); - } - - 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; - } - + StatementTerminator(); + NodeEnd(result, role); } void Identifier() { - if (StartOf(6)) { + if (StartOf(1)) { IdentifierForFieldDeclaration(); } else if (la.kind == 98) { Get(); - } else SynErr(248); - } - - void NamespaceBody() { - while (la.kind == 1 || la.kind == 21) { - EndOfStmt(); - } - while (StartOf(2)) { - NamespaceMemberDecl(); - while (la.kind == 1 || la.kind == 21) { - EndOfStmt(); - } - } - Expect(113); - Expect(160); - EndOfStmt(); - } - - void AttributeSection(out AttributeSection section) { - string attributeTarget = ""; - List attributes = new List(); - ASTAttribute attribute; - Location startLocation = la.Location; - - Expect(40); - if (IsLocalAttrTarget()) { - if (la.kind == 119) { - Get(); - attributeTarget = "event"; - } else if (la.kind == 195) { - Get(); - attributeTarget = "return"; - } else if (StartOf(5)) { - 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; - - } else SynErr(249); - Expect(21); - } - Attribute(out attribute); - attributes.Add(attribute); - while (NotFinalComma()) { - Expect(22); - Attribute(out attribute); - attributes.Add(attribute); - } - if (la.kind == 22) { - Get(); - } - Expect(39); - section = new AttributeSection { - AttributeTarget = attributeTarget, - Attributes = attributes, - StartLocation = startLocation, - EndLocation = t.EndLocation - }; - + } else SynErr(242); } - void TypeModifier(ModifierList m) { + void IdentifierForFieldDeclaration() { switch (la.kind) { - case 188: { + case 2: { Get(); - m.Add(Modifiers.Public, t.Location); break; } - case 187: { + case 58: { Get(); - m.Add(Modifiers.Protected, t.Location); break; } - case 125: { + case 62: { Get(); - m.Add(Modifiers.Internal, t.Location); break; } - case 185: { + case 64: { Get(); - m.Add(Modifiers.Private, t.Location); break; } - case 200: { + case 65: { Get(); - m.Add(Modifiers.Static, t.Location); break; } - case 199: { + case 66: { Get(); - m.Add(Modifiers.New, t.Location); break; } - case 156: { + case 67: { Get(); - m.Add(Modifiers.Abstract, t.Location); break; } - case 166: { + case 70: { Get(); - m.Add(Modifiers.Sealed, t.Location); break; } - case 183: { + case 87: { Get(); - m.Add(Modifiers.Partial, t.Location); break; } - default: SynErr(250); break; - } - } - - void NonModuleDeclaration(ModifierList m, List attributes) { - TypeReference typeRef = null; - List baseInterfaces = null; - - switch (la.kind) { - case 84: { - m.Check(Modifiers.Classes); + case 104: { Get(); - TypeDeclaration newType = new TypeDeclaration(m.Modifier, attributes); - newType.StartLocation = t.Location; - AddChild(newType); - BlockStart(newType); - - newType.Type = ClassType.Class; - - Identifier(); - newType.Name = t.val; - TypeParameterList(newType.Templates); - EndOfStmt(); - newType.BodyStartLocation = t.Location; - if (la.kind == 140) { - ClassBaseType(out typeRef); - SafeAdd(newType, newType.BaseTypes, typeRef); - } - while (la.kind == 136) { - TypeImplementsClause(out baseInterfaces); - newType.BaseTypes.AddRange(baseInterfaces); - } - ClassBody(newType); - Expect(113); - Expect(84); - newType.EndLocation = t.EndLocation; - EndOfStmt(); - BlockEnd(); - break; } - case 155: { + case 107: { Get(); - m.Check(Modifiers.VBModules); - TypeDeclaration newType = new TypeDeclaration(m.Modifier, attributes); - AddChild(newType); - BlockStart(newType); - newType.StartLocation = m.GetDeclarationLocation(t.Location); - newType.Type = ClassType.Module; - - Identifier(); - newType.Name = t.val; - EndOfStmt(); - newType.BodyStartLocation = t.Location; - ModuleBody(newType); - BlockEnd(); - break; } - case 209: { + case 116: { Get(); - m.Check(Modifiers.VBStructures); - TypeDeclaration newType = new TypeDeclaration(m.Modifier, attributes); - AddChild(newType); - BlockStart(newType); - newType.StartLocation = m.GetDeclarationLocation(t.Location); - newType.Type = ClassType.Struct; - - Identifier(); - newType.Name = t.val; - TypeParameterList(newType.Templates); - EndOfStmt(); - newType.BodyStartLocation = t.Location; - while (la.kind == 136) { - TypeImplementsClause(out baseInterfaces); - newType.BaseTypes.AddRange(baseInterfaces); - } - StructureBody(newType); - BlockEnd(); - break; } - case 115: { + case 121: { Get(); - m.Check(Modifiers.VBEnums); - TypeDeclaration newType = new TypeDeclaration(m.Modifier, attributes); - newType.StartLocation = m.GetDeclarationLocation(t.Location); - AddChild(newType); - BlockStart(newType); - - newType.Type = ClassType.Enum; - - Identifier(); - newType.Name = t.val; - if (la.kind == 63) { - Get(); - NonArrayTypeName(out typeRef, false); - SafeAdd(newType, newType.BaseTypes, typeRef); - } - EndOfStmt(); - newType.BodyStartLocation = t.Location; - EnumBody(newType); - BlockEnd(); - break; } - case 142: { + case 126: { Get(); - m.Check(Modifiers.VBInterfacs); - TypeDeclaration newType = new TypeDeclaration(m.Modifier, attributes); - newType.StartLocation = m.GetDeclarationLocation(t.Location); - AddChild(newType); - BlockStart(newType); - newType.Type = ClassType.Interface; - - Identifier(); - newType.Name = t.val; - TypeParameterList(newType.Templates); - EndOfStmt(); - newType.BodyStartLocation = t.Location; - while (la.kind == 140) { - InterfaceBase(out baseInterfaces); - newType.BaseTypes.AddRange(baseInterfaces); - } - InterfaceBody(newType); - BlockEnd(); - break; } - case 103: { + case 133: { Get(); - m.Check(Modifiers.VBDelegates); - DelegateDeclaration delegateDeclr = new DelegateDeclaration(m.Modifier, attributes); - delegateDeclr.ReturnType = new TypeReference("System.Void", true); - delegateDeclr.StartLocation = m.GetDeclarationLocation(t.Location); - List p = new List(); - - if (la.kind == 210) { - Get(); - Identifier(); - delegateDeclr.Name = t.val; - TypeParameterList(delegateDeclr.Templates); - if (la.kind == 37) { - Get(); - if (StartOf(7)) { - FormalParameterList(p); - } - Expect(38); - delegateDeclr.Parameters = p; - } - } else if (la.kind == 127) { - Get(); - Identifier(); - delegateDeclr.Name = t.val; - TypeParameterList(delegateDeclr.Templates); - if (la.kind == 37) { - Get(); - if (StartOf(7)) { - FormalParameterList(p); - } - Expect(38); - delegateDeclr.Parameters = p; - } - if (la.kind == 63) { - Get(); - TypeReference type; - TypeName(out type); - delegateDeclr.ReturnType = type; - } - } else SynErr(251); - delegateDeclr.EndLocation = t.EndLocation; - EndOfStmt(); - AddChild(delegateDeclr); - break; } - default: SynErr(252); break; - } - } - - void TypeParameterList(List templates) { - TemplateDefinition template; - - if (la.kind == Tokens.OpenParenthesis && Peek(1).kind == Tokens.Of) { - Expect(37); - Expect(169); - TypeParameter(out template); - if (template != null) templates.Add(template); - - while (la.kind == 22) { - Get(); - TypeParameter(out template); - if (template != null) templates.Add(template); - - } - Expect(38); - } - } - - void TypeParameter(out TemplateDefinition template) { - VarianceModifier modifier = VarianceModifier.Invariant; Location startLocation = la.Location; - if (la.kind == 138 || (la.kind == Tokens.Out && IsIdentifierToken(Peek(1)))) { - if (la.kind == 138) { - Get(); - modifier = VarianceModifier.Contravariant; - } else { - Expect(178); - modifier = VarianceModifier.Covariant; - } - } - Identifier(); - template = new TemplateDefinition(t.val, null) { VarianceModifier = modifier }; - if (la.kind == 63) { - TypeParameterConstraints(template); - } - if (template != null) { - template.StartLocation = startLocation; - template.EndLocation = t.EndLocation; - } - - } - - void TypeParameterConstraints(TemplateDefinition template) { - TypeReference constraint; - - Expect(63); - if (la.kind == 35) { - Get(); - TypeParameterConstraint(out constraint); - if (constraint != null) { template.Bases.Add(constraint); } - while (la.kind == 22) { - Get(); - TypeParameterConstraint(out constraint); - if (constraint != null) { template.Bases.Add(constraint); } - } - Expect(36); - } else if (StartOf(8)) { - TypeParameterConstraint(out constraint); - if (constraint != null) { template.Bases.Add(constraint); } - } else SynErr(253); - } - - 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); - } - - void ClassBaseType(out TypeReference typeRef) { - typeRef = null; - - Expect(140); - TypeName(out typeRef); - EndOfStmt(); - } - - void TypeImplementsClause(out List baseInterfaces) { - baseInterfaces = new List(); - TypeReference type = null; - - Expect(136); - TypeName(out type); - if (type != null) baseInterfaces.Add(type); - - while (la.kind == 22) { - Get(); - TypeName(out type); - if (type != null) baseInterfaces.Add(type); - } - EndOfStmt(); - } - - void ClassBody(TypeDeclaration newType) { - AttributeSection section; - while (la.kind == 1 || la.kind == 21) { - EndOfStmt(); - } - while (StartOf(10)) { - List attributes = new List(); - ModifierList m = new ModifierList(); - - while (la.kind == 40) { - AttributeSection(out section); - attributes.Add(section); - } - while (StartOf(11)) { - MemberModifier(m); - } - ClassMemberDecl(m, attributes); - while (la.kind == 1 || la.kind == 21) { - EndOfStmt(); - } - } - } - - void ModuleBody(TypeDeclaration newType) { - AttributeSection section; - while (la.kind == 1 || la.kind == 21) { - EndOfStmt(); - } - while (StartOf(10)) { - List attributes = new List(); - ModifierList m = new ModifierList(); - - while (la.kind == 40) { - AttributeSection(out section); - attributes.Add(section); - } - while (StartOf(11)) { - MemberModifier(m); - } - ClassMemberDecl(m, attributes); - while (la.kind == 1 || la.kind == 21) { - EndOfStmt(); - } - } - Expect(113); - Expect(155); - newType.EndLocation = t.EndLocation; - EndOfStmt(); - } - - void StructureBody(TypeDeclaration newType) { - AttributeSection section; - while (la.kind == 1 || la.kind == 21) { - EndOfStmt(); - } - while (StartOf(10)) { - List attributes = new List(); - ModifierList m = new ModifierList(); - - while (la.kind == 40) { - AttributeSection(out section); - attributes.Add(section); - } - while (StartOf(11)) { - MemberModifier(m); - } - StructureMemberDecl(m, attributes); - while (la.kind == 1 || la.kind == 21) { - EndOfStmt(); - } - } - Expect(113); - Expect(209); - newType.EndLocation = t.EndLocation; - EndOfStmt(); - } - - 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) { + case 139: { Get(); - typeref = new TypeReference("System.Object", true); - if (la.kind == 33) { - Get(); - List typeArguments = new List(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 typeArguments = new List(1); - if (typeref != null) typeArguments.Add(typeref); - typeref = new TypeReference("System.Nullable", typeArguments) { IsKeyword = true }; - - } - } else SynErr(255); - } - - void EnumBody(TypeDeclaration newType) { - FieldDeclaration f; - while (la.kind == 1 || la.kind == 21) { - EndOfStmt(); - } - while (StartOf(14)) { - EnumMemberDecl(out f); - AddChild(f); - - while (la.kind == 1 || la.kind == 21) { - EndOfStmt(); - } + break; } - Expect(113); - Expect(115); - newType.EndLocation = t.EndLocation; - EndOfStmt(); - } - - void InterfaceBase(out List bases) { - TypeReference type; - bases = new List(); - - Expect(140); - TypeName(out type); - if (type != null) bases.Add(type); - while (la.kind == 22) { + case 143: { Get(); - TypeName(out type); - if (type != null) bases.Add(type); - } - EndOfStmt(); - } - - void InterfaceBody(TypeDeclaration newType) { - while (la.kind == 1 || la.kind == 21) { - EndOfStmt(); - } - while (StartOf(15)) { - InterfaceMemberDecl(); - while (la.kind == 1 || la.kind == 21) { - EndOfStmt(); - } + break; } - Expect(113); - Expect(142); - newType.EndLocation = t.EndLocation; - EndOfStmt(); - } - - void FormalParameterList(List parameter) { - ParameterDeclarationExpression p; - FormalParameter(out p); - if (p != null) parameter.Add(p); - while (la.kind == 22) { + case 146: { Get(); - FormalParameter(out p); - if (p != null) parameter.Add(p); + break; } - } - - void MemberModifier(ModifierList m) { - switch (la.kind) { - case 156: { + case 147: { Get(); - m.Add(Modifiers.Abstract, t.Location); break; } - case 102: { + case 170: { Get(); - m.Add(Modifiers.Default, t.Location); break; } - case 125: { + case 176: { Get(); - m.Add(Modifiers.Internal, t.Location); break; } - case 199: { + case 178: { Get(); - m.Add(Modifiers.New, t.Location); break; } - case 181: { + case 184: { Get(); - m.Add(Modifiers.Override, t.Location); break; } - case 157: { + case 203: { Get(); - m.Add(Modifiers.Abstract, t.Location); break; } - case 185: { + case 212: { Get(); - m.Add(Modifiers.Private, t.Location); break; } - case 187: { + case 213: { Get(); - m.Add(Modifiers.Protected, t.Location); break; } - case 188: { + case 223: { Get(); - m.Add(Modifiers.Public, t.Location); break; } - case 166: { + case 224: { Get(); - m.Add(Modifiers.Sealed, t.Location); break; } - case 167: { + case 230: { Get(); - m.Add(Modifiers.Sealed, t.Location); break; } - case 200: { - Get(); - m.Add(Modifiers.Static, t.Location); - break; - } - case 180: { - Get(); - m.Add(Modifiers.Virtual, t.Location); - break; - } - case 179: { - Get(); - m.Add(Modifiers.Overloads, t.Location); - break; - } - case 190: { - Get(); - m.Add(Modifiers.ReadOnly, t.Location); - break; - } - case 235: { - Get(); - m.Add(Modifiers.WriteOnly, t.Location); - break; - } - case 234: { - Get(); - m.Add(Modifiers.WithEvents, t.Location); - break; - } - case 105: { - Get(); - m.Add(Modifiers.Dim, t.Location); - break; - } - case 183: { - Get(); - m.Add(Modifiers.Partial, t.Location); - break; - } - default: SynErr(256); break; - } - } - - void ClassMemberDecl(ModifierList m, List attributes) { - StructureMemberDecl(m, attributes); - } - - void StructureMemberDecl(ModifierList m, List attributes) { - TypeReference type = null; - List p = new List(); - Statement stmt = null; - List variableDeclarators = new List(); - List templates = new List(); - - 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 handlesClause = null; - List 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 handlesClause = null; - List 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 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 constantDeclarators = new List(); - - 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 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 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 parameters = new List(); - - 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; - } - } - - void EnumMemberDecl(out FieldDeclaration f) { - Expression expr = null;List attributes = new List(); - AttributeSection section = null; - VariableDeclaration varDecl = null; - - while (la.kind == 40) { - AttributeSection(out section); - attributes.Add(section); - } - Identifier(); - f = new FieldDeclaration(attributes); - varDecl = new VariableDeclaration(t.val); - f.Fields.Add(varDecl); - f.StartLocation = varDecl.StartLocation = t.Location; - - if (la.kind == 20) { - Get(); - Expr(out expr); - varDecl.Initializer = expr; - } - f.EndLocation = varDecl.EndLocation = t.EndLocation; - EndOfStmt(); - } - - void InterfaceMemberDecl() { - TypeReference type =null; - List p = new List(); - List templates = new List(); - AttributeSection section, returnTypeAttributeSection = null; - ModifierList mod = new ModifierList(); - List attributes = new List(); - 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); - } - - void Expr(out Expression expr) { - expr = null; Location startLocation = la.Location; - if (IsQueryExpression()) { - QueryExpr(out expr); - } else if (la.kind == 127 || la.kind == 210) { - LambdaExpr(out expr); - } else if (StartOf(22)) { - DisjunctionExpr(out expr); - } else SynErr(267); - if (expr != null) { - expr.StartLocation = startLocation; - expr.EndLocation = t.EndLocation; - } - - } - - void ImplementsClause(out List baseInterfaces) { - baseInterfaces = new List(); - TypeReference type = null; - string memberName = null; - - Expect(136); - NonArrayTypeName(out type, false); - if (type != null) memberName = TypeReference.StripLastIdentifierFromType(ref type); - baseInterfaces.Add(new InterfaceImplementation(type, memberName)); - while (la.kind == 22) { - Get(); - NonArrayTypeName(out type, false); - if (type != null) memberName = TypeReference.StripLastIdentifierFromType(ref type); - baseInterfaces.Add(new InterfaceImplementation(type, memberName)); - } - } - - void HandlesClause(out List handlesClause) { - handlesClause = new List(); - string name; - - Expect(134); - EventMemberSpecifier(out name); - if (name != null) handlesClause.Add(name); - while (la.kind == 22) { - Get(); - EventMemberSpecifier(out name); - if (name != null) handlesClause.Add(name); - } - } - - void Block(out Statement stmt) { - BlockStatement blockStmt = new BlockStatement(); - /* in snippet parsing mode, t might be null */ - if (t != null) blockStmt.StartLocation = t.EndLocation; - BlockStart(blockStmt); - - while (IsEndStmtAhead() || StartOf(StatementEndOfStmt)) { - if (la.kind == 113) { - Get(); - Token first = t; - AddChild(new EndStatement() { - StartLocation = first.Location, - EndLocation = first.EndLocation } - ); - - EndOfStmt(); - } else if (StartOf(1)) { - Statement(); - EndOfStmt(); - } else SynErr(268); - } - stmt = blockStmt; - if (t != null) blockStmt.EndLocation = t.EndLocation; - BlockEnd(); - - } - - void Charset(out CharsetModifier charsetModifier) { - charsetModifier = CharsetModifier.None; - if (la.kind == 127 || la.kind == 210) { - } else if (la.kind == 62) { - Get(); - charsetModifier = CharsetModifier.Ansi; - } else if (la.kind == 66) { - Get(); - charsetModifier = CharsetModifier.Auto; - } else if (la.kind == 223) { - Get(); - charsetModifier = CharsetModifier.Unicode; - } else SynErr(269); - } - - void IdentifierForFieldDeclaration() { - switch (la.kind) { - case 2: { - Get(); - break; - } - case 58: { - Get(); - break; - } - case 62: { - Get(); - break; - } - case 64: { - Get(); - break; - } - case 65: { - Get(); - break; - } - case 66: { - Get(); - break; - } - case 67: { - Get(); - break; - } - case 70: { - Get(); - break; - } - case 87: { - Get(); - break; - } - case 104: { - Get(); - break; - } - case 107: { - Get(); - break; - } - case 116: { - Get(); - break; - } - case 121: { - Get(); - break; - } - case 126: { - Get(); - break; - } - case 133: { - Get(); - break; - } - case 139: { - Get(); - break; - } - case 143: { - Get(); - break; - } - case 146: { - Get(); - break; - } - case 147: { - Get(); - break; - } - case 170: { - Get(); - break; - } - case 176: { - Get(); - break; - } - case 178: { - Get(); - break; - } - case 184: { - Get(); - break; - } - case 203: { - Get(); - break; - } - case 212: { - Get(); - break; - } - case 213: { - Get(); - break; - } - case 223: { - Get(); - break; - } - case 224: { - Get(); - break; - } - case 230: { - Get(); - break; - } - default: SynErr(270); break; - } - } - - void VariableDeclaratorPartAfterIdentifier(List fieldDeclaration, string name) { - Expression expr = null; - TypeReference type = null; - ArrayList rank = null; - List 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); - - } - - void VariableDeclarator(List fieldDeclaration) { - Identifier(); - string name = t.val; - VariableDeclaratorPartAfterIdentifier(fieldDeclaration, name); - } - - void ConstantDeclarator(List constantDeclaration) { - Expression expr = null; - TypeReference type = null; - string name = String.Empty; - Location location; - - Identifier(); - name = t.val; location = t.Location; - if (la.kind == 63) { - Get(); - TypeName(out type); - } - Expect(20); - Expr(out expr); - VariableDeclaration f = new VariableDeclaration(name, expr); - f.TypeReference = type; - f.StartLocation = location; - constantDeclaration.Add(f); - - } - - void ObjectCreateExpression(out Expression oce) { - TypeReference type = null; - CollectionInitializerExpression initializer = null; - List arguments = null; - ArrayList dimensions = null; - oce = null; - Location startLocation = la.Location; - bool canBeNormal; bool canBeReDim; - - Expect(162); - if (StartOf(9)) { - NonArrayTypeName(out type, false); - if (la.kind == 37) { - Get(); - NormalOrReDimArgumentList(out arguments, out canBeNormal, out canBeReDim); - Expect(38); - if (la.kind == 35 || (la.kind == Tokens.OpenParenthesis)) { - if (la.kind == Tokens.OpenParenthesis) { - ArrayTypeModifiers(out dimensions); - CollectionInitializer(out initializer); - } else { - CollectionInitializer(out initializer); - } - } - if (canBeReDim && !canBeNormal && initializer == null) initializer = new CollectionInitializerExpression(); - } - } - 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); - ace.Arguments = arguments; - oce = ace; - } - - if (la.kind == 126 || la.kind == 233) { - if (la.kind == 233) { - MemberInitializerExpression memberInitializer = null; - Expression anonymousMember = null; - - Get(); - CollectionInitializerExpression memberInitializers = new CollectionInitializerExpression(); - memberInitializers.StartLocation = la.Location; - - Expect(35); - if (la.kind == 26 || la.kind == 147) { - MemberInitializer(out memberInitializer); - memberInitializers.CreateExpressions.Add(memberInitializer); - } else if (StartOf(24)) { - Expr(out anonymousMember); - memberInitializers.CreateExpressions.Add(anonymousMember); - } else SynErr(272); - while (la.kind == 22) { - Get(); - if (la.kind == 26 || la.kind == 147) { - MemberInitializer(out memberInitializer); - memberInitializers.CreateExpressions.Add(memberInitializer); - } else if (StartOf(24)) { - Expr(out anonymousMember); - memberInitializers.CreateExpressions.Add(anonymousMember); - } else SynErr(273); - } - Expect(36); - memberInitializers.EndLocation = t.Location; - if(oce is ObjectCreateExpression) - { - ((ObjectCreateExpression)oce).ObjectInitializer = memberInitializers; - } - - } else { - Get(); - CollectionInitializer(out initializer); - if(oce is ObjectCreateExpression) - ((ObjectCreateExpression)oce).ObjectInitializer = initializer; - - } - } - if (oce != null) { - oce.StartLocation = startLocation; - oce.EndLocation = t.EndLocation; - } - - } - - void AccessorDecls(out PropertyGetRegion getBlock, out PropertySetRegion setBlock) { - List attributes = new List(); - AttributeSection section; - getBlock = null; - setBlock = null; - - while (la.kind == 40) { - AttributeSection(out section); - attributes.Add(section); - } - if (StartOf(25)) { - GetAccessorDecl(out getBlock, attributes); - if (StartOf(26)) { - attributes = new List(); - while (la.kind == 40) { - AttributeSection(out section); - attributes.Add(section); - } - SetAccessorDecl(out setBlock, attributes); - } - } else if (StartOf(27)) { - SetAccessorDecl(out setBlock, attributes); - if (StartOf(28)) { - attributes = new List(); - while (la.kind == 40) { - AttributeSection(out section); - attributes.Add(section); - } - GetAccessorDecl(out getBlock, attributes); - } - } else SynErr(274); - } - - void EventAccessorDeclaration(out EventAddRemoveRegion eventAccessorDeclaration) { - Statement stmt = null; - List p = new List(); - AttributeSection section; - List attributes = new List(); - eventAccessorDeclaration = null; - - while (la.kind == 40) { - AttributeSection(out section); - attributes.Add(section); - } - if (la.kind == 56) { - Get(); - if (la.kind == 37) { - Get(); - if (StartOf(7)) { - FormalParameterList(p); - } - Expect(38); - } - Expect(1); - Block(out stmt); - Expect(113); - Expect(56); - EndOfStmt(); - eventAccessorDeclaration = new EventAddRegion(attributes); - eventAccessorDeclaration.Block = (BlockStatement)stmt; - eventAccessorDeclaration.Parameters = p; - - } else if (la.kind == 193) { - Get(); - if (la.kind == 37) { - Get(); - if (StartOf(7)) { - FormalParameterList(p); - } - Expect(38); - } - Expect(1); - Block(out stmt); - Expect(113); - Expect(193); - EndOfStmt(); - eventAccessorDeclaration = new EventRemoveRegion(attributes); - eventAccessorDeclaration.Block = (BlockStatement)stmt; - eventAccessorDeclaration.Parameters = p; - - } else if (la.kind == 189) { - Get(); - if (la.kind == 37) { - Get(); - if (StartOf(7)) { - FormalParameterList(p); - } - Expect(38); - } - Expect(1); - Block(out stmt); - Expect(113); - Expect(189); - EndOfStmt(); - eventAccessorDeclaration = new EventRaiseRegion(attributes); - eventAccessorDeclaration.Block = (BlockStatement)stmt; - eventAccessorDeclaration.Parameters = p; - - } else SynErr(275); - } - - void OverloadableOperator(out OverloadableOperatorType operatorType) { - operatorType = OverloadableOperatorType.None; - switch (la.kind) { - case 31: { - Get(); - operatorType = OverloadableOperatorType.Add; - break; - } - case 30: { - Get(); - operatorType = OverloadableOperatorType.Subtract; - break; - } - case 34: { - Get(); - operatorType = OverloadableOperatorType.Multiply; - break; - } - case 24: { - Get(); - operatorType = OverloadableOperatorType.Divide; - break; - } - case 25: { - Get(); - operatorType = OverloadableOperatorType.DivideInteger; - break; - } - case 23: { - Get(); - operatorType = OverloadableOperatorType.Concat; - break; - } - case 150: { - Get(); - operatorType = OverloadableOperatorType.Like; - break; - } - case 154: { - Get(); - operatorType = OverloadableOperatorType.Modulus; - break; - } - case 60: { - Get(); - operatorType = OverloadableOperatorType.BitwiseAnd; - break; - } - case 175: { - Get(); - operatorType = OverloadableOperatorType.BitwiseOr; - break; - } - case 236: { - Get(); - operatorType = OverloadableOperatorType.ExclusiveOr; - break; - } - case 32: { - Get(); - operatorType = OverloadableOperatorType.Power; - break; - } - case 44: { - Get(); - operatorType = OverloadableOperatorType.ShiftLeft; - break; - } - case 45: { - Get(); - operatorType = OverloadableOperatorType.ShiftRight; - break; - } - case 20: { - Get(); - operatorType = OverloadableOperatorType.Equality; - break; - } - case 41: { - Get(); - operatorType = OverloadableOperatorType.InEquality; - break; - } - case 40: { - Get(); - operatorType = OverloadableOperatorType.LessThan; - break; - } - case 43: { - Get(); - operatorType = OverloadableOperatorType.LessThanOrEqual; - break; - } - case 39: { - Get(); - operatorType = OverloadableOperatorType.GreaterThan; - break; - } - case 42: { - Get(); - operatorType = OverloadableOperatorType.GreaterThanOrEqual; - break; - } - case 94: { - Get(); - operatorType = OverloadableOperatorType.CType; - 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(); - 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'."); - } - - break; - } - default: SynErr(276); break; - } - } - - void FormalParameter(out ParameterDeclarationExpression p) { - AttributeSection section; - List attributes = new List(); - TypeReference type = null; - ParamModifierList mod = new ParamModifierList(this); - Expression expr = null; - p = null; - ArrayList arrayModifiers = null; - Location startLocation = la.Location; - - while (la.kind == 40) { - AttributeSection(out section); - attributes.Add(section); - } - while (StartOf(29)) { - ParameterModifier(mod); - } - Identifier(); - string parameterName = t.val; - if (IsDims()) { - ArrayTypeModifiers(out arrayModifiers); - } - if (la.kind == 63) { - Get(); - 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)); - } - } - } - - if (la.kind == 20) { - Get(); - Expr(out expr); - } - mod.Check(); - p = new ParameterDeclarationExpression(type, parameterName, mod.Modifier, expr); - p.Attributes = attributes; - p.StartLocation = startLocation; - p.EndLocation = t.EndLocation; - - } - - void GetAccessorDecl(out PropertyGetRegion getBlock, List attributes) { - Statement stmt = null; Modifiers m; - PropertyAccessorAccessModifier(out m); - Expect(128); - Location startLocation = t.Location; - Expect(1); - Block(out stmt); - getBlock = new PropertyGetRegion((BlockStatement)stmt, attributes); - Expect(113); - Expect(128); - getBlock.Modifier = m; - getBlock.StartLocation = startLocation; getBlock.EndLocation = t.EndLocation; - EndOfStmt(); - } - - void SetAccessorDecl(out PropertySetRegion setBlock, List attributes) { - Statement stmt = null; - List p = new List(); - Modifiers m; - - PropertyAccessorAccessModifier(out m); - Expect(198); - Location startLocation = t.Location; - if (la.kind == 37) { - Get(); - if (StartOf(7)) { - FormalParameterList(p); - } - Expect(38); - } - Expect(1); - Block(out stmt); - setBlock = new PropertySetRegion((BlockStatement)stmt, attributes); - setBlock.Modifier = m; - setBlock.Parameters = p; - - Expect(113); - Expect(198); - setBlock.StartLocation = startLocation; setBlock.EndLocation = t.EndLocation; - EndOfStmt(); - } - - void PropertyAccessorAccessModifier(out Modifiers m) { - m = Modifiers.None; - while (StartOf(30)) { - if (la.kind == 188) { - Get(); - m |= Modifiers.Public; - } else if (la.kind == 187) { - Get(); - m |= Modifiers.Protected; - } else if (la.kind == 125) { - Get(); - m |= Modifiers.Internal; - } else { - Get(); - m |= Modifiers.Private; - } - } - } - - void ArrayInitializationModifier(out List arrayModifiers) { - arrayModifiers = null; - - Expect(37); - InitializationRankList(out arrayModifiers); - Expect(38); - } - - void ArrayNameModifier(out ArrayList arrayModifiers) { - arrayModifiers = null; - - ArrayTypeModifiers(out arrayModifiers); - } - - void InitializationRankList(out List rank) { - rank = new List(); - Expression expr = null; - - Expr(out expr); - if (la.kind == 216) { - Get(); - EnsureIsZero(expr); - Expr(out expr); - } - if (expr != null) { rank.Add(expr); } - while (la.kind == 22) { - Get(); - Expr(out expr); - if (la.kind == 216) { - Get(); - EnsureIsZero(expr); - Expr(out expr); - } - if (expr != null) { rank.Add(expr); } - } - } - - void CollectionInitializer(out CollectionInitializerExpression outExpr) { - Expression expr = null; - CollectionInitializerExpression initializer = new CollectionInitializerExpression(); - Location startLocation = la.Location; - - Expect(35); - if (StartOf(24)) { - Expr(out expr); - if (expr != null) { initializer.CreateExpressions.Add(expr); } - - while (NotFinalComma()) { - Expect(22); - Expr(out expr); - if (expr != null) { initializer.CreateExpressions.Add(expr); } - } - } - Expect(36); - outExpr = initializer; - outExpr.StartLocation = startLocation; - outExpr.EndLocation = t.EndLocation; - - } - - void EventMemberSpecifier(out string name) { - string eventName; - if (StartOf(5)) { - Identifier(); - } else if (la.kind == 158) { - Get(); - } else if (la.kind == 153) { - Get(); - } else SynErr(277); - name = t.val; - Expect(26); - IdentifierOrKeyword(out eventName); - name = name + "." + eventName; - } - - void IdentifierOrKeyword(out string name) { - Get(); - name = t.val; - } - - void QueryExpr(out Expression expr) { - QueryExpression qexpr = new QueryExpression(); - qexpr.StartLocation = la.Location; - expr = qexpr; - - FromOrAggregateQueryOperator(qexpr.Clauses); - while (StartOf(31)) { - QueryOperator(qexpr.Clauses); - } - qexpr.EndLocation = t.EndLocation; - - } - - void LambdaExpr(out Expression expr) { - LambdaExpression lambda = null; - - if (la.kind == 210) { - SubLambdaExpression(out lambda); - } else if (la.kind == 127) { - FunctionLambdaExpression(out lambda); - } else SynErr(278); - expr = lambda; - } - - void DisjunctionExpr(out Expression outExpr) { - Expression expr; - BinaryOperatorType op = BinaryOperatorType.None; - Location startLocation = la.Location; - - ConjunctionExpr(out outExpr); - while (la.kind == 175 || la.kind == 177 || la.kind == 236) { - if (la.kind == 175) { - Get(); - op = BinaryOperatorType.BitwiseOr; - } else if (la.kind == 177) { - Get(); - op = BinaryOperatorType.LogicalOr; - } else { - Get(); - op = BinaryOperatorType.ExclusiveOr; - } - ConjunctionExpr(out expr); - outExpr = new BinaryOperatorExpression(outExpr, op, expr) { StartLocation = startLocation, EndLocation = t.EndLocation }; - } - } - - void AssignmentOperator(out AssignmentOperatorType op) { - op = AssignmentOperatorType.None; - switch (la.kind) { - case 20: { - Get(); - op = AssignmentOperatorType.Assign; - break; - } - case 54: { - Get(); - op = AssignmentOperatorType.ConcatString; - break; - } - case 46: { - Get(); - op = AssignmentOperatorType.Add; - break; - } - case 48: { - Get(); - op = AssignmentOperatorType.Subtract; - break; - } - case 49: { - Get(); - op = AssignmentOperatorType.Multiply; - break; - } - case 50: { - Get(); - op = AssignmentOperatorType.Divide; - break; - } - case 51: { - Get(); - op = AssignmentOperatorType.DivideInteger; - break; - } - case 47: { - Get(); - op = AssignmentOperatorType.Power; - break; - } - case 52: { - Get(); - op = AssignmentOperatorType.ShiftLeft; - break; - } - case 53: { - Get(); - op = AssignmentOperatorType.ShiftRight; - break; - } - default: SynErr(279); break; - } - } - - void SimpleExpr(out Expression pexpr) { - string name; Location startLocation = la.Location; - SimpleNonInvocationExpression(out pexpr); - while (StartOf(32)) { - if (la.kind == 26) { - Get(); - if (la.kind == 10) { - Get(); - IdentifierOrKeyword(out name); - Expect(11); - pexpr = new XmlMemberAccessExpression(pexpr, XmlAxisType.Element, name, true); - } else if (StartOf(33)) { - IdentifierOrKeyword(out name); - pexpr = new MemberReferenceExpression(pexpr, name) { StartLocation = startLocation, EndLocation = t.EndLocation }; - } else SynErr(280); - if (la.kind == Tokens.OpenParenthesis && Peek(1).kind == Tokens.Of) { - Expect(37); - Expect(169); - TypeArgumentList(((MemberReferenceExpression)pexpr).TypeArguments); - Expect(38); - } - } else if (la.kind == 29) { - Get(); - IdentifierOrKeyword(out name); - pexpr = new BinaryOperatorExpression(pexpr, BinaryOperatorType.DictionaryAccess, new PrimitiveExpression(name, name) { StartLocation = t.Location, EndLocation = t.EndLocation }); - } else if (la.kind == 27 || la.kind == 28) { - XmlAxisType type = XmlAxisType.Attribute; bool isXmlName = false; - if (la.kind == 28) { - Get(); - } else { - Get(); - type = XmlAxisType.Descendents; - } - if (la.kind == 10) { - Get(); - isXmlName = true; - } - IdentifierOrKeyword(out name); - if (la.kind == 11) { - Get(); - } - pexpr = new XmlMemberAccessExpression(pexpr, type, name, isXmlName); - } else { - InvocationExpression(ref pexpr); - } - } - if (pexpr != null) { - pexpr.StartLocation = startLocation; - pexpr.EndLocation = t.EndLocation; - } - - } - - 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; - } - - } - - void TypeArgumentList(List typeArguments) { - TypeReference typeref; - - TypeName(out typeref); - if (typeref != null) typeArguments.Add(typeref); - while (la.kind == 22) { - Get(); - TypeName(out typeref); - if (typeref != null) typeArguments.Add(typeref); - } - } - - void InvocationExpression(ref Expression pexpr) { - List parameters = null; - Expect(37); - Location start = t.Location; - ArgumentList(out parameters); - Expect(38); - pexpr = new InvocationExpression(pexpr, parameters); - - pexpr.StartLocation = start; pexpr.EndLocation = t.Location; - } - - void PrimitiveTypeName(out string type) { - type = String.Empty; - switch (la.kind) { - case 68: { - Get(); - type = "System.Boolean"; - break; - } - case 99: { - Get(); - type = "System.DateTime"; - break; - } - case 82: { - Get(); - type = "System.Char"; - break; - } - case 208: { - Get(); - type = "System.String"; - break; - } - case 100: { - Get(); - type = "System.Decimal"; - break; - } - case 71: { - Get(); - type = "System.Byte"; - break; - } - case 201: { - Get(); - type = "System.Int16"; - break; - } - case 141: { - Get(); - type = "System.Int32"; - break; - } - case 151: { - Get(); - type = "System.Int64"; - break; - } - case 202: { - Get(); - type = "System.Single"; - break; - } - case 109: { - Get(); - type = "System.Double"; - break; - } - case 221: { - Get(); - type = "System.UInt32"; - break; - } - case 222: { - Get(); - type = "System.UInt64"; - break; - } - case 225: { - Get(); - type = "System.UInt16"; - break; - } - case 196: { - Get(); - type = "System.SByte"; - break; - } - default: SynErr(283); break; - } - } - - 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; - } - } - - 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)); - } - - } - - void ConditionalExpression(out Expression expr) { - ConditionalExpression conditionalExpression = new ConditionalExpression(); - BinaryOperatorExpression binaryOperatorExpression = new BinaryOperatorExpression(); - conditionalExpression.StartLocation = binaryOperatorExpression.StartLocation = la.Location; - - Expression condition = null; - Expression trueExpr = null; - Expression falseExpr = null; - - Expect(135); - Expect(37); - Expr(out condition); - Expect(22); - Expr(out trueExpr); - if (la.kind == 22) { - Get(); - Expr(out falseExpr); - } - Expect(38); - if(falseExpr != null) - { - conditionalExpression.Condition = condition; - conditionalExpression.TrueExpression = trueExpr; - conditionalExpression.FalseExpression = falseExpr; - conditionalExpression.EndLocation = t.EndLocation; - - expr = conditionalExpression; - } - else - { - binaryOperatorExpression.Left = condition; - binaryOperatorExpression.Right = trueExpr; - binaryOperatorExpression.Op = BinaryOperatorType.NullCoalescing; - binaryOperatorExpression.EndLocation = t.EndLocation; - - expr = binaryOperatorExpression; - } - - } - - void XmlLiteralExpression(out Expression pexpr) { - List exprs = new List(); - XmlExpression currentExpression = null; - - if (StartOf(36)) { - XmlContentExpression(exprs); - while (StartOf(36)) { - XmlContentExpression(exprs); - } - if (la.kind == 10) { - XmlElement(out currentExpression); - exprs.Add(currentExpression); - while (StartOf(36)) { - XmlContentExpression(exprs); - } - } - } else if (la.kind == 10) { - XmlElement(out currentExpression); - exprs.Add(currentExpression); - while (StartOf(36)) { - XmlContentExpression(exprs); - } - } else SynErr(285); - if (exprs.Count > 1) { - pexpr = new XmlDocumentExpression() { Expressions = exprs }; - } else { - pexpr = exprs[0]; - } - - } - - void XmlContentExpression(List exprs) { - XmlContentExpression expr = null; - if (la.kind == 16) { - Get(); - expr = new XmlContentExpression(t.val, XmlContentType.Text); - } else if (la.kind == 18) { - Get(); - expr = new XmlContentExpression(t.val, XmlContentType.CData); - } else if (la.kind == 17) { - Get(); - expr = new XmlContentExpression(t.val, XmlContentType.Comment); - } else if (la.kind == 19) { - Get(); - expr = new XmlContentExpression(t.val, XmlContentType.ProcessingInstruction); - } else SynErr(286); - expr.StartLocation = t.Location; - expr.EndLocation = t.EndLocation; - exprs.Add(expr); - - } - - void XmlElement(out XmlExpression expr) { - XmlElementExpression el = new XmlElementExpression(); - Expect(10); - el.StartLocation = t.Location; - if (la.kind == 12) { - Get(); - Expression innerExpression; - Expr(out innerExpression); - Expect(13); - el.NameExpression = new XmlEmbeddedExpression() { InlineVBExpression = innerExpression }; - } else if (StartOf(5)) { - Identifier(); - el.XmlName = t.val; - } else SynErr(287); - while (StartOf(37)) { - XmlAttribute(el.Attributes); - } - if (la.kind == 14) { - Get(); - el.EndLocation = t.EndLocation; - } else if (la.kind == 11) { - Get(); - while (StartOf(38)) { - XmlExpression child; - XmlNestedContent(out child); - el.Children.Add(child); - } - Expect(15); - while (StartOf(39)) { - Get(); - } - Expect(11); - el.EndLocation = t.EndLocation; - } else SynErr(288); - expr = el; - } - - void XmlNestedContent(out XmlExpression expr) { - XmlExpression tmpExpr = null; Location start = la.Location; - switch (la.kind) { - case 16: { - Get(); - tmpExpr = new XmlContentExpression(t.val, XmlContentType.Text); - break; - } - case 18: { - Get(); - tmpExpr = new XmlContentExpression(t.val, XmlContentType.CData); - break; - } - case 17: { - Get(); - tmpExpr = new XmlContentExpression(t.val, XmlContentType.Comment); - break; - } - case 19: { - Get(); - tmpExpr = new XmlContentExpression(t.val, XmlContentType.ProcessingInstruction); - break; - } - case 12: { - Get(); - Expression innerExpression; - Expr(out innerExpression); - Expect(13); - tmpExpr = new XmlEmbeddedExpression() { InlineVBExpression = innerExpression }; - break; - } - case 10: { - XmlElement(out tmpExpr); - break; - } - default: SynErr(289); break; - } - if (tmpExpr.StartLocation.IsEmpty) - tmpExpr.StartLocation = start; - if (tmpExpr.EndLocation.IsEmpty) - tmpExpr.EndLocation = t.EndLocation; - expr = tmpExpr; - - } - - void XmlAttribute(List attrs) { - Location start = la.Location; - if (StartOf(5)) { - Identifier(); - string name = t.val; - Expect(20); - string literalValue = null; Expression expressionValue = null; bool useDoubleQuotes = false; - if (la.kind == 3) { - Get(); - literalValue = t.literalValue.ToString(); useDoubleQuotes = t.val[0] == '"'; - } else if (la.kind == 12) { - Get(); - Expr(out expressionValue); - Expect(13); - } else SynErr(290); - attrs.Add(new XmlAttributeExpression() { Name = name, ExpressionValue = expressionValue, LiteralValue = literalValue, UseDoubleQuotes = useDoubleQuotes, StartLocation = start, EndLocation = t.EndLocation }); - } else if (la.kind == 12) { - Get(); - Expression innerExpression; - Expr(out innerExpression); - Expect(13); - attrs.Add(new XmlEmbeddedExpression() { InlineVBExpression = innerExpression, StartLocation = start, EndLocation = t.EndLocation }); - } else SynErr(291); - } - - void ArgumentList(out List arguments) { - arguments = new List(); - Expression expr = null; - - if (StartOf(24)) { - Argument(out expr); - } - while (la.kind == 22) { - Get(); - arguments.Add(expr ?? Expression.Null); expr = null; - if (StartOf(24)) { - Argument(out expr); - } - if (expr == null) expr = Expression.Null; - } - if (expr != null) arguments.Add(expr); - } - - void ConjunctionExpr(out Expression outExpr) { - Expression expr; - BinaryOperatorType op = BinaryOperatorType.None; - Location startLocation = la.Location; - - NotExpr(out outExpr); - while (la.kind == 60 || la.kind == 61) { - if (la.kind == 60) { - Get(); - op = BinaryOperatorType.BitwiseAnd; - } else { - Get(); - op = BinaryOperatorType.LogicalAnd; - } - NotExpr(out expr); - outExpr = new BinaryOperatorExpression(outExpr, op, expr) { StartLocation = startLocation, EndLocation = t.EndLocation }; - } - } - - void NotExpr(out Expression outExpr) { - UnaryOperatorType uop = UnaryOperatorType.None; - while (la.kind == 164) { - Get(); - uop = UnaryOperatorType.Not; - } - ComparisonExpr(out outExpr); - if (uop != UnaryOperatorType.None) - outExpr = new UnaryOperatorExpression(outExpr, uop); - - } - - void ComparisonExpr(out Expression outExpr) { - Expression expr; - BinaryOperatorType op = BinaryOperatorType.None; - Location startLocation = la.Location; - - ShiftExpr(out outExpr); - while (StartOf(40)) { - switch (la.kind) { - case 40: { - Get(); - op = BinaryOperatorType.LessThan; - break; - } - case 39: { - Get(); - op = BinaryOperatorType.GreaterThan; - break; - } - case 43: { - Get(); - op = BinaryOperatorType.LessThanOrEqual; - break; - } - case 42: { - Get(); - op = BinaryOperatorType.GreaterThanOrEqual; - break; - } - case 41: { - Get(); - op = BinaryOperatorType.InEquality; - break; - } - case 20: { - Get(); - op = BinaryOperatorType.Equality; - break; - } - case 150: { - Get(); - op = BinaryOperatorType.Like; - break; - } - case 144: { - Get(); - op = BinaryOperatorType.ReferenceEquality; - break; - } - case 145: { - Get(); - op = BinaryOperatorType.ReferenceInequality; - break; - } - } - if (StartOf(41)) { - ShiftExpr(out expr); - outExpr = new BinaryOperatorExpression(outExpr, op, expr) { StartLocation = startLocation, EndLocation = t.EndLocation }; - } else if (la.kind == 164) { - Location startLocation2 = la.Location; - Get(); - ShiftExpr(out expr); - outExpr = new BinaryOperatorExpression(outExpr, op, new UnaryOperatorExpression(expr, UnaryOperatorType.Not) { StartLocation = startLocation2, EndLocation = t.EndLocation }) { StartLocation = startLocation, EndLocation = t.EndLocation }; - } else SynErr(292); - } - } - - void ShiftExpr(out Expression outExpr) { - Expression expr; - BinaryOperatorType op = BinaryOperatorType.None; - Location startLocation = la.Location; - - ConcatenationExpr(out outExpr); - while (la.kind == 44 || la.kind == 45) { - if (la.kind == 44) { - Get(); - op = BinaryOperatorType.ShiftLeft; - } else { - Get(); - op = BinaryOperatorType.ShiftRight; - } - ConcatenationExpr(out expr); - outExpr = new BinaryOperatorExpression(outExpr, op, expr) { StartLocation = startLocation, EndLocation = t.EndLocation }; - } - } - - void ConcatenationExpr(out Expression outExpr) { - Expression expr; Location startLocation = la.Location; - AdditiveExpr(out outExpr); - while (la.kind == 23) { - Get(); - AdditiveExpr(out expr); - outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.Concat, expr) { StartLocation = startLocation, EndLocation = t.EndLocation }; - } - } - - void AdditiveExpr(out Expression outExpr) { - Expression expr; - BinaryOperatorType op = BinaryOperatorType.None; - Location startLocation = la.Location; - - ModuloExpr(out outExpr); - while (la.kind == 30 || la.kind == 31) { - if (la.kind == 31) { - Get(); - op = BinaryOperatorType.Add; - } else { - Get(); - op = BinaryOperatorType.Subtract; - } - ModuloExpr(out expr); - outExpr = new BinaryOperatorExpression(outExpr, op, expr) { StartLocation = startLocation, EndLocation = t.EndLocation }; - } - } - - void ModuloExpr(out Expression outExpr) { - Expression expr; Location startLocation = la.Location; - IntegerDivisionExpr(out outExpr); - while (la.kind == 154) { - Get(); - IntegerDivisionExpr(out expr); - outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.Modulus, expr) { StartLocation = startLocation, EndLocation = t.EndLocation }; - } - } - - void IntegerDivisionExpr(out Expression outExpr) { - Expression expr; Location startLocation = la.Location; - MultiplicativeExpr(out outExpr); - while (la.kind == 25) { - Get(); - MultiplicativeExpr(out expr); - outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.DivideInteger, expr) { StartLocation = startLocation, EndLocation = t.EndLocation }; - } - } - - void MultiplicativeExpr(out Expression outExpr) { - Expression expr; - BinaryOperatorType op = BinaryOperatorType.None; - Location startLocation = la.Location; - - UnaryExpr(out outExpr); - while (la.kind == 24 || la.kind == 34) { - if (la.kind == 34) { - Get(); - op = BinaryOperatorType.Multiply; - } else { - Get(); - op = BinaryOperatorType.Divide; - } - UnaryExpr(out expr); - outExpr = new BinaryOperatorExpression(outExpr, op, expr) { StartLocation = startLocation, EndLocation = t.EndLocation }; - } - } - - void UnaryExpr(out Expression uExpr) { - Expression expr; - UnaryOperatorType uop = UnaryOperatorType.None; - Location startLocation = la.Location; - bool isUOp = false; - - while (la.kind == 30 || la.kind == 31 || la.kind == 34) { - if (la.kind == 31) { - Get(); - uop = UnaryOperatorType.Plus; isUOp = true; - } else if (la.kind == 30) { - Get(); - uop = UnaryOperatorType.Minus; isUOp = true; - } else { - Get(); - uop = UnaryOperatorType.Dereference; isUOp = true; - } - } - ExponentiationExpr(out expr); - if (isUOp) { - uExpr = new UnaryOperatorExpression(expr, uop) { StartLocation = startLocation, EndLocation = t.EndLocation }; - } else { - uExpr = expr; - } - - } - - void ExponentiationExpr(out Expression outExpr) { - Expression expr; Location startLocation = la.Location; - SimpleExpr(out outExpr); - while (la.kind == 32) { - Get(); - SimpleExpr(out expr); - outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.Power, expr) { StartLocation = startLocation, EndLocation = t.EndLocation }; - } - } - - void NormalOrReDimArgumentList(out List arguments, out bool canBeNormal, out bool canBeRedim) { - arguments = new List(); - canBeNormal = true; canBeRedim = !IsNamedAssign(); - Expression expr = null; - - if (StartOf(24)) { - Argument(out expr); - if (la.kind == 216) { - Get(); - EnsureIsZero(expr); canBeNormal = false; - Expr(out expr); - } - } - while (la.kind == 22) { - Get(); - if (expr == null) canBeRedim = false; - arguments.Add(expr ?? Expression.Null); expr = null; - canBeRedim &= !IsNamedAssign(); - if (StartOf(24)) { - Argument(out expr); - if (la.kind == 216) { - Get(); - EnsureIsZero(expr); canBeNormal = false; - Expr(out expr); - } - } - if (expr == null) { canBeRedim = false; expr = Expression.Null; } - } - if (expr != null) arguments.Add(expr); else canBeRedim = false; - } - - void ArrayTypeModifiers(out ArrayList arrayModifiers) { - arrayModifiers = new ArrayList(); - int i = 0; - - while (IsDims()) { - Expect(37); - if (la.kind == 22 || la.kind == 38) { - RankList(out i); - } - arrayModifiers.Add(i); - - Expect(38); - } - if(arrayModifiers.Count == 0) { - arrayModifiers = null; - } - - } - - void MemberInitializer(out MemberInitializerExpression memberInitializer) { - memberInitializer = new MemberInitializerExpression(); - memberInitializer.StartLocation = la.Location; - Expression initExpr = null; - bool isKey = false; - string name = null; - - if (la.kind == 147) { - Get(); - isKey = true; - } - Expect(26); - IdentifierOrKeyword(out name); - Expect(20); - Expr(out initExpr); - memberInitializer.Name = name; - memberInitializer.Expression = initExpr; - memberInitializer.IsKey = isKey; - memberInitializer.EndLocation = t.EndLocation; - - } - - void SubLambdaExpression(out LambdaExpression lambda) { - lambda = new LambdaExpression(); - lambda.ReturnType = new TypeReference("System.Void", true); - Statement statement = null; - lambda.StartLocation = la.Location; - - Expect(210); - Expect(37); - if (StartOf(7)) { - FormalParameterList(lambda.Parameters); - } - Expect(38); - if (StartOf(1)) { - EmbeddedStatement(out statement); - lambda.StatementBody = statement; - lambda.EndLocation = t.EndLocation; - lambda.ExtendedEndLocation = la.Location; - - } else if (la.kind == 1) { - Get(); - Block(out statement); - Expect(113); - Expect(210); - lambda.StatementBody = statement; - lambda.EndLocation = t.EndLocation; - lambda.ExtendedEndLocation = la.Location; - - } else SynErr(293); - } - - void FunctionLambdaExpression(out LambdaExpression lambda) { - lambda = new LambdaExpression(); - TypeReference typeRef = null; - Expression inner = null; - Statement statement = null; - lambda.StartLocation = la.Location; - - Expect(127); - Expect(37); - if (StartOf(7)) { - FormalParameterList(lambda.Parameters); - } - Expect(38); - if (la.kind == 63) { - Get(); - TypeName(out typeRef); - lambda.ReturnType = typeRef; - } - if (StartOf(24)) { - Expr(out inner); - lambda.ExpressionBody = inner; - lambda.EndLocation = t.EndLocation; - lambda.ExtendedEndLocation = la.Location; - - } else if (la.kind == 1) { - Get(); - Block(out statement); - Expect(113); - Expect(127); - lambda.StatementBody = statement; - lambda.EndLocation = t.EndLocation; - lambda.ExtendedEndLocation = la.Location; - - } else SynErr(294); - } - - void EmbeddedStatement(out Statement statement) { - statement = null; - string name = String.Empty; - Location startLocation = la.Location; - - if (la.kind == 120) { - ExitStatement(out statement); - } else if (la.kind == 218) { - TryStatement(out statement); - } else if (la.kind == 89) { - ContinueStatement(out statement); - } else if (la.kind == 215) { - ThrowStatement(out statement); - } else if (la.kind == 195) { - ReturnStatement(out statement); - } else if (la.kind == 211) { - SyncLockStatement(out statement); - } else if (la.kind == 189) { - RaiseEventStatement(out statement); - } else if (la.kind == 233) { - WithStatement(out statement); - } else if (la.kind == 56) { - AddHandlerStatement(out statement); - } else if (la.kind == 193) { - RemoveHandlerStatement(out statement); - } else if (la.kind == 231) { - WhileStatement(out statement); - } else if (la.kind == 108) { - DoLoopStatement(out statement); - } else if (la.kind == 124) { - ForStatement(out statement); - } else if (la.kind == 118) { - ErrorStatement(out statement); - } else if (la.kind == 191) { - ReDimStatement(out statement); - } else if (la.kind == 117) { - EraseStatement(out statement); - } else if (la.kind == 206) { - StopStatement(out statement); - } else if (la.kind == 135) { - IfStatement(out statement); - } else if (la.kind == 197) { - SelectStatement(out statement); - } else if (la.kind == 171) { - OnErrorStatement onErrorStatement = null; - OnErrorStatement(out onErrorStatement); - statement = onErrorStatement; - } else if (la.kind == 132) { - GotoStatement goToStatement = null; - GotoStatement(out goToStatement); - statement = goToStatement; - } else if (la.kind == 194) { - ResumeStatement(out statement); - } else if (StartOf(42)) { - ExpressionStatement(out statement); - } else if (la.kind == 73) { - InvocationStatement(out statement); - } else if (la.kind == 226) { - UsingStatement(out statement); - } else if (StartOf(43)) { - LocalDeclarationStatement(out statement); - } else SynErr(295); - if (statement != null) { - statement.StartLocation = startLocation; - statement.EndLocation = t.EndLocation; - } - - } - - void FromOrAggregateQueryOperator(List middleClauses) { - QueryExpressionFromClause fromClause = null; - QueryExpressionAggregateClause aggregateClause = null; - - if (la.kind == 126) { - FromQueryOperator(out fromClause); - middleClauses.Add(fromClause); - } else if (la.kind == 58) { - AggregateQueryOperator(out aggregateClause); - middleClauses.Add(aggregateClause); - } else SynErr(296); - } - - void QueryOperator(List middleClauses) { - QueryExpressionJoinVBClause joinClause = null; - QueryExpressionGroupVBClause groupByClause = null; - QueryExpressionPartitionVBClause partitionClause = null; - QueryExpressionGroupJoinVBClause groupJoinClause = null; - QueryExpressionFromClause fromClause = null; - QueryExpressionAggregateClause aggregateClause = null; - - if (la.kind == 126) { - FromQueryOperator(out fromClause); - middleClauses.Add(fromClause); - } else if (la.kind == 58) { - AggregateQueryOperator(out aggregateClause); - middleClauses.Add(aggregateClause); - } else if (la.kind == 197) { - SelectQueryOperator(middleClauses); - } else if (la.kind == 107) { - DistinctQueryOperator(middleClauses); - } else if (la.kind == 230) { - WhereQueryOperator(middleClauses); - } else if (la.kind == 176) { - OrderByQueryOperator(middleClauses); - } else if (la.kind == 203 || la.kind == 212) { - PartitionQueryOperator(out partitionClause); - middleClauses.Add(partitionClause); - } else if (la.kind == 148) { - LetQueryOperator(middleClauses); - } else if (la.kind == 146) { - JoinQueryOperator(out joinClause); - middleClauses.Add(joinClause); - } else if (la.kind == Tokens.Group && Peek(1).kind == Tokens.Join) { - GroupJoinQueryOperator(out groupJoinClause); - middleClauses.Add(groupJoinClause); - } else if (la.kind == 133) { - GroupByQueryOperator(out groupByClause); - middleClauses.Add(groupByClause); - } else SynErr(297); - } - - void FromQueryOperator(out QueryExpressionFromClause fromClause) { - fromClause = new QueryExpressionFromClause(); - fromClause.StartLocation = la.Location; - - Expect(126); - CollectionRangeVariableDeclarationList(fromClause.Sources); - fromClause.EndLocation = t.EndLocation; - - } - - void AggregateQueryOperator(out QueryExpressionAggregateClause aggregateClause) { - aggregateClause = new QueryExpressionAggregateClause(); - aggregateClause.IntoVariables = new List(); - aggregateClause.StartLocation = la.Location; - CollectionRangeVariable source; - - Expect(58); - CollectionRangeVariableDeclaration(out source); - aggregateClause.Source = source; - - while (StartOf(31)) { - QueryOperator(aggregateClause.MiddleClauses); - } - Expect(143); - ExpressionRangeVariableDeclarationList(aggregateClause.IntoVariables); - aggregateClause.EndLocation = t.EndLocation; - - } - - void SelectQueryOperator(List middleClauses) { - QueryExpressionSelectVBClause selectClause = new QueryExpressionSelectVBClause(); - selectClause.StartLocation = la.Location; - - Expect(197); - ExpressionRangeVariableDeclarationList(selectClause.Variables); - selectClause.EndLocation = t.Location; - middleClauses.Add(selectClause); - - } - - void DistinctQueryOperator(List middleClauses) { - QueryExpressionDistinctClause distinctClause = new QueryExpressionDistinctClause(); - distinctClause.StartLocation = la.Location; - - Expect(107); - distinctClause.EndLocation = t.EndLocation; - middleClauses.Add(distinctClause); - - } - - void WhereQueryOperator(List middleClauses) { - QueryExpressionWhereClause whereClause = new QueryExpressionWhereClause(); - whereClause.StartLocation = la.Location; - Expression operand = null; - - Expect(230); - Expr(out operand); - whereClause.Condition = operand; - whereClause.EndLocation = t.EndLocation; - - middleClauses.Add(whereClause); - - } - - void OrderByQueryOperator(List middleClauses) { - QueryExpressionOrderClause orderClause = new QueryExpressionOrderClause(); - orderClause.StartLocation = la.Location; - List orderings = null; - - Expect(176); - Expect(70); - OrderExpressionList(out orderings); - orderClause.Orderings = orderings; - orderClause.EndLocation = t.EndLocation; - middleClauses.Add(orderClause); - - } - - void PartitionQueryOperator(out QueryExpressionPartitionVBClause partitionClause) { - partitionClause = new QueryExpressionPartitionVBClause(); - partitionClause.StartLocation = la.Location; - Expression expr = null; - - if (la.kind == 212) { - Get(); - partitionClause.PartitionType = QueryExpressionPartitionType.Take; - if (la.kind == 231) { - Get(); - partitionClause.PartitionType = QueryExpressionPartitionType.TakeWhile; - } - } else if (la.kind == 203) { - Get(); - partitionClause.PartitionType = QueryExpressionPartitionType.Skip; - if (la.kind == 231) { - Get(); - partitionClause.PartitionType = QueryExpressionPartitionType.SkipWhile; - } - } else SynErr(298); - Expr(out expr); - partitionClause.Expression = expr; - partitionClause.EndLocation = t.EndLocation; - - } - - void LetQueryOperator(List middleClauses) { - QueryExpressionLetVBClause letClause = new QueryExpressionLetVBClause(); - letClause.StartLocation = la.Location; - - Expect(148); - ExpressionRangeVariableDeclarationList(letClause.Variables); - letClause.EndLocation = t.EndLocation; - middleClauses.Add(letClause); - - } - - void JoinQueryOperator(out QueryExpressionJoinVBClause joinClause) { - joinClause = new QueryExpressionJoinVBClause(); - joinClause.StartLocation = la.Location; - CollectionRangeVariable joinVariable = null; - QueryExpressionJoinVBClause subJoin = null; - QueryExpressionJoinConditionVB condition = null; - - - Expect(146); - CollectionRangeVariableDeclaration(out joinVariable); - joinClause.JoinVariable = joinVariable; - if (la.kind == 146) { - JoinQueryOperator(out subJoin); - joinClause.SubJoin = subJoin; - } - Expect(171); - JoinCondition(out condition); - SafeAdd(joinClause, joinClause.Conditions, condition); - while (la.kind == 60) { - Get(); - JoinCondition(out condition); - SafeAdd(joinClause, joinClause.Conditions, condition); - } - joinClause.EndLocation = t.EndLocation; - - } - - void GroupJoinQueryOperator(out QueryExpressionGroupJoinVBClause groupJoinClause) { - groupJoinClause = new QueryExpressionGroupJoinVBClause(); - groupJoinClause.StartLocation = la.Location; - QueryExpressionJoinVBClause joinClause = null; - - Expect(133); - JoinQueryOperator(out joinClause); - Expect(143); - ExpressionRangeVariableDeclarationList(groupJoinClause.IntoVariables); - groupJoinClause.JoinClause = joinClause; - groupJoinClause.EndLocation = t.EndLocation; - - } - - void GroupByQueryOperator(out QueryExpressionGroupVBClause groupByClause) { - groupByClause = new QueryExpressionGroupVBClause(); - groupByClause.StartLocation = la.Location; - - Expect(133); - ExpressionRangeVariableDeclarationList(groupByClause.GroupVariables); - Expect(70); - ExpressionRangeVariableDeclarationList(groupByClause.ByVariables); - Expect(143); - ExpressionRangeVariableDeclarationList(groupByClause.IntoVariables); - groupByClause.EndLocation = t.EndLocation; - - } - - void OrderExpressionList(out List orderings) { - orderings = new List(); - QueryExpressionOrdering ordering = null; - - OrderExpression(out ordering); - orderings.Add(ordering); - while (la.kind == 22) { - Get(); - OrderExpression(out ordering); - orderings.Add(ordering); - } - } - - void OrderExpression(out QueryExpressionOrdering ordering) { - ordering = new QueryExpressionOrdering(); - ordering.StartLocation = la.Location; - ordering.Direction = QueryExpressionOrderingDirection.None; - Expression orderExpr = null; - - Expr(out orderExpr); - ordering.Criteria = orderExpr; - - if (la.kind == 64 || la.kind == 104) { - if (la.kind == 64) { - Get(); - ordering.Direction = QueryExpressionOrderingDirection.Ascending; - } else { - Get(); - ordering.Direction = QueryExpressionOrderingDirection.Descending; - } - } - ordering.EndLocation = t.EndLocation; - } - - void ExpressionRangeVariableDeclarationList(List variables) { - ExpressionRangeVariable variable = null; - - ExpressionRangeVariableDeclaration(out variable); - variables.Add(variable); - while (la.kind == 22) { - Get(); - ExpressionRangeVariableDeclaration(out variable); - variables.Add(variable); - } - } - - void CollectionRangeVariableDeclarationList(List rangeVariables) { - CollectionRangeVariable variableDeclaration; - CollectionRangeVariableDeclaration(out variableDeclaration); - rangeVariables.Add(variableDeclaration); - while (la.kind == 22) { - Get(); - CollectionRangeVariableDeclaration(out variableDeclaration); - rangeVariables.Add(variableDeclaration); - } - } - - void CollectionRangeVariableDeclaration(out CollectionRangeVariable rangeVariable) { - rangeVariable = new CollectionRangeVariable(); - rangeVariable.StartLocation = la.Location; - TypeReference typeName = null; - Expression inExpr = null; - - Identifier(); - rangeVariable.Identifier = t.val; - if (la.kind == 63) { - Get(); - TypeName(out typeName); - rangeVariable.Type = typeName; - } - Expect(138); - Expr(out inExpr); - rangeVariable.Expression = inExpr; - rangeVariable.EndLocation = t.EndLocation; - - } - - void ExpressionRangeVariableDeclaration(out ExpressionRangeVariable variable) { - variable = new ExpressionRangeVariable(); - variable.StartLocation = la.Location; - Expression rhs = null; - TypeReference typeName = null; - - if (IsIdentifiedExpressionRange()) { - Identifier(); - variable.Identifier = t.val; - if (la.kind == 63) { - Get(); - TypeName(out typeName); - variable.Type = typeName; - } - Expect(20); - } - Expr(out rhs); - variable.Expression = rhs; - variable.EndLocation = t.EndLocation; - - } - - void JoinCondition(out QueryExpressionJoinConditionVB condition) { - condition = new QueryExpressionJoinConditionVB(); - condition.StartLocation = la.Location; - - Expression lhs = null; - Expression rhs = null; - - Expr(out lhs); - Expect(116); - Expr(out rhs); - condition.LeftSide = lhs; - condition.RightSide = rhs; - condition.EndLocation = t.EndLocation; - - } - - void Argument(out Expression argumentexpr) { - Expression expr; - argumentexpr = null; - string name; - Location startLocation = la.Location; - - if (IsNamedAssign()) { - Identifier(); - name = t.val; - Expect(55); - Expr(out expr); - argumentexpr = new NamedArgumentExpression(name, expr) { StartLocation = startLocation, EndLocation = t.EndLocation }; - - } else if (StartOf(24)) { - Expr(out argumentexpr); - } else SynErr(299); - } - - 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); - } - } - - void RankList(out int i) { - i = 0; - while (la.kind == 22) { - Get(); - ++i; - } - } - - void Attribute(out ASTAttribute attribute) { - string name; - List positional = new List(); - List named = new List(); - Location startLocation = la.Location; - - if (la.kind == 130) { - Get(); - Expect(26); - } - Qualident(out name); - if (la.kind == 37) { - AttributeArguments(positional, named); - } - attribute = new ASTAttribute(name, positional, named) { StartLocation = startLocation, EndLocation = t.EndLocation }; - - } - - void AttributeArguments(List positional, List named) { - bool nameFound = false; - string name = ""; - Expression expr; - - Expect(37); - if (IsNotClosingParenthesis()) { - Location startLocation = la.Location; - if (IsNamedAssign()) { - nameFound = true; - IdentifierOrKeyword(out name); - if (la.kind == 55) { - Get(); - } else if (la.kind == 20) { - Get(); - } else SynErr(301); - } - Expr(out expr); - if (expr != null) { - if (string.IsNullOrEmpty(name)) { positional.Add(expr); } - else { named.Add(new NamedArgumentExpression(name, expr) { StartLocation = startLocation, EndLocation = t.EndLocation }); name = ""; } - } - - while (la.kind == 22) { - Get(); - if (IsNamedAssign()) { - nameFound = true; - IdentifierOrKeyword(out name); - if (la.kind == 55) { - Get(); - } else if (la.kind == 20) { - Get(); - } else SynErr(302); - } else if (StartOf(24)) { - if (nameFound) Error("no positional argument after named argument"); - } else SynErr(303); - Expr(out expr); - if (expr != null) { if(name == "") positional.Add(expr); - else { named.Add(new NamedArgumentExpression(name, expr) { StartLocation = startLocation, EndLocation = t.EndLocation }); name = ""; } - } - - } + default: SynErr(243); break; } - Expect(38); - } - - void ParameterModifier(ParamModifierList m) { - if (la.kind == 72) { - Get(); - m.Add(ParameterModifiers.In); - } else if (la.kind == 69) { - Get(); - m.Add(ParameterModifiers.Ref); - } else if (la.kind == 174) { - Get(); - m.Add(ParameterModifiers.Optional); - } else if (la.kind == 182) { - Get(); - m.Add(ParameterModifiers.Params); - } else SynErr(304); - } - - void Statement() { - Statement stmt = null; - Location startPos = la.Location; - string label = String.Empty; - - if (IsLabel()) { - LabelName(out label); - AddChild(new LabelStatement(t.val)); - - Expect(21); - Statement(); - } else if (StartOf(1)) { - EmbeddedStatement(out stmt); - AddChild(stmt); - } else SynErr(305); - if (stmt != null) { - stmt.StartLocation = startPos; - stmt.EndLocation = t.Location; - } - - } - - void LabelName(out string name) { - name = string.Empty; - - if (StartOf(5)) { - Identifier(); - name = t.val; - } else if (la.kind == 5) { - Get(); - name = t.val; - } else SynErr(306); } - void LocalDeclarationStatement(out Statement statement) { - ModifierList m = new ModifierList(); - LocalVariableDeclaration localVariableDeclaration; - bool dimfound = false; - - while (la.kind == 88 || la.kind == 105 || la.kind == 204) { - if (la.kind == 88) { - Get(); - m.Add(Modifiers.Const, t.Location); - } else if (la.kind == 204) { - Get(); - m.Add(Modifiers.Static, t.Location); - } else { - Get(); - 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); - while (la.kind == 22) { - Get(); - VariableDeclarator(localVariableDeclaration.Variables); - } - statement = localVariableDeclaration; - + void TypeName(out AstType type) { + type = null; + if (StartOf(2)) { + PrimitiveTypeName(out type); + } else if (StartOf(3)) { + QualifiedTypeName(out type); + } else SynErr(244); } - void ExitStatement(out Statement statement) { - Expect(120); - ExitType exitType = ExitType.None; + void PrimitiveTypeName(out AstType type) { + type = null; switch (la.kind) { - case 210: { + case 168: { Get(); - exitType = ExitType.Sub; + type = new PrimitiveType("Object", t.Location); break; } - case 127: { + case 68: { Get(); - exitType = ExitType.Function; + type = new PrimitiveType("Boolean", t.Location); break; } - case 186: { + case 99: { Get(); - exitType = ExitType.Property; + type = new PrimitiveType("Date", t.Location); break; } - case 108: { + case 82: { Get(); - exitType = ExitType.Do; + type = new PrimitiveType("Char", t.Location); break; } - case 124: { + case 208: { Get(); - exitType = ExitType.For; + type = new PrimitiveType("String", t.Location); break; } - case 218: { + case 100: { Get(); - exitType = ExitType.Try; + type = new PrimitiveType("Decimal", t.Location); break; } - case 231: { + case 71: { Get(); - exitType = ExitType.While; + type = new PrimitiveType("Byte", t.Location); break; } - case 197: { + case 201: { Get(); - exitType = ExitType.Select; + type = new PrimitiveType("Short", t.Location); break; } - default: SynErr(307); break; - } - statement = new ExitStatement(exitType); - } - - void TryStatement(out Statement tryStatement) { - Statement blockStmt = null; - Statement finallyStmt = null; - CatchClause clause = null; - List catchClauses = new List(); - - Expect(218); - EndOfStmt(); - Block(out blockStmt); - while (la.kind == 75) { - CatchClause(out clause); - if (clause != null) catchClauses.Add(clause); - } - if (la.kind == 123) { + case 141: { Get(); - EndOfStmt(); - Block(out finallyStmt); - } - Expect(113); - Expect(218); - tryStatement = new TryCatchStatement(blockStmt, catchClauses, finallyStmt); - } - - void ContinueStatement(out Statement statement) { - Expect(89); - ContinueType continueType = ContinueType.None; - if (la.kind == 108 || la.kind == 124 || la.kind == 231) { - if (la.kind == 108) { - Get(); - continueType = ContinueType.Do; - } else if (la.kind == 124) { - Get(); - continueType = ContinueType.For; - } else { - Get(); - continueType = ContinueType.While; - } - } - statement = new ContinueStatement(continueType); - } - - void ThrowStatement(out Statement statement) { - Expression expr = null; - Expect(215); - if (StartOf(24)) { - Expr(out expr); - } - statement = new ThrowStatement(expr); - } - - void ReturnStatement(out Statement statement) { - Expression expr = null; - Expect(195); - if (StartOf(24)) { - Expr(out expr); + type = new PrimitiveType("Integer", t.Location); + break; } - statement = new ReturnStatement(expr); - } - - void SyncLockStatement(out Statement statement) { - Expression expr; Statement embeddedStatement; - Expect(211); - Expr(out expr); - EndOfStmt(); - Block(out embeddedStatement); - Expect(113); - Expect(211); - statement = new LockStatement(expr, embeddedStatement); - } - - void RaiseEventStatement(out Statement statement) { - List arguments = null; - Expect(189); - Identifier(); - string name = t.val; - if (la.kind == 37) { + case 151: { Get(); - ArgumentList(out arguments); - Expect(38); + type = new PrimitiveType("Long", t.Location); + break; } - statement = new RaiseEventStatement(name, arguments); - } - - void WithStatement(out Statement withStatement) { - Statement blockStmt = null; - Expression expr = null; - - Expect(233); - Location start = t.Location; - Expr(out expr); - EndOfStmt(); - withStatement = new WithStatement(expr); - withStatement.StartLocation = start; - - Block(out blockStmt); - ((WithStatement)withStatement).Body = (BlockStatement)blockStmt; - - Expect(113); - Expect(233); - withStatement.EndLocation = t.Location; - } - - void AddHandlerStatement(out Statement statement) { - Expression expr = null; - Expect(56); - Expression handlerExpr = null; - Expr(out expr); - Expect(22); - Expr(out handlerExpr); - statement = new AddHandlerStatement(expr, handlerExpr); - } - - void RemoveHandlerStatement(out Statement statement) { - Expression expr = null; - Expect(193); - Expression handlerExpr = null; - Expr(out expr); - Expect(22); - Expr(out handlerExpr); - statement = new RemoveHandlerStatement(expr, handlerExpr); - } - - void WhileStatement(out Statement statement) { - Expression expr = null; Statement embeddedStatement; - Expect(231); - Expr(out expr); - EndOfStmt(); - Block(out embeddedStatement); - Expect(113); - Expect(231); - statement = new DoLoopStatement(expr, embeddedStatement, ConditionType.While, ConditionPosition.Start); - } - - void DoLoopStatement(out Statement statement) { - Expression expr = null; Statement embeddedStatement; statement = null; - Expect(108); - ConditionType conditionType = ConditionType.None; - if (la.kind == 224 || la.kind == 231) { - WhileOrUntil(out conditionType); - Expr(out expr); - EndOfStmt(); - Block(out embeddedStatement); - Expect(152); - statement = new DoLoopStatement(expr, - embeddedStatement, - conditionType == ConditionType.While ? ConditionType.DoWhile : conditionType, - ConditionPosition.Start); - - } else if (la.kind == 1 || la.kind == 21) { - EndOfStmt(); - Block(out embeddedStatement); - Expect(152); - if (la.kind == 224 || la.kind == 231) { - WhileOrUntil(out conditionType); - Expr(out expr); - } - statement = new DoLoopStatement(expr, embeddedStatement, conditionType, ConditionPosition.End); - } else SynErr(308); - } - - void ForStatement(out Statement statement) { - Expression expr = null; Statement embeddedStatement; statement = null; Location startLocation = la.Location; - Expect(124); - Expression group = null; - TypeReference typeReference; - string typeName; - - if (la.kind == 110) { + case 202: { Get(); - LoopControlVariable(out typeReference, out typeName); - Expect(138); - Expr(out group); - EndOfStmt(); - Block(out embeddedStatement); - Expect(163); - if (StartOf(24)) { - Expr(out expr); - } - statement = new ForeachStatement(typeReference, - typeName, - group, - embeddedStatement, - expr); - statement.StartLocation = startLocation; - statement.EndLocation = t.EndLocation; - - - } else if (StartOf(42)) { - Expression start = null; - Expression end = null; - Expression step = null; - Expression variableExpr = null; - Expression nextExpr = null; - List nextExpressions = null; - - if (IsLoopVariableDeclaration()) { - LoopControlVariable(out typeReference, out typeName); - } else { - typeReference = null; typeName = null; - SimpleExpr(out variableExpr); - } - Expect(20); - Expr(out start); - Expect(216); - Expr(out end); - if (la.kind == 205) { - Get(); - Expr(out step); - } - EndOfStmt(); - Block(out embeddedStatement); - Expect(163); - if (StartOf(24)) { - Expr(out nextExpr); - nextExpressions = new List(); - nextExpressions.Add(nextExpr); - - while (la.kind == 22) { - Get(); - Expr(out nextExpr); - nextExpressions.Add(nextExpr); - } - } - statement = new ForNextStatement { - TypeReference = typeReference, - VariableName = typeName, - LoopVariableExpression = variableExpr, - Start = start, - End = end, - Step = step, - EmbeddedStatement = embeddedStatement, - NextExpressions = nextExpressions - }; - - } else SynErr(309); - } - - void ErrorStatement(out Statement statement) { - Expression expr = null; - Expect(118); - Expr(out expr); - statement = new ErrorStatement(expr); - } - - void ReDimStatement(out Statement statement) { - Expression expr = null; - Expect(191); - bool isPreserve = false; - if (la.kind == 184) { - Expect(184); - isPreserve = true; + type = new PrimitiveType("Single", t.Location); + break; } - ReDimClause(out expr); - ReDimStatement reDimStatement = new ReDimStatement(isPreserve); - statement = reDimStatement; - SafeAdd(reDimStatement, reDimStatement.ReDimClauses, expr as InvocationExpression); - - while (la.kind == 22) { + case 109: { Get(); - ReDimClause(out expr); - SafeAdd(reDimStatement, reDimStatement.ReDimClauses, expr as InvocationExpression); + type = new PrimitiveType("Double", t.Location); + break; } - } - - void EraseStatement(out Statement statement) { - Expression expr = null; - Expect(117); - Expr(out expr); - EraseStatement eraseStatement = new EraseStatement(); - if (expr != null) { SafeAdd(eraseStatement, eraseStatement.Expressions, expr);} - - while (la.kind == 22) { + case 221: { Get(); - Expr(out expr); - if (expr != null) { SafeAdd(eraseStatement, eraseStatement.Expressions, expr); } + type = new PrimitiveType("UInteger", t.Location); + break; } - statement = eraseStatement; - } - - void StopStatement(out Statement statement) { - Expect(206); - statement = new StopStatement(); - } - - void IfStatement(out Statement statement) { - Expression expr = null; Statement embeddedStatement; statement = null; - Expect(135); - Location ifStartLocation = t.Location; - Expr(out expr); - if (la.kind == 214) { + case 222: { Get(); + type = new PrimitiveType("ULong", t.Location); + break; } - if (la.kind == 1 || la.kind == 21) { - EndOfStmt(); - Block(out embeddedStatement); - IfElseStatement ifStatement = new IfElseStatement(expr, embeddedStatement); - ifStatement.StartLocation = ifStartLocation; - Location elseIfStart; - - while (la.kind == 112 || (IsElseIf())) { - if (IsElseIf()) { - Expect(111); - elseIfStart = t.Location; - Expect(135); - } else { - Get(); - elseIfStart = t.Location; - } - Expression condition = null; Statement block = null; - Expr(out condition); - if (la.kind == 214) { - Get(); - } - EndOfStmt(); - Block(out block); - ElseIfSection elseIfSection = new ElseIfSection(condition, block); - elseIfSection.StartLocation = elseIfStart; - elseIfSection.EndLocation = t.Location; - elseIfSection.Parent = ifStatement; - ifStatement.ElseIfSections.Add(elseIfSection); - - } - if (la.kind == 111) { - Get(); - if (la.kind == 1 || la.kind == 21) { - EndOfStmt(); - } - Block(out embeddedStatement); - ifStatement.FalseStatement.Add(embeddedStatement); - - } - Expect(113); - Expect(135); - ifStatement.EndLocation = t.Location; - statement = ifStatement; - - } else if (StartOf(44)) { - IfElseStatement ifStatement = new IfElseStatement(expr); - ifStatement.StartLocation = ifStartLocation; - - SingleLineStatementList(ifStatement.TrueStatement); - if (la.kind == 111) { - Get(); - if (StartOf(44)) { - SingleLineStatementList(ifStatement.FalseStatement); - } - } - ifStatement.EndLocation = t.Location; statement = ifStatement; - } else SynErr(310); - } - - void SelectStatement(out Statement statement) { - Expression expr = null; - Expect(197); - if (la.kind == 74) { + case 225: { Get(); + type = new PrimitiveType("UShort", t.Location); + break; } - Expr(out expr); - EndOfStmt(); - List selectSections = new List(); - Statement block = null; - - while (la.kind == 74) { - List caseClauses = null; Location caseLocation = la.Location; + case 196: { Get(); - CaseClauses(out caseClauses); - if (IsNotStatementSeparator()) { - Expect(21); - } - EndOfStmt(); - SwitchSection selectSection = new SwitchSection(caseClauses); - selectSection.StartLocation = caseLocation; - - Block(out block); - selectSection.Children = block.Children; - selectSection.EndLocation = t.EndLocation; - selectSections.Add(selectSection); - + type = new PrimitiveType("SByte", t.Location); + break; } - statement = new SwitchStatement(expr, selectSections); - - Expect(113); - Expect(197); - } - - void OnErrorStatement(out OnErrorStatement stmt) { - stmt = null; - Location startLocation = la.Location; - GotoStatement goToStatement = null; - - Expect(171); - Expect(118); - if (IsNegativeLabelName()) { - Expect(132); - Expect(30); - Expect(5); - long intLabel = Int64.Parse(t.val); - if(intLabel != 1) { - Error("invalid label in on error statement."); - } - stmt = new OnErrorStatement(new GotoStatement((intLabel * -1).ToString())); - - } else if (la.kind == 132) { - GotoStatement(out goToStatement); - string val = goToStatement.Label; - - // if value is numeric, make sure that is 0 - try { - long intLabel = Int64.Parse(val); - if(intLabel != 0) { - Error("invalid label in on error statement."); - } - } catch { - } - stmt = new OnErrorStatement(goToStatement); - - } else if (la.kind == 194) { - Get(); - Expect(163); - stmt = new OnErrorStatement(new ResumeStatement(true)); - - } else SynErr(311); - if (stmt != null) { - stmt.StartLocation = startLocation; - stmt.EndLocation = t.EndLocation; - } - - } - - void GotoStatement(out GotoStatement goToStatement) { - string label = string.Empty; - Location startLocation = la.Location; - - Expect(132); - LabelName(out label); - goToStatement = new GotoStatement(label) { - StartLocation = startLocation, - EndLocation = t.EndLocation - }; - - } - - void ResumeStatement(out Statement resumeStatement) { - resumeStatement = null; - string label = string.Empty; - - Expect(194); - if (StartOf(45)) { - if (la.kind == 163) { - Get(); - resumeStatement = new ResumeStatement(true); - } else { - LabelName(out label); - } + default: SynErr(245); break; } - resumeStatement = new ResumeStatement(label); - } - - void ExpressionStatement(out Statement statement) { - Expression expr = null; - Expression val = null; - AssignmentOperatorType op; - Location startLoc = la.Location; - - bool mustBeAssignment = la.kind == Tokens.Plus || la.kind == Tokens.Minus || - la.kind == Tokens.Not || la.kind == Tokens.Times; - - SimpleExpr(out expr); - if (StartOf(46)) { - AssignmentOperator(out op); - Expr(out val); - expr = new AssignmentExpression(expr, op, val); - expr.StartLocation = startLoc; - expr.EndLocation = t.EndLocation; - - } else if (la.kind == 1 || la.kind == 21 || la.kind == 111) { - if (mustBeAssignment) Error("error in assignment."); - } else SynErr(312); - if(expr is MemberReferenceExpression || expr is IdentifierExpression) { - Location endLocation = expr.EndLocation; - expr = new InvocationExpression(expr); - expr.StartLocation = startLoc; - expr.EndLocation = endLocation; - } - statement = new ExpressionStatement(expr); - - } - - void InvocationStatement(out Statement statement) { - Expression expr = null; - Expect(73); - SimpleExpr(out expr); - statement = new ExpressionStatement(expr); - } - - void UsingStatement(out Statement statement) { - Expression expr = null; Statement block; statement = null; - Expect(226); - if (Peek(1).kind == Tokens.As) { - LocalVariableDeclaration resourceAquisition = - new LocalVariableDeclaration(Modifiers.None); - VariableDeclarator(resourceAquisition.Variables); - while (la.kind == 22) { - Get(); - VariableDeclarator(resourceAquisition.Variables); - } - EndOfStmt(); - Block(out block); - statement = new UsingStatement(resourceAquisition, block); - } else if (StartOf(24)) { - Expr(out expr); - EndOfStmt(); - Block(out block); - statement = new UsingStatement(new ExpressionStatement(expr), block); - } else SynErr(313); - Expect(113); - Expect(226); } - void WhileOrUntil(out ConditionType conditionType) { - conditionType = ConditionType.None; - if (la.kind == 231) { - Get(); - conditionType = ConditionType.While; - } else if (la.kind == 224) { + void QualifiedTypeName(out AstType type) { + if (la.kind == 130) { Get(); - conditionType = ConditionType.Until; - } else SynErr(314); - } - - 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) { + } else if (StartOf(4)) { + Identifier(); + } else SynErr(246); + type = new SimpleType(t.val, t.Location); + while (la.kind == 26) { Get(); - TypeName(out type); - if (name.IndexOf('.') > 0) { Error("No type def for 'for each' member indexer allowed."); } + Identifier(); + type = new QualifiedType(type, new Identifier(t.val, t.Location)); } - 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)); - } - } - - } - - void ReDimClause(out Expression expr) { - SimpleNonInvocationExpression(out expr); - ReDimClauseInternal(ref expr); } - void SingleLineStatementList(List list) { - Statement embeddedStatement = null; - if (la.kind == 113) { + void OnOff(OptionStatement os) { + if (la.kind == 171) { Get(); - embeddedStatement = new EndStatement() { StartLocation = t.Location, EndLocation = t.EndLocation }; - } else if (StartOf(1)) { - EmbeddedStatement(out embeddedStatement); - } else SynErr(315); - if (embeddedStatement != null) list.Add(embeddedStatement); - while (la.kind == 21) { + AddTerminal(Ast.OptionStatement.OptionValueRole); + os.OptionValue = OptionValue.On; + } else if (la.kind == 170) { Get(); - while (la.kind == 21) { - Get(); - } - if (la.kind == 113) { - Get(); - embeddedStatement = new EndStatement() { StartLocation = t.Location, EndLocation = t.EndLocation }; - } else if (StartOf(1)) { - EmbeddedStatement(out embeddedStatement); - } else SynErr(316); - if (embeddedStatement != null) list.Add(embeddedStatement); - } + AddTerminal(Ast.OptionStatement.OptionValueRole); + os.OptionValue = OptionValue.Off; + } else SynErr(247); } - void CaseClauses(out List caseClauses) { - caseClauses = new List(); - CaseLabel caseClause = null; - - CaseClause(out caseClause); - if (caseClause != null) { caseClauses.Add(caseClause); } - while (la.kind == 22) { + void BinaryText(OptionStatement os) { + if (la.kind == 213) { Get(); - CaseClause(out caseClause); - if (caseClause != null) { caseClauses.Add(caseClause); } - } + AddTerminal(Ast.OptionStatement.OptionValueRole); + os.OptionValue = OptionValue.Text; + } else if (la.kind == 67) { + Get(); + AddTerminal(Ast.OptionStatement.OptionValueRole); + os.OptionValue = OptionValue.Binary; + } else SynErr(248); } - void ReDimClauseInternal(ref Expression expr) { - List arguments; bool canBeNormal; bool canBeRedim; string name; Location startLocation = la.Location; - while (la.kind == 26 || (la.kind == Tokens.OpenParenthesis && Peek(1).kind == Tokens.Of)) { - if (la.kind == 26) { - Get(); - IdentifierOrKeyword(out name); - expr = new MemberReferenceExpression(expr, name) { StartLocation = startLocation, EndLocation = t.EndLocation }; - } else { - InvocationExpression(ref expr); - expr.StartLocation = startLocation; - expr.EndLocation = t.EndLocation; - - } - } - Expect(37); - NormalOrReDimArgumentList(out arguments, out canBeNormal, out canBeRedim); - Expect(38); - expr = new InvocationExpression(expr, arguments); - if (canBeRedim == false || canBeNormal && (la.kind == Tokens.Dot || la.kind == Tokens.OpenParenthesis)) { - if (this.Errors.Count == 0) { - // don't recurse on parse errors - could result in endless recursion - ReDimClauseInternal(ref expr); - } - } - + void ImportsClause() { + if (IsAliasImportsClause()) { + AliasImportsClause(Ast.ImportsStatement.ImportsClauseRole); + } else if (StartOf(5)) { + MemberImportsClause(Ast.ImportsStatement.ImportsClauseRole); + } else if (la.kind == 10) { + XmlNamespaceImportsClause(Ast.ImportsStatement.ImportsClauseRole); + } else SynErr(249); + while (!(StartOf(6))) {SynErr(250); Get();} } - void CaseClause(out CaseLabel caseClause) { - Expression expr = null; - Expression sexpr = null; - BinaryOperatorType op = BinaryOperatorType.None; - caseClause = null; - - if (la.kind == 111) { - Get(); - caseClause = new CaseLabel(); - } else if (StartOf(47)) { - if (la.kind == 144) { - Get(); - } - switch (la.kind) { - case 40: { - Get(); - op = BinaryOperatorType.LessThan; - break; - } - case 39: { - Get(); - op = BinaryOperatorType.GreaterThan; - break; - } - case 43: { - Get(); - op = BinaryOperatorType.LessThanOrEqual; - break; - } - case 42: { - Get(); - op = BinaryOperatorType.GreaterThanOrEqual; - break; - } - case 20: { - Get(); - op = BinaryOperatorType.Equality; - break; - } - case 41: { - Get(); - op = BinaryOperatorType.InEquality; - break; - } - default: SynErr(317); break; - } - Expr(out expr); - caseClause = new CaseLabel(op, expr); - - } else if (StartOf(24)) { - Expr(out expr); - if (la.kind == 216) { - Get(); - Expr(out sexpr); - } - caseClause = new CaseLabel(expr, sexpr); - - } else SynErr(318); + void AliasImportsClause(Role role) { + var result = new AliasImportsClause(); NodeStart(result); + AstType alias; + Identifier(); + result.Name = new Identifier(t.val, t.Location); + Expect(20); + TypeName(out alias); + result.Alias = alias; + NodeEnd(result, role); } - void CatchClause(out CatchClause catchClause) { - TypeReference type = null; - Statement blockStmt = null; - Expression expr = null; - string name = String.Empty; + void MemberImportsClause(Role role) { + var result = new MemberImportsClause(); NodeStart(result); + AstType member; + TypeName(out member); + result.Member = member; + NodeEnd(result, role); + } - Expect(75); - if (StartOf(5)) { - Identifier(); - name = t.val; - if (la.kind == 63) { - Get(); - TypeName(out type); - } - } - if (la.kind == 229) { - Get(); - Expr(out expr); - } - EndOfStmt(); - Block(out blockStmt); - catchClause = new CatchClause(type, name, blockStmt, expr); + void XmlNamespaceImportsClause(Role role) { + var result = new XmlNamespaceImportsClause(); NodeStart(result); + Expect(10); + AddTerminal(Roles.XmlOpenTag); + Identifier(); + Expect(20); + AddTerminal(Roles.Assign); + Expect(3); + Expect(11); + AddTerminal(Roles.XmlCloseTag); + NodeEnd(result, role); } @@ -5094,54 +482,13 @@ partial class VBParser } static readonly BitArray[] set = { - new BitArray(new int[] {2097155, 0, 0, 0, 0, 0, 0, 0}), - new BitArray(new int[] {1007618044, 1191182376, -1051937, 1466973983, -1030969162, -1593504476, -21406146, 711}), - new BitArray(new int[] {0, 256, 1048576, 537395328, 402669568, 444596289, 131456, 0}), - new BitArray(new int[] {0, 256, 1048576, 537395328, 402669568, 444596288, 131456, 0}), - new BitArray(new int[] {0, 0, 0, 536870912, 268435456, 444596288, 384, 0}), - new BitArray(new int[] {4, 1140850688, 8388687, 1108347140, 821280, 17105920, -2144335872, 65}), + new BitArray(new int[] {6291459, 0, 0, 0, 0, 0, 0, 0}), new BitArray(new int[] {4, 1140850688, 8388687, 1108347136, 821280, 17105920, -2144335872, 65}), - new BitArray(new int[] {4, 1140850944, 8388975, 1108347140, 821280, 21316608, -2144335872, 65}), - new BitArray(new int[] {4, 1140850688, 9699551, 1108355356, 9218084, 17106180, -533524976, 67}), - new BitArray(new int[] {4, 1140850688, 8650975, 1108355356, 9218084, 17106176, -533656048, 67}), - new BitArray(new int[] {4, 1140850944, 26214479, -493351964, 940361760, 1606227138, -2143942272, 3393}), - new BitArray(new int[] {0, 0, 0, 536871488, 805306368, 1522008256, 384, 3072}), + new BitArray(new int[] {0, 0, 262288, 8216, 8396800, 256, 1610679824, 2}), new BitArray(new int[] {4, 1140850688, 8388687, 1108347140, 821284, 17105920, -2144335872, 65}), - new BitArray(new int[] {0, 0, 262288, 8216, 8396800, 0, 1610679824, 2}), - new BitArray(new int[] {4, 1140850944, 8388687, 1108347140, 821280, 17105920, -2144335872, 65}), - new BitArray(new int[] {0, 256, 1048576, -1601699136, 939540480, 1589117120, 393600, 3072}), - new BitArray(new int[] {0, 1073741824, 4, -2147483648, 0, 0, -2147221504, 0}), - new BitArray(new int[] {2097154, 32, 0, 0, 256, 0, 0, 0}), - new BitArray(new int[] {0, 256, 0, 536870912, 1, 436207616, 64, 0}), - new BitArray(new int[] {0, 16777472, 0, 0, 0, 536870912, 2, 0}), - new BitArray(new int[] {0, 256, 0, -1602223552, 805306368, 1589117120, 262528, 3072}), - new BitArray(new int[] {0, 0, 1048576, 524416, 134234112, 0, 131072, 0}), - new BitArray(new int[] {-66123780, 1174405164, -51384097, 1175465247, -1030969178, 17106228, -97448432, 67}), - new BitArray(new int[] {7340034, -2147483648, 0, 32768, 0, 0, 0, 0}), - new BitArray(new int[] {-66123780, 1174405164, -51384097, -972018401, -1030969178, 17106228, -97186288, 67}), - new BitArray(new int[] {0, 0, 0, 536870912, 1, 436207616, 0, 0}), - new BitArray(new int[] {0, 256, 0, 536870912, 0, 436207616, 64, 0}), - new BitArray(new int[] {0, 0, 0, 536870912, 0, 436207616, 64, 0}), - new BitArray(new int[] {0, 256, 0, 536870912, 1, 436207616, 0, 0}), - new BitArray(new int[] {0, 0, 288, 0, 0, 4210688, 0, 0}), - new BitArray(new int[] {0, 0, 0, 536870912, 0, 436207616, 0, 0}), - new BitArray(new int[] {0, 67108864, 0, 1073743872, 1310752, 65536, 1050656, 64}), - new BitArray(new int[] {1006632960, 32, 0, 0, 0, 0, 0, 0}), - new BitArray(new int[] {-2, -1, -1, -1, -1, -1, -1, -1}), - new BitArray(new int[] {985084, 1174405160, -51384097, 1175465247, -1030969178, 17106212, -97448432, 67}), - new BitArray(new int[] {1006632960, 0, 0, 0, 0, 0, 0, 0}), - new BitArray(new int[] {983040, 0, 0, 0, 0, 0, 0, 0}), - new BitArray(new int[] {4100, 1140850688, 8388687, 1108347140, 821280, 17105920, -2144335872, 65}), - new BitArray(new int[] {988160, 0, 0, 0, 0, 0, 0, 0}), - new BitArray(new int[] {-2050, -1, -1, -1, -1, -1, -1, -1}), - new BitArray(new int[] {1048576, 3968, 0, 0, 4390912, 0, 0, 0}), - new BitArray(new int[] {-66123780, 1174405164, -51384097, 1175465247, -1030969178, 17106212, -97448432, 67}), - new BitArray(new int[] {1007618044, 1174405160, -51384097, 1175465247, -1030969178, 17106212, -97448432, 67}), - new BitArray(new int[] {4, 1140850688, 25165903, 1108347652, 821280, 17105920, -2144331776, 65}), - new BitArray(new int[] {1007618044, 1191182376, -1051937, 1467105055, -1030969162, -1593504476, -21406146, 711}), - new BitArray(new int[] {36, 1140850688, 8388687, 1108347140, 821280, 17105928, -2144335872, 65}), - new BitArray(new int[] {1048576, 8372224, 0, 0, 0, 0, 0, 0}), - new BitArray(new int[] {1048576, 3968, 0, 0, 65536, 0, 0, 0}) + new BitArray(new int[] {4, 1140850688, 8388687, 1108347140, 821280, 17105920, -2144335872, 65}), + new BitArray(new int[] {4, 1140850688, 8650975, 1108355356, 9218084, 17106176, -533656048, 67}), + new BitArray(new int[] {6291459, 0, 0, 0, 0, 0, 0, 0}) }; @@ -5392,86 +739,18 @@ partial class VBParser case 236: return "\"Xor\" expected"; case 237: return "\"GetXmlNamespace\" expected"; case 238: return "??? expected"; - case 239: return "this symbol not expected in EndOfStmt"; - case 240: return "invalid EndOfStmt"; - case 241: return "invalid OptionStmt"; - case 242: return "invalid OptionStmt"; - case 243: return "invalid GlobalAttributeSection"; - case 244: return "invalid GlobalAttributeSection"; - case 245: return "invalid NamespaceMemberDecl"; - case 246: return "invalid OptionValue"; - case 247: return "invalid ImportClause"; - case 248: return "invalid Identifier"; - case 249: return "invalid AttributeSection"; - case 250: return "invalid TypeModifier"; - case 251: return "invalid NonModuleDeclaration"; - case 252: return "invalid NonModuleDeclaration"; - case 253: return "invalid TypeParameterConstraints"; - case 254: return "invalid TypeParameterConstraint"; - case 255: return "invalid NonArrayTypeName"; - case 256: return "invalid MemberModifier"; - case 257: return "invalid StructureMemberDecl"; - case 258: return "invalid StructureMemberDecl"; - case 259: return "invalid StructureMemberDecl"; - case 260: return "invalid StructureMemberDecl"; - case 261: return "invalid StructureMemberDecl"; - case 262: return "invalid StructureMemberDecl"; - case 263: return "invalid StructureMemberDecl"; - case 264: return "invalid StructureMemberDecl"; - case 265: return "invalid InterfaceMemberDecl"; - case 266: return "invalid InterfaceMemberDecl"; - case 267: return "invalid Expr"; - case 268: return "invalid Block"; - case 269: return "invalid Charset"; - case 270: return "invalid IdentifierForFieldDeclaration"; - case 271: return "invalid VariableDeclaratorPartAfterIdentifier"; - case 272: return "invalid ObjectCreateExpression"; - case 273: return "invalid ObjectCreateExpression"; - case 274: return "invalid AccessorDecls"; - case 275: return "invalid EventAccessorDeclaration"; - case 276: return "invalid OverloadableOperator"; - case 277: return "invalid EventMemberSpecifier"; - case 278: return "invalid LambdaExpr"; - case 279: return "invalid AssignmentOperator"; - case 280: return "invalid SimpleExpr"; - case 281: return "invalid SimpleNonInvocationExpression"; - case 282: return "invalid SimpleNonInvocationExpression"; - case 283: return "invalid PrimitiveTypeName"; - case 284: return "invalid CastTarget"; - case 285: return "invalid XmlLiteralExpression"; - case 286: return "invalid XmlContentExpression"; - case 287: return "invalid XmlElement"; - case 288: return "invalid XmlElement"; - case 289: return "invalid XmlNestedContent"; - case 290: return "invalid XmlAttribute"; - case 291: return "invalid XmlAttribute"; - case 292: return "invalid ComparisonExpr"; - case 293: return "invalid SubLambdaExpression"; - case 294: return "invalid FunctionLambdaExpression"; - case 295: return "invalid EmbeddedStatement"; - case 296: return "invalid FromOrAggregateQueryOperator"; - case 297: return "invalid QueryOperator"; - case 298: return "invalid PartitionQueryOperator"; - case 299: return "invalid Argument"; - case 300: return "invalid QualIdentAndTypeArguments"; - case 301: return "invalid AttributeArguments"; - case 302: return "invalid AttributeArguments"; - case 303: return "invalid AttributeArguments"; - case 304: return "invalid ParameterModifier"; - case 305: return "invalid Statement"; - case 306: return "invalid LabelName"; - case 307: return "invalid ExitStatement"; - case 308: return "invalid DoLoopStatement"; - case 309: return "invalid ForStatement"; - case 310: return "invalid IfStatement"; - case 311: return "invalid OnErrorStatement"; - case 312: return "invalid ExpressionStatement"; - case 313: return "invalid UsingStatement"; - case 314: return "invalid WhileOrUntil"; - case 315: return "invalid SingleLineStatementList"; - case 316: return "invalid SingleLineStatementList"; - case 317: return "invalid CaseClause"; - case 318: return "invalid CaseClause"; + case 239: return "this symbol not expected in StatementTerminator"; + case 240: return "invalid StatementTerminator"; + case 241: return "invalid OptionStatement"; + case 242: return "invalid Identifier"; + case 243: return "invalid IdentifierForFieldDeclaration"; + case 244: return "invalid TypeName"; + case 245: return "invalid PrimitiveTypeName"; + case 246: return "invalid QualifiedTypeName"; + case 247: return "invalid OnOff"; + case 248: return "invalid BinaryText"; + case 249: return "invalid ImportsClause"; + case 250: return "this symbol not expected in ImportsClause"; default: return "error " + errorNumber; } diff --git a/ICSharpCode.NRefactory.VB/Parser/VBParser.cs b/ICSharpCode.NRefactory.VB/Parser/VBParser.cs index 07c67597c..c099d7981 100644 --- a/ICSharpCode.NRefactory.VB/Parser/VBParser.cs +++ b/ICSharpCode.NRefactory.VB/Parser/VBParser.cs @@ -12,13 +12,12 @@ using ICSharpCode.NRefactory.VB.Visitors; namespace ICSharpCode.NRefactory.VB.Parser { - public partial class VBParser : IDisposable + internal partial class VBParser : IDisposable { VBLexer lexer; - Stack blockStack; + Stack stack; CompilationUnit compilationUnit; int errDist = MinErrDist; - bool parseMethodContents = true; const int MinErrDist = 2; const string ErrMsgFormat = "-- line {0} col {1}: {2}"; // 0=line, 1=column, 2=text @@ -28,25 +27,31 @@ namespace ICSharpCode.NRefactory.VB.Parser this.errors = lexer.Errors; errors.SynErr = new ErrorCodeProc(SynErr); this.lexer = (VBLexer)lexer; - this.blockStack = new Stack(); + this.stack = new Stack(); } - void BlockStart(INode block) + #region Infrastructure + void NodeStart(AstNode node) { - blockStack.Push(block); + stack.Push(node); } - void BlockEnd() + void NodeEnd(AstNode currentNode, Role role) { - blockStack.Pop(); + AstNode node = stack.Pop(); + Debug.Assert(currentNode == node); + stack.Peek().AddChildUntyped(node, role); } - void AddChild(INode childNode) + void AddTerminal(Role role) + { + stack.Peek().AddChild(new VBTokenNode(t.Location, t.EndLocation), role); + } + + void AddChild(T childNode, Role role) where T : AstNode { if (childNode != null) { - INode parent = (INode)blockStack.Peek(); - parent.Children.Add(childNode); - childNode.Parent = parent; + stack.Peek().AddChild(childNode, role); } } @@ -59,6 +64,7 @@ namespace ICSharpCode.NRefactory.VB.Parser return lexer.Token; } } + Token la { [System.Diagnostics.DebuggerStepThrough] @@ -67,7 +73,7 @@ namespace ICSharpCode.NRefactory.VB.Parser } } - Token Peek (int n) + Token Peek(int n) { lexer.StartPeek(); Token x = la; @@ -85,78 +91,87 @@ namespace ICSharpCode.NRefactory.VB.Parser } errDist = 0; } - + #endregion + + #region Parse public void Parse() { ParseRoot(); - compilationUnit.AcceptVisitor(new SetParentVisitor(), null); } - public TypeReference ParseTypeReference () + public AstType ParseAstType() { // TODO return null; } - public Expression ParseExpression() - { - lexer.SetInitialContext(SnippetType.Expression); - lexer.NextToken(); - Location startLocation = la.Location; - Expression expr; - Expr(out expr); - while (la.kind == Tokens.EOL) lexer.NextToken(); - if (expr != null) { - expr.StartLocation = startLocation; - expr.EndLocation = t.EndLocation; - expr.AcceptVisitor(new SetParentVisitor(), null); - } - Expect(Tokens.EOF); - return expr; - } +// public Expression ParseExpression() +// { +// lexer.SetInitialContext(SnippetType.Expression); +// lexer.NextToken(); +// Location startLocation = la.Location; +// Expression expr; +// Expr(out expr); +// while (la.kind == Tokens.EOL) lexer.NextToken(); +// if (expr != null) { +// expr.StartLocation = startLocation; +// expr.EndLocation = t.EndLocation; +// expr.AcceptVisitor(new SetParentVisitor(), null); +// } +// Expect(Tokens.EOF); +// return expr; +// } + +// public BlockStatement ParseBlock() +// { +// lexer.NextToken(); +// compilationUnit = new CompilationUnit(); +// +// Location startLocation = la.Location; +// Statement st; +// Block(out st); +// if (st != null) { +// st.StartLocation = startLocation; +// if (t != null) +// st.EndLocation = t.EndLocation; +// else +// st.EndLocation = la.Location; +// st.AcceptVisitor(new SetParentVisitor(), null); +// } +// Expect(Tokens.EOF); +// return st as BlockStatement; +// } + +// public List ParseTypeMembers() +// { +// lexer.NextToken(); +// TypeDeclaration newType = new TypeDeclaration(Modifiers.None, null); +// BlockStart(newType); +// ClassBody(newType); +// BlockEnd(); +// Expect(Tokens.EOF); +// newType.AcceptVisitor(new SetParentVisitor(), null); +// return newType.Children; +// } + #endregion - public BlockStatement ParseBlock() + #region Conflict Resolvers + bool IsAliasImportsClause() { - lexer.NextToken(); - compilationUnit = new CompilationUnit(); - - Location startLocation = la.Location; - Statement st; - Block(out st); - if (st != null) { - st.StartLocation = startLocation; - if (t != null) - st.EndLocation = t.EndLocation; - else - st.EndLocation = la.Location; - st.AcceptVisitor(new SetParentVisitor(), null); - } - Expect(Tokens.EOF); - return st as BlockStatement; + return IsIdentifierToken(la) && Peek(1).Kind == Tokens.Assign; } - public List ParseTypeMembers() + static bool IsIdentifierToken(Token tk) { - lexer.NextToken(); - TypeDeclaration newType = new TypeDeclaration(Modifiers.None, null); - BlockStart(newType); - ClassBody(newType); - BlockEnd(); - Expect(Tokens.EOF); - newType.AcceptVisitor(new SetParentVisitor(), null); - return newType.Children; + return Tokens.IdentifierTokens[tk.kind] || tk.kind == Tokens.Identifier; } - + #endregion + /* True, if "." is followed by an ident */ bool DotAndIdentOrKw () { int peek = Peek(1).kind; return la.kind == Tokens.Dot && (peek == Tokens.Identifier || peek >= Tokens.AddHandler); } - - static bool IsIdentifierToken(Token tk) - { - return Tokens.IdentifierTokens[tk.kind] || tk.kind == Tokens.Identifier; - } bool IsIdentifiedExpressionRange() { @@ -331,39 +346,29 @@ namespace ICSharpCode.NRefactory.VB.Parser return la.kind == Tokens.Colon && Peek(1).kind == Tokens.EOL; } - static bool IsMustOverride(ModifierList m) + static bool IsMustOverride(AttributedNode node) { - return m.Contains(Modifiers.Abstract); + return node.Modifiers.HasFlag(Modifiers.MustOverride); } /* Writes the type name represented through the expression into the string builder. */ /* Returns true when the expression was converted successfully, returns false when */ /* There was an unknown expression (e.g. TypeReferenceExpression) in it */ - bool WriteFullTypeName(StringBuilder b, Expression expr) - { - MemberReferenceExpression fre = expr as MemberReferenceExpression; - if (fre != null) { - bool result = WriteFullTypeName(b, fre.TargetObject); - if (b.Length > 0) b.Append('.'); - b.Append(fre.MemberName); - return result; - } else if (expr is IdentifierExpression) { - b.Append(((IdentifierExpression)expr).Identifier); - return true; - } else { - return false; - } - } - - /* - True, if lookahead is a local attribute target specifier, - i.e. one of "event", "return", "field", "method", - "module", "param", "property", or "type" - */ - bool IsLocalAttrTarget() { - // TODO - return false; - } +// bool WriteFullTypeName(StringBuilder b, Expression expr) +// { +// MemberReferenceExpression fre = expr as MemberReferenceExpression; +// if (fre != null) { +// bool result = WriteFullTypeName(b, fre.TargetObject); +// if (b.Length > 0) b.Append('.'); +// b.Append(fre.MemberName); +// return result; +// } else if (expr is SimpleNameExpression) { +// b.Append(((SimpleNameExpression)expr).Identifier); +// return true; +// } else { +// return false; +// } +// } void EnsureIsZero(Expression expr) { @@ -371,31 +376,7 @@ namespace ICSharpCode.NRefactory.VB.Parser Error("lower bound of array must be zero"); } - /// - /// Adds a child item to a collection stored in the parent node. - /// Also set's the item's parent to . - /// Does nothing if item is null. - /// - static void SafeAdd(INode parent, List list, T item) where T : class, INode - { - Debug.Assert(parent != null); - Debug.Assert((parent is INullable) ? !(parent as INullable).IsNull : true); - if (item != null) { - list.Add(item); - item.Parent = parent; - } - } - - - - public bool ParseMethodBodies { - get { - return parseMethodContents; - } - set { - parseMethodContents = value; - } - } + public bool ParseMethodBodies { get; set; } public VBLexer Lexer { get { diff --git a/ICSharpCode.NRefactory.VB/Parser/vb.atg b/ICSharpCode.NRefactory.VB/Parser/vb.atg index fbaf98990..f6787ab95 100644 --- a/ICSharpCode.NRefactory.VB/Parser/vb.atg +++ b/ICSharpCode.NRefactory.VB/Parser/vb.atg @@ -7,10 +7,11 @@ using System.Text; using ICSharpCode.NRefactory.VB.Ast; using ICSharpCode.NRefactory.VB.Parser; using ASTAttribute = ICSharpCode.NRefactory.VB.Ast.Attribute; +using Roles = ICSharpCode.NRefactory.VB.AstNode.Roles; COMPILER VB -/* START AUTOGENERATED TOKENS SECTION */ +#region AUTOGENERATED TOKENS SECTION TOKENS /* ----- terminal classes ----- */ /* EOF is 0 */ @@ -23,16 +24,16 @@ TOKENS LiteralSingle LiteralDecimal LiteralDate - XmlOpenTag - XmlCloseTag - XmlStartInlineVB - XmlEndInlineVB - XmlCloseTagEmptyElement - XmlOpenEndTag - XmlContent - XmlComment - XmlCData - XmlProcessingInstruction + XmlOpenTag // < + XmlCloseTag // > + XmlStartInlineVB // <%= + XmlEndInlineVB // %> + XmlCloseTagEmptyElement // /> + XmlOpenEndTag // + XmlCData // + XmlProcessingInstruction /* ----- special character ----- */ "=" @@ -255,3453 +256,35 @@ TOKENS "WriteOnly" "Xor" "GetXmlNamespace" -/* END AUTOGENERATED TOKENS SECTION */ +#endregion PRODUCTIONS -VB - (. - lexer.NextToken(); // get the first token - compilationUnit = new CompilationUnit(); - BlockStart(compilationUnit); - .) -= - { EndOfStmt } - { OptionStmt { EndOfStmt } } - { ImportsStmt { EndOfStmt } } - { IF (IsGlobalAttrTarget()) GlobalAttributeSection { EndOfStmt } } - { NamespaceMemberDecl { EndOfStmt } } -. - -OptionStmt (. INode node = null; bool val = true; .) = - "Option" (. Location startPos = t.Location; .) - ( - "Explicit" [ OptionValue ] - (. node = new OptionDeclaration(OptionType.Explicit, val); .) - | - "Strict" [ OptionValue ] - (. node = new OptionDeclaration(OptionType.Strict, val); .) - | - "Compare" ( "Binary" (. node = new OptionDeclaration(OptionType.CompareBinary, val); .) - | "Text" (. node = new OptionDeclaration(OptionType.CompareText, val); .) - ) - | - "Infer" [ OptionValue ] - (. node = new OptionDeclaration(OptionType.Infer, val); .) - ) - EndOfStmt - (. - if (node != null) { - node.StartLocation = startPos; - node.EndLocation = t.Location; - AddChild(node); - } - .) -. - -OptionValue = - ( - "On" (. val = true; .) - | - "Off" (. val = false; .) - ) - . - -EndOfStmt = - SYNC ( EOL | ":" ) -. - -ImportsStmt - (.List usings = new List(); - .) = - "Imports" - (. - Location startPos = t.Location; - Using u; - .) - ImportClause (. if (u != null) { usings.Add(u); } .) - { - "," ImportClause (. if (u != null) { usings.Add(u); } .) - } - EndOfStmt - (. - UsingDeclaration usingDeclaration = new UsingDeclaration(usings); - usingDeclaration.StartLocation = startPos; - usingDeclaration.EndLocation = t.Location; - AddChild(usingDeclaration); - .) - . - -ImportClause - (. - string qualident = null; - TypeReference aliasedType = null; - u = null; - .) = - ( - Qualident - [ "=" TypeName ] - (. - if (qualident != null && qualident.Length > 0) { - if (aliasedType != null) { - u = new Using(qualident, aliasedType); - } else { - u = new Using(qualident); - } - } - .) - ) | ( (. string prefix = null; .) - XmlOpenTag Identifier (. prefix = t.val; .) "=" LiteralString (. u = new Using(t.literalValue as string, prefix); .) XmlCloseTag - ) - . - -/* 6.4.2 */ -NamespaceMemberDecl - (. - ModifierList m = new ModifierList(); - AttributeSection section; - List attributes = new List(); - string qualident; - .) = - ("Namespace" - (. - Location startPos = t.Location; - .) - Qualident - (. - INode node = new NamespaceDeclaration(qualident); - node.StartLocation = startPos; - AddChild(node); - BlockStart(node); - .) - EndOfStmt - NamespaceBody - (. - node.EndLocation = t.Location; - BlockEnd(); - .) - ) | ( - { AttributeSection (. attributes.Add(section); .) } - { TypeModifier } NonModuleDeclaration ) - . - -/* 4.9.1 */ -TypeParameterList<.List templates.> -(. - TemplateDefinition template; -.) -= - [ - IF (la.kind == Tokens.OpenParenthesis && Peek(1).kind == Tokens.Of) - "(" "Of" TypeParameter - (. - if (template != null) templates.Add(template); - .) - { - "," TypeParameter - (. - if (template != null) templates.Add(template); - .) - } - ")" - ] -. - -/* 4.9.1 */ -TypeParameter - (. VarianceModifier modifier = VarianceModifier.Invariant; Location startLocation = la.Location; .) -= - ( - [ "In" (. modifier = VarianceModifier.Contravariant; .) - | IF (la.kind == Tokens.Out && IsIdentifierToken(Peek(1))) "Out" (. modifier = VarianceModifier.Covariant; .) - ] - Identifier (. template = new TemplateDefinition(t.val, null) { VarianceModifier = modifier }; .) - [TypeParameterConstraints