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

            Variable varRoot = this.Root as Variable;

            if (varRoot != null)
            {
                string rootName = varRoot.Name;
                if (rootName == "Core")
                {
                    NativeFunction nativeFunction = this.GetNativeCoreFunction(this.FieldName.Value);
                    switch (nativeFunction)
                    {
                    case NativeFunction.FLOAT_BUFFER_16:
                    case NativeFunction.INT_BUFFER_16:
                    case NativeFunction.STRING_BUFFER_16:
                        return(new NativeFunctionInvocation(this.FirstToken, nativeFunction, new Expression[0]));

                    default:
                        return(new NativeFunctionReference(this.FirstToken, nativeFunction));
                    }
                }
                EnumDefinition enumDef = compiler.GetEnumDefinition(rootName);
                if (enumDef != null)
                {
                    InlineConstant enumValue = enumDef.GetValue(this.FieldName);
                    return(enumValue.CloneWithNewToken(this.FirstToken));
                }
            }
            else if (this.Root is EnumReference)
            {
                EnumDefinition enumDef   = ((EnumReference)this.Root).EnumDef;
                InlineConstant enumValue = enumDef.GetValue(this.FieldName);
                return(enumValue);
            }

            return(this);
        }
예제 #2
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);
        }