Пример #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
        private void RegisterAnonTypeLeaf(IChelaType type, bool registered)
        {
            // Make sure lower types are registered.
            if(!registered)
                RegisterType(type);

            if(type.IsReference())
            {
                ReferenceType refType = (ReferenceType)type;
                RegisterAnonTypeLeaf(refType.GetReferencedType());
            }
            else if(type.IsPointer())
            {
                PointerType pointerType = (PointerType)type;
                RegisterAnonTypeLeaf(pointerType.GetPointedType());
            }
            else if(type.IsConstant())
            {
                ConstantType constType = (ConstantType)type;
                RegisterAnonTypeLeaf(constType.GetValueType());
            }
            else if(type.IsArray())
            {
                ArrayType arrayType = (ArrayType)type;
                RegisterAnonTypeLeaf(arrayType.GetValueType());
            }
            else if(type.IsVector())
            {
                VectorType vectorType = (VectorType)type;
                RegisterAnonTypeLeaf(vectorType.GetPrimitiveType());
            }
            else if(type.IsMatrix())
            {
                MatrixType matrixType = (MatrixType)type;
                RegisterAnonTypeLeaf(matrixType.GetPrimitiveType());
            }
            else if(type.IsFunction())
            {
                FunctionType functionType = (FunctionType)type;

                // Register the return type.
                RegisterAnonTypeLeaf(functionType.GetReturnType());

                // Register the function arguments.
                for(int i = 0; i < functionType.GetArgumentCount(); ++i)
                    RegisterAnonTypeLeaf(functionType.GetArgument(i));
            }
            else if(type.IsPlaceHolderType())
            {
                // Register the base types.
                PlaceHolderType placeholder = (PlaceHolderType)type;
                for(int i = 0; i < placeholder.GetBaseCount(); ++i)
                    RegisterMember(placeholder.GetBase(i));
            }
            else if(type.IsPrimitive())
            {
                // Do nothing.
            }
            else if(type.IsTypeInstance())
            {
                StructureInstance instance = (StructureInstance)type;
                instance.PrepareSerialization();
                RegisterMember(instance);
            }
            else
            {
                // Found a leaf.
                ScopeMember member = (ScopeMember)type;
                RegisterMember(member);
            }
        }