コード例 #1
0
ファイル: TypeDeclarations.cs プロジェクト: Suchiman/vcc
        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);
        }
コード例 #2
0
ファイル: TypeDeclarations.cs プロジェクト: Suchiman/vcc
 protected override bool CheckForErrorsAndReturnTrueIfAnyAreFound()
 {
     return(base.CheckForErrorsAndReturnTrueIfAnyAreFound() ||
            VccStructuredTypeDeclaration.HasTypeCycle(this.TypeDefinition, this.Helper) ||
            VccStructuredTypeDeclaration.HasFieldOfUnspecifiedType(this.TypeDefinition, this.TypeDefinition.Members, this.Helper));
 }
コード例 #3
0
ファイル: TypeDeclarations.cs プロジェクト: Suchiman/vcc
 protected VccStructuredTypeDeclaration(NamespaceDeclaration containingNamespaceDeclaration, VccStructuredTypeDeclaration template)
     : base(containingNamespaceDeclaration, template)
 {
     this.extendedAttributes = new List <Specifier>(template.extendedAttributes);
 }
コード例 #4
0
ファイル: TypeDeclarations.cs プロジェクト: Suchiman/vcc
 internal static bool HasTypeCycle(ITypeReference type, LanguageSpecificCompilationHelper helper)
 {
     return(VccStructuredTypeDeclaration.HasTypeCycle(type, null, new Stack <ITypeReference>(), helper));
 }
コード例 #5
0
ファイル: Expressions.cs プロジェクト: edgar-pek/VCDryad
        internal override void AddInitializingFieldAssignmentsTo(ICollection<Statement> statements, Expression target, VccStructuredTypeDeclaration typeDecl)
        {
            foreach (var pair in this.designatorsWithExpressions) {
            var targetDotField = target;
            foreach (var desig in pair.Designators)
              targetDotField = new VccQualifiedName(targetDotField, desig, desig.SourceLocation);

            targetDotField.SetContainingExpression(this);
            AddInitializationTo(statements, pair.Expression, targetDotField, TypeExpression.For(targetDotField.Type.ResolvedType), this.ContainingBlock);
              }
        }
コード例 #6
0
ファイル: Expressions.cs プロジェクト: edgar-pek/VCDryad
 internal override void PropagateStructuredTypeToSubExpressions(VccStructuredTypeDeclaration typeDecl)
 {
     // read field->type map into a dictionary so that we do not run into quadratic behaviour
       // (even though the number of fields should likely be small)
       Dictionary<IName, TypeExpression> fieldToTypeMap = new Dictionary<IName, TypeExpression>();
       foreach (var field in IteratorHelper.GetFilterEnumerable<ITypeDeclarationMember, FieldDefinition>(typeDecl.TypeDeclarationMembers))
     fieldToTypeMap[field.Name.Name] = field.Type;
       foreach (var init in this.DesignatorsWithExpressions) {
     TypeExpression fieldType;
     if (fieldToTypeMap.TryGetValue(init.Designators[0].Name, out fieldType))
       VccInitializerBase.PropagateTypeToExpressionIfAppropriate(init.Expression, fieldType);
       }
 }
コード例 #7
0
ファイル: Expressions.cs プロジェクト: edgar-pek/VCDryad
 /// <summary>
 /// To be called when this object has been determined to be of structured type and the appropriate type information should be
 /// propagated to field initializers
 /// </summary>
 internal abstract void PropagateStructuredTypeToSubExpressions(VccStructuredTypeDeclaration typeDecl);
コード例 #8
0
ファイル: Expressions.cs プロジェクト: edgar-pek/VCDryad
 internal abstract void AddInitializingFieldAssignmentsTo(ICollection<Statement> statements, Expression target, VccStructuredTypeDeclaration typeDecl);
コード例 #9
0
ファイル: Expressions.cs プロジェクト: edgar-pek/VCDryad
 internal override void PropagateStructuredTypeToSubExpressions(VccStructuredTypeDeclaration typeDecl)
 {
     using (IEnumerator<FieldDefinition> fieldEnum = IteratorHelper.GetFilterEnumerable<ITypeDeclarationMember, FieldDefinition>(typeDecl.TypeDeclarationMembers).GetEnumerator())
       using (IEnumerator<Expression> exprEnum = this.Expressions.GetEnumerator())
       while (fieldEnum.MoveNext() && exprEnum.MoveNext())
     VccInitializerBase.PropagateTypeToExpressionIfAppropriate(exprEnum.Current, fieldEnum.Current.Type);
 }
コード例 #10
0
ファイル: Expressions.cs プロジェクト: edgar-pek/VCDryad
 /// <summary>
 /// Supply initialization code for a structured variable in the static initializer.
 /// </summary>
 /// <param name="statements">statements collection into which new statements are added</param>
 /// <param name="target">the name of the struct variable</param>
 /// <param name="typeDecl">the structured type's declaration</param>
 internal override void AddInitializingFieldAssignmentsTo(ICollection<Statement> statements, Expression target, VccStructuredTypeDeclaration typeDecl)
 {
     bool isUnion = typeDecl is VccUnionDeclaration;
       IEnumerator<Expression> exprEnumerator= this.expressions.GetEnumerator();
       foreach (FieldDefinition fd in IteratorHelper.GetFilterEnumerable<ITypeDeclarationMember, FieldDefinition>(typeDecl.TypeDeclarationMembers)) {
     SimpleName fieldName = new SimpleName(fd.Name, target.SourceLocation, false);
     var varDotField = new VccQualifiedName(target, fieldName, target.SourceLocation);
     if (exprEnumerator.MoveNext())
       AddInitializationTo(statements, exprEnumerator.Current, varDotField, fd.Type, this.ContainingBlock);
     if (isUnion) return;
       }
 }
コード例 #11
0
ファイル: TypeDeclarations.cs プロジェクト: edgar-pek/VCDryad
 protected VccStructuredTypeDeclaration(NamespaceDeclaration containingNamespaceDeclaration, VccStructuredTypeDeclaration template)
     : base(containingNamespaceDeclaration, template)
 {
     this.extendedAttributes = new List<Specifier>(template.extendedAttributes);
 }