コード例 #1
0
ファイル: CCase.cs プロジェクト: nagyistoce/RoslynGenerator
        private CStatementBlock statements; // the statements to be executed in this case of the switch

        #endregion Fields

        #region Constructors

        // if statements is null, that means there are no statements.  meaning this case uses the statements
        // of the case below it.  so dont put a break point.  eg:
        //  switch (color) {
        //      case (red):
        //      case (blue):
        //          print("its red or blue);
        //          break;
        //
        public CCase(CToken token, CExpression val)
            : base(token)
        {
            m_value = val;
            m_value.Parent = this;
            statements = null;
        }
コード例 #2
0
ファイル: CSelect.cs プロジェクト: FogCreek/RoslynGenerator
        private CStatementBlock cases; // this will be a vector of case objects

        public CSelect(CToken token, CExpression pivot)
            : base(token)
        {
            cases = new CStatementBlock();
            this.pivot = pivot;
            pivot.Parent = this;
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: testpulse/RoslynGenerator
        public static void AddBody(CStatementBlock block)
        {
            block.Add(new CComment(new CToken(FILE, TokenTypes.comment, "' This is an example"), " This is an example"));

            block.Add(new CReturn(new CToken(FILE, TokenTypes.keyword, "Return"))
            {
                Expression = new CConstantExpression(new CToken(FILE, TokenTypes.number, "5"))
            });
        }
コード例 #4
0
ファイル: CCase.cs プロジェクト: nagyistoce/RoslynGenerator
 // this is the constructor when you actually need to parse all the statements of a case
 // until you hit the next case
 public CCase(CToken token, CExpression val, CStatementBlock block)
     : base(token)
 {
     m_value = val;
     elseCaseFlag = val == null;
     if (!elseCaseFlag)
         m_value.Parent = this;
     statements = block;
 }
コード例 #5
0
ファイル: Program.cs プロジェクト: nagyistoce/RoslynGenerator
        public static void AddBody(CStatementBlock block)
        {
            block.Add(new CComment(new CToken(FILE, TokenTypes.comment, "' This is an example"), " This is an example"));

            block.Add(new CReturn(new CToken(FILE, TokenTypes.keyword, "Return"))
            {
                Expression = new CConstantExpression(new CToken(FILE, TokenTypes.number, "5"))
            });
        }
コード例 #6
0
        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);
            }
        }
コード例 #7
0
 public void VisitBlock(CStatementBlock statements)
 {
     visitor.VisitBlock(statements);
 }
コード例 #8
0
        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);
            }
        }
コード例 #9
0
 public void VisitBlock(CStatementBlock statements)
 {
     visitor.VisitBlock(statements);
 }