public bool canGenerate(CFile file)
        {
            if (file.Attributes.contains("ExecuteAtCompiler") || file.IncludedByExecuteAtCompilerFile)
                return false;

            return internalCanGenerate(file);
        }
 public CLambdaFunction(CToken token, CFunction containingFunction, CFile containingFile, String name, CTypeRef tref,
                        CArgumentList args)
     : base(token, name, name, TokenTypes.visInternal, FunctionType.Function, args, tref)
 {
     this.containingFunction = containingFunction;
     this.containingFile = containingFile;
     if (this.containingFunction != null)
         this.containingFunction.Lambdas.Add(this);
     else
         this.containingFile.Lambdas.Add(this);
     CallCount++;
     Attributes.Add(CToken.Identifer(null, "ExecuteAnywhere"), new CTypeRef(null, CToken.Identifer(null, "ExecuteAnywhereAttribute")));
 }
 public CLambdaFunction(CToken token, CFunction containingFunction, CFile containingFile, String name, CTypeRef tref,
                        CArgumentList args)
     : base(token, name, name, TokenTypes.visInternal, FunctionType.Function, args, tref)
 {
     this.containingFunction = containingFunction;
     this.containingFile     = containingFile;
     if (this.containingFunction != null)
     {
         this.containingFunction.Lambdas.Add(this);
     }
     else
     {
         this.containingFile.Lambdas.Add(this);
     }
     CallCount++;
     Attributes.Add(CToken.Identifer(null, "ExecuteAnywhere"), new CTypeRef(null, CToken.Identifer(null, "ExecuteAnywhereAttribute")));
 }
