/// <summary> /// The root node and global context for a compilation. Every node in the AST has a path back to this node. /// Compilation nodes and all of their descendants are immutable once initialized. Initialization happens in two phases. /// Calling this constructor is phase one. Setting the parent node is phase two (and is delayed in order to allow for bottom up AST construction). /// A compilation does not have a second phase initialization method since it has no parent. /// </summary> /// <param name="hostEnvironment">An object that represents the application that hosts the compilation and that provides things such as a shared name table.</param> /// <param name="result">A "unit of compilation" that holds the result of this compilation. Once the Compilation has been constructed, result can be navigated causing /// on demand compilation to occur.</param> /// <param name="sources">A singleton collection whose member is a dummy source document.</param> internal HelloCompilation(ISourceEditHost hostEnvironment, Unit result, IEnumerable <HelloSourceDocument> sources) : base(hostEnvironment, result, new FrameworkOptions()) { var helper = new LanguageSpecificCompilationHelper(this, "hello"); this.partList = new List <CompilationPart>(); foreach (var source in sources) { //The source document is a dummy, but the compilation part is not. It proffers a valid AST via its RootNamespace property. //These nodes of this AST uses the dummy source location as the value of their SourceLocation properties. this.partList.Add(new HelloCompilationPart(helper, source.SourceLocation)); } }
internal static bool CheckAndReturnTrueIfFound(Expression expression, LanguageSpecificCompilationHelper helper) { ErrorForOutParameterReporter er = new ErrorForOutParameterReporter(helper, expression); expression.Dispatch(er); return er.OutParameterFound; }
private ErrorForOutParameterReporter(LanguageSpecificCompilationHelper helper, ISourceItem defaultSourceItemForErrorReporting) { this.helper = helper; this.defaultSourceItemForErrorReporting = defaultSourceItemForErrorReporting; }
private static bool HasTypeCycle(ITypeReference type, IFieldDefinition /*?*/ offendingField, Stack <ITypeReference> seenTypes, LanguageSpecificCompilationHelper helper) { if (type.TypeCode != PrimitiveTypeCode.NotPrimitive || !type.ResolvedType.IsStruct) { return(false); } lock (GlobalLock.LockingObject) { if (typesWithKnownLoops.ContainsKey(type)) { return(true); } } if (seenTypes.Contains(type)) { lock (GlobalLock.LockingObject) { if (!typesWithKnownLoops.ContainsKey(type)) { typesWithKnownLoops.Add(type, true); var location = IteratorHelper.First(helper.Compilation.SourceLocationProvider.GetPrimarySourceLocationsFor(type.Locations)); helper.ReportError( new VccErrorMessage(location, Error.ValueTypeLayoutCycle, offendingField.Name.Value, helper.GetTypeName(type.ResolvedType))); } } return(true); } seenTypes.Push(type); bool hasCycle = false; foreach (var field in IteratorHelper.GetFilterEnumerable <ITypeDefinitionMember, IFieldDefinition>(type.ResolvedType.Members)) { if (!field.IsStatic) { hasCycle |= VccStructuredTypeDeclaration.HasTypeCycle(field.Type, field, seenTypes, helper); } } seenTypes.Pop(); return(hasCycle); }
internal static bool HasTypeCycle(ITypeReference type, LanguageSpecificCompilationHelper helper) { return(VccStructuredTypeDeclaration.HasTypeCycle(type, null, new Stack <ITypeReference>(), helper)); }
internal static bool HasFieldOfUnspecifiedType(ITypeReference type, IEnumerable <ITypeDefinitionMember> members, LanguageSpecificCompilationHelper helper) { bool errorFound = false; foreach (var member in members) { var field = member as IFieldDefinition; if (field != null && field.Type == helper.Compilation.PlatformType.SystemVoid.ResolvedType) { var fieldDecl = ((Cci.Ast.FieldDefinition)field).Declaration as FieldDefinition; var location = IteratorHelper.First(helper.Compilation.SourceLocationProvider.GetPrimarySourceLocationsFor(type.Locations)); helper.ReportError( new VccErrorMessage(location, Error.IllegalUseOfUndefinedType, field.Name.Value, fieldDecl != null ? fieldDecl.Type.SourceLocation.Source : helper.GetTypeName(field.Type.ResolvedType))); errorFound = true; } } return(errorFound); }
private static bool HasTypeCycle(ITypeReference type, IFieldDefinition/*?*/ offendingField, Stack<ITypeReference> seenTypes, LanguageSpecificCompilationHelper helper) { if (type.TypeCode != PrimitiveTypeCode.NotPrimitive || !type.ResolvedType.IsStruct) return false; lock (GlobalLock.LockingObject) { if (typesWithKnownLoops.ContainsKey(type)) return true; } if (seenTypes.Contains(type)) { lock (GlobalLock.LockingObject) { if (!typesWithKnownLoops.ContainsKey(type)) { typesWithKnownLoops.Add(type, true); var location = IteratorHelper.First(helper.Compilation.SourceLocationProvider.GetPrimarySourceLocationsFor(type.Locations)); helper.ReportError( new VccErrorMessage(location, Error.ValueTypeLayoutCycle, offendingField.Name.Value, helper.GetTypeName(type.ResolvedType))); } } return true; } seenTypes.Push(type); bool hasCycle = false; foreach (var field in IteratorHelper.GetFilterEnumerable<ITypeDefinitionMember, IFieldDefinition>(type.ResolvedType.Members)) { if (!field.IsStatic) { hasCycle |= VccStructuredTypeDeclaration.HasTypeCycle(field.Type, field, seenTypes, helper); } } seenTypes.Pop(); return hasCycle; }
internal static bool HasTypeCycle(ITypeReference type, LanguageSpecificCompilationHelper helper) { return VccStructuredTypeDeclaration.HasTypeCycle(type, null, new Stack<ITypeReference>(), helper); }
internal static bool HasFieldOfUnspecifiedType(ITypeReference type, IEnumerable<ITypeDefinitionMember> members, LanguageSpecificCompilationHelper helper) { bool errorFound = false; foreach (var member in members) { var field = member as IFieldDefinition; if (field != null && field.Type == helper.Compilation.PlatformType.SystemVoid.ResolvedType) { var fieldDecl = ((Cci.Ast.FieldDefinition) field).Declaration as FieldDefinition; var location = IteratorHelper.First(helper.Compilation.SourceLocationProvider.GetPrimarySourceLocationsFor(type.Locations)); helper.ReportError( new VccErrorMessage(location, Error.IllegalUseOfUndefinedType, field.Name.Value, fieldDecl != null ? fieldDecl.Type.SourceLocation.Source : helper.GetTypeName(field.Type.ResolvedType))); errorFound = true; } } return errorFound; }
/// <summary> /// Initializes a part of a compilation that has been derived from a single source document. /// </summary> /// <param name="helper">An instance of a language specific class containing methods that are of general utility during semantic analysis.</param> /// <param name="sourceLocation">The source location corresponding to the newly allocated compilation part.</param> internal HelloCompilationPart(LanguageSpecificCompilationHelper helper, ISourceLocation sourceLocation) : base(helper, sourceLocation) { }