예제 #1
0
        public override Expression ResolveNamesAndCullUnusedCode(PastelCompiler compiler)
        {
            string name = this.Name;

            InlineConstant constantValue = compiler.GetConstantDefinition(name);

            if (constantValue != null)
            {
                return(constantValue.CloneWithNewToken(this.FirstToken));
            }

            if (name == "Core")
            {
                return(new CoreNamespaceReference(this.FirstToken, this.Owner));
            }

            if (name == "Extension")
            {
                return(new ExtensibleNamespaceReference(this.FirstToken, this.Owner));
            }

            FunctionDefinition functionDefinition = compiler.GetFunctionDefinition(name);

            if (functionDefinition != null)
            {
                return(new FunctionReference(this.FirstToken, functionDefinition, this.Owner));
            }

            EnumDefinition enumDefinition = compiler.GetEnumDefinition(name);

            if (enumDefinition != null)
            {
                return(new EnumReference(this.FirstToken, enumDefinition, this.Owner));
            }

            if (compiler.IncludedScopeNamespacesToIndex.ContainsKey(name))
            {
                int            index           = compiler.IncludedScopeNamespacesToIndex[name];
                PastelCompiler referencedScope = compiler.IncludedScopes[index];
                return(new DependencyNamespaceReference(this.FirstToken, referencedScope, this.Owner));
            }

            return(this);
        }
예제 #2
0
        public override Expression ResolveNamesAndCullUnusedCode(PastelCompiler compiler)
        {
            string name = this.Name;

            InlineConstant constantValue = compiler.GetConstantDefinition(name);

            if (constantValue != null)
            {
                return(constantValue.CloneWithNewToken(this.FirstToken));
            }

            FunctionDefinition functionDefinition = compiler.GetFunctionDefinitionAndMaybeQueueForResolution(name);

            if (functionDefinition != null)
            {
                return(new FunctionReference(this.FirstToken, functionDefinition));
            }

            return(this);
        }
예제 #3
0
        public override Expression ResolveNamesAndCullUnusedCode(PastelCompiler compiler)
        {
            this.Root = this.Root.ResolveNamesAndCullUnusedCode(compiler);

            if (this.Root is EnumReference)
            {
                InlineConstant enumValue = ((EnumReference)this.Root).EnumDef.GetValue(this.FieldName);
                return(enumValue.CloneWithNewToken(this.FirstToken));
            }

            if (this.Root is DependencyNamespaceReference)
            {
                PastelCompiler     dependencyScope = ((DependencyNamespaceReference)this.Root).Scope;
                string             field           = this.FieldName.Value;
                FunctionDefinition funcDef         = dependencyScope.GetFunctionDefinition(field);
                if (funcDef != null)
                {
                    return(new FunctionReference(this.FirstToken, funcDef, this.Owner));
                }

                EnumDefinition enumDef = dependencyScope.GetEnumDefinition(field);
                if (enumDef != null)
                {
                    return(new EnumReference(this.FirstToken, enumDef, this.Owner));
                }

                InlineConstant constValue = dependencyScope.GetConstantDefinition(field);
                if (constValue != null)
                {
                    return(constValue.CloneWithNewTokenAndOwner(this.FirstToken, this.Owner));
                }

                throw new ParserException(this.FieldName, "The namespace '" + ((DependencyNamespaceReference)this.Root).FirstToken.Value + "' does not have a member called '" + field + "'");
            }

            if (this.Root is CoreNamespaceReference)
            {
                CoreFunction coreFunction = this.GetCoreFunction(this.FieldName.Value);
                switch (coreFunction)
                {
                case CoreFunction.FLOAT_BUFFER_16:
                case CoreFunction.INT_BUFFER_16:
                case CoreFunction.STRING_BUFFER_16:
                    return(new CoreFunctionInvocation(this.FirstToken, coreFunction, new Expression[0], this.Owner));

                default:
                    return(new CoreFunctionReference(this.FirstToken, coreFunction, this.Owner));
                }
            }

            if (this.Root is ExtensibleNamespaceReference)
            {
                string name = this.FieldName.Value;
                return(new ExtensibleFunctionReference(this.FirstToken, name, this.Owner));
            }

            if (this.Root is EnumReference)
            {
                EnumDefinition enumDef   = ((EnumReference)this.Root).EnumDef;
                InlineConstant enumValue = enumDef.GetValue(this.FieldName);
                return(enumValue);
            }

            return(this);
        }