Esempio n. 4
0
        public CClass FindClass(CToken name, bool searchImports)
        {
            CClass result = null;

            CFile file = null;

            if (name.Filename != null)
            {
                fileMap.TryGetValue(name.Filename, out file);
            }

            // first look to see if the type has been renamed
            CToken newName;

            if (file != null && file.ClassNameAliases.TryGetValue(name.RawValue, out newName))
            {
                name = newName;
            }

            // Try to find the class the normal way
            if (result == null)
            {
                result = InternalFindClass(name.RawValue, name.Value, searchImports);
            }

            // Look in the namespace mapping
            if (result == null && file != null)
            {
                foreach (var prefix in file.NameSpaceResolutionPrefixes)
                {
                    result = InternalFindClass(
                        prefix.RawValue + "." + name.RawValue,
                        prefix.Value + "." + name.Value,
                        searchImports);
                    if (result != null)
                    {
                        break;
                    }
                }
            }

            return(result);
        }
        internal CStatementBlock StartInitialize(CFunction containingFunction, CFile containingFile, CTypeRef tref, CArgumentList args)
        {
            if (lambdaFunction != null)
                throw new InvalidOperationException("Lambdas can only be initalized once");

            CClass @class = null;
            string extra = "";
            if (containingFunction != null)
            {
                @class = containingFunction.Class;
                extra += containingFunction.RawName;
            }

            lambdaFunction =
                new CLambdaFunction(Token, containingFunction, containingFile, "Lambda_" + extra + "_" + lambdaId, tref, args);
            base.LoadType(lambdaType = new CFunctionType(Token, lambdaFunction, false));

            lambdaFunction.Class = @class;

            return lambdaFunction.Statements;
        }
        internal CStatementBlock StartInitialize(CFunction containingFunction, CFile containingFile, CTypeRef tref, CArgumentList args)
        {
            if (lambdaFunction != null)
            {
                throw new InvalidOperationException("Lambdas can only be initalized once");
            }

            CClass @class = null;
            string extra  = "";

            if (containingFunction != null)
            {
                @class = containingFunction.Class;
                extra += containingFunction.RawName;
            }

            lambdaFunction =
                new CLambdaFunction(Token, containingFunction, containingFile, "Lambda_" + extra + "_" + lambdaId, tref, args);
            base.LoadType(lambdaType = new CFunctionType(Token, lambdaFunction, false));

            lambdaFunction.Class = @class;

            return(lambdaFunction.Statements);
        }
 protected internal virtual bool internalCanGenerate(CFile file)
 {
     return true;
 }
        public void VisitFile(CFile file)
        {
            if (!canGenerate(file))
                return;

            visitor.PreVisitFile(file);

            filenamesrc = file.Token;

            new CNewline(null).Accept(visitor);

            if (instrument)
            {
                COption cCodeCoverage =
                    new COption(new CToken(file.Filename, TokenTypes.keyword, "option"),
                                new CToken(file.Filename, TokenTypes.keyword, "include"),
                                new CToken(file.Filename, TokenTypes.str, "cCodeCoverage.asp"));
                cCodeCoverage.Accept(this);
            }

            visitor.VisitFile(file);

            if (file.Attributes.contains("GenerateProcessAjaxFunction"))
            {
                CFunction unicoderequest = CProgram.Global.FindFunction("unicoderequest");
                CFunction intrequest = CProgram.Global.FindFunction("intrequest");
                CFunction boolrequest = CProgram.Global.FindFunction("boolrequest");

                CToken tok = CreateTokenWithAdditionalInfo("ProcessAjax", "processajax", TokenTypes.identifier);
                CFunction processAjax =
                    new CFunction(tok, tok.RawValue, tok.Value, TokenTypes.visPublic, CFunction.vbSub, null,
                                  new CTypeRef(null, BuiltIns.Void));

                CAccess pivotitem = new CAccess(unicoderequest.Token, unicoderequest.Token);
                pivotitem.ReferenceTarget = unicoderequest;
                CParameters pivotparams = new CParameters();
                pivotparams.Unnamed.Add(
                    new CConstantExpression(CreateTokenWithAdditionalInfo("sFunction", TokenTypes.str)));
                CSelect select =
                    new CSelect(CreateTokenWithAdditionalInfo("select", TokenTypes.controlFlow),
                                new CDefaultAccess(pivotitem.Token, pivotitem, pivotparams));

                IEnumerator it = CProgram.Global.Functions.GetEnumerator();
                List<CVariable> vars = new List<CVariable>();
                while (it.MoveNext())
                {
                    CFunction func = (CFunction)it.Current;
                    if (!func.Attributes.contains("ExecuteOnServer"))
                        continue;

                    CStatementBlock block = new CStatementBlock();
                    CParameters funcParams = new CParameters();
                    for (int ixArg = 0; ixArg < func.Arguments.Count - 3; ixArg++)
                    {
                        CArgument arg = func.Arguments[ixArg];

                        tok =
                            CreateTokenWithAdditionalInfo("vParam" + (ixArg + 1), "vparam" + (ixArg + 1),
                                                          TokenTypes.identifier);
                        if (ixArg >= vars.Count)
                            vars.Add(new CVariable(tok, false, new CTypeRef(null, BuiltIns.Variant), null, null, null));

                        CAssignment assign = new CAssignment(tok);

                        CAccess left = new CAccess(tok, tok);
                        left.ReferenceTarget = vars[ixArg];
                        assign.Target = left;
                        funcParams.Unnamed.Add(left);

                        CFunction rightfunc = intrequest;
                        if (arg.Type.RawName == "Boolean")
                            rightfunc = boolrequest;
                        else if (arg.Type.RawName == "String")
                            rightfunc = unicoderequest;

                        CParameters parameters = new CParameters();
                        parameters.Unnamed.Add(
                            new CConstantExpression(CreateTokenWithAdditionalInfo(tok.RawValue, TokenTypes.str)));

                        CAccess rightitem = new CAccess(rightfunc.Token, rightfunc.Token);
                        rightitem.ReferenceTarget = rightfunc;

                        assign.Source = new CDefaultAccess(rightfunc.Token, rightitem, parameters);
                        assign.Source.RhsAssignmentSource = true;

                        block.Add(assign);
                    }

                    CAccess calledItem = new CAccess(func.Token, func.Token);
                    CDefaultAccess called = new CDefaultAccess(func.Token, calledItem, funcParams);
                    calledItem.ReferenceTarget = calledItem.ReferenceTarget = func;

                    if (func.Attributes.contains("picture") || func.FunctionType == CFunction.vbFunction)
                    {
                        CAccess returnItem = new CAccess(processAjax.Token, processAjax.Token);
                        returnItem.ReferenceTarget = processAjax;

                        CAssignment assign = new CAssignment(processAjax.Token);
                        assign.Target = returnItem;

                        if (func.FunctionType == CFunction.vbFunction)
                            assign.Source = called;
                        else
                            assign.Source = new CPictureOfExpression(tok, called);

                        block.Add(assign);
                    }
                    else
                        block.Add(new CExpressionStatement(called));

                    tok = CreateTokenWithAdditionalInfo("case", TokenTypes.controlFlow);
                    CExpression exp =
                        new CConstantExpression(CreateTokenWithAdditionalInfo(func.RawName, TokenTypes.str));
                    select.Cases.Add(new CCase(tok, exp, block));
                }

                CDim dim = new CDim(CreateTokenWithAdditionalInfo("Dim", TokenTypes.declaration));
                dim.Variables.AddRange(vars);
                processAjax.Statements.Add(dim);
                processAjax.Statements.Add(select);

                CNewline nl = new CNewline(CreateTokenWithAdditionalInfo("\n", TokenTypes.newline));
                nl.Accept(this);
                processAjax.Accept(this);
                nl.Accept(this);
            }
        }