示例#1
0
        public override AstNode Visit(MemberAccess node)
        {
            // This is the same as VariableReference implementation.
            // Get the node type.
            IChelaType variableType = node.GetNodeType();

            // Ignore type references, namespaces and functions.
            if (variableType.IsMetaType() || variableType.IsNamespace() ||
                variableType.IsFunctionGroup() || variableType.IsFunction())
            {
                return(node);
            }

            // The type must be a reference.
            variableType = DeReferenceType(variableType);

            // Now, it must be a constant.
            if (!variableType.IsConstant())
            {
                Error(node, "constant initialization can't reference no constant variables.");
            }

            // The node value, must be the constant variable.
            FieldVariable constantVar = (FieldVariable)node.GetNodeValue();

            // Find the corresponding constant data.
            ConstantData depData;

            if (constants.TryGetValue(constantVar, out depData))
            {
                currentConstant.AddDependency(depData);
            }

            return(node);
        }
示例#2
0
        public override AstNode Visit(UsingStatement node)
        {
            // Visit the using member.
            Expression member = node.GetMember();

            member.Accept(this);

            // Cast the pseudo-scope.
            PseudoScope scope = (PseudoScope)node.GetScope();

            // Get the member type.
            IChelaType memberType = member.GetNodeType();

            if (memberType.IsMetaType())
            {
                // Get the actual type.
                MetaType meta = (MetaType)memberType;
                memberType = meta.GetActualType();

                // Only structure relatives.
                if (memberType.IsStructure() || memberType.IsClass() || memberType.IsInterface())
                {
                    scope.AddAlias(memberType.GetName(), (ScopeMember)memberType);
                }
                else
                {
                    Error(node, "unexpected type.");
                }
            }
            else if (memberType.IsReference())
            {
                // Only static members supported.
                ScopeMember theMember     = (ScopeMember)member.GetNodeValue();
                MemberFlags instanceFlags = MemberFlags.InstanceMask & theMember.GetFlags();
                if (instanceFlags != MemberFlags.Static)
                {
                    Error(node, "unexpected member type.");
                }

                // Store the member.
                scope.AddAlias(theMember.GetName(), theMember);
            }
            else if (memberType.IsNamespace())
            {
                // Set the namespace chain.
                Namespace space = (Namespace)member.GetNodeValue();
                scope.SetChainNamespace(space);
            }
            else
            {
                Error(node, "unsupported object to use.");
            }

            base.Visit(node);

            return(node);
        }
示例#3
0
        public IChelaType ExtractActualType(AstNode where, IChelaType type)
        {
            // Extract from the meta type.
            if(!type.IsMetaType())
                Error(where, "expected a type.");
            type = ExtractMetaType(type);

            // Use the default element from the type group.
            if(type.IsTypeGroup())
            {
                TypeGroup group = (TypeGroup)type;
                Structure building = group.GetDefaultType();
                type = building;
                if(building == null)
                    Error(where, "unexpected type group {0}", @group.GetDisplayName());

                // Prevent ambiguity of merged type group.
                building.CheckAmbiguity(where.GetPosition());
            }
            return type;
        }