Example #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);
        }
Example #2
0
        private void ExpandType(TypeNameMember typeName)
        {
            // Circular references are wrong.
            AstNode typedefNode = typeName.GetTypedefNode();

            if (typeName.IsExpanding)
            {
                Error(typedefNode, "typedef with circular reference.");
            }

            // Ignore expanded types.
            IChelaType type = typeName.GetActualType();

            if (!type.IsIncompleteType())
            {
                return;
            }

            // Set the expanding flag.
            typeName.IsExpanding = true;

            // Expand the dependencies first.
            IncompleteType incomplete = (IncompleteType)type;

            foreach (TypeNameMember dep in incomplete.Dependencies)
            {
                ExpandType(dep);
            }

            // Expand the type name itself.
            ExpandTypeNode((TypedefDefinition)typedefNode, true);

            // Unset the expanding flag.
            typeName.IsExpanding = false;
        }
Example #3
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);
            }
        }
Example #4
0
 public void SetTypeName(TypeNameMember typeName)
 {
     this.typeName = typeName;
 }