示例#1
0
        public override AstNode Visit(TypedefDefinition node)
        {
            // Prevent redefinition.
            ScopeMember old = currentContainer.FindMember(node.GetName());

            if (old != null)
            {
                Error(node, "trying to redefine a typedef.");
            }

            // Create the type name.
            TypeNameMember typeName = new TypeNameMember(node.GetFlags(), node.GetName(), currentContainer);

            typeName.SetTypedefNode(node);
            node.SetTypeName(typeName);

            // Register the type name.
            if (currentContainer.IsNamespace())
            {
                Namespace space = (Namespace)currentContainer;
                space.AddMember(typeName);
            }
            else if (currentContainer.IsStructure() || currentContainer.IsClass())
            {
                Structure parent = (Structure)currentContainer;
                parent.AddTypeName(typeName);
            }
            else
            {
                Error(node, "unexpected place for a typedef.");
            }

            return(node);
        }
示例#2
0
 public TypeNameMember(ChelaModule module)
     : base(module)
 {
     this.name        = string.Empty;
     this.parentScope = null;
     this.typedefNode = null;
     this.actualType  = null;
     this.isExpanding = false;
     this.flags       = MemberFlags.Default;
 }
示例#3
0
 public override AstNode Visit(TypedefDefinition node)
 {
     ExpandTypeNode(node, false);
     return(node);
 }
示例#4
0
        private void ExpandTypeNode(TypedefDefinition node, bool sorted)
        {
            // Use the scope in the same place as the definition.
            Scope[] expansionScope = null;
            if (sorted)
            {
                expansionScope = node.GetExpansionScope();
                foreach (Scope scope in expansionScope)
                {
                    PushScope(scope);
                }
            }

            // Allow unsafe typedefs.
            PushUnsafe();

            // Get the type name member.
            TypeNameMember typeName = node.GetTypeName();

            // Parse the type expression.
            Expression typeExpr = node.GetTypeExpression();

            typeExpr.Accept(this);

            // Make sure the type expression is a type.
            IChelaType actualType = typeExpr.GetNodeType();

            actualType = ExtractActualType(typeExpr, actualType);

            // Store the type.
            typeName.SetActualType(actualType);

            // Store the incomplete typename.
            if (actualType.IsIncompleteType())
            {
                // Don't allow cyclic expansion.
                if (sorted)
                {
                    Error(node, "typedef cannot be expanded.");
                }

                // Store the incomplete type name.
                incompletes.Add(typeName);

                // Store the typedef scope stack.
                int     numscopes = scopeStack.Count + 1;
                Scope[] scopeData = new Scope[numscopes];
                int     i         = numscopes - 1;
                scopeData[i--] = currentScope;
                foreach (Scope scope in scopeStack)
                {
                    scopeData[i--] = scope;
                }
                node.SetExpansionScope(scopeData);
            }

            // Restore the safe context.
            PopUnsafe();

            // Restore the scope.
            if (sorted)
            {
                for (int i = 0; i < expansionScope.Length; ++i)
                {
                    PopScope();
                }
                node.SetExpansionScope(null);
            }
        }
示例#5
0
 public void SetTypedefNode(TypedefDefinition typedefNode)
 {
     this.typedefNode = typedefNode;
 }