示例#1
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);
            }
        }