コード例 #1
0
ファイル: EchoNode.cs プロジェクト: soywiz/nphp
 public override void Generate(NodeGenerateContext Context)
 {
     Context.MethodGenerator.LoadScope();
     base.Generate(Context);
     Context.MethodGenerator.ConvTo<Php54Var>();
     Context.MethodGenerator.Call((Action<Php54Scope, Php54Var>)Php54Runtime.Echo);
 }
コード例 #2
0
ファイル: ArrayNode.cs プロジェクト: soywiz/nphp
        public override void Generate(NodeGenerateContext Context)
        {
            Context.MethodGenerator.Call((Func<Php54Var>)Php54Var.FromNewArray);
            foreach (var ParseNode in Childs)
            {
                if (ParseNode.ChildNodes[0].Term.Name == Php54Grammar.ArrayKeyValueElement.Name)
                {
                    //ParseNode.ChildNodes[0].ChildNodes[2]

                    Context.MethodGenerator.Dup();
                    (ParseNode.ChildNodes[0].ChildNodes[0].AstNode as Node).Generate(Context);
                    Context.MethodGenerator.ConvTo<Php54Var>();
                    (ParseNode.ChildNodes[0].ChildNodes[1].AstNode as Node).Generate(Context);
                    Context.MethodGenerator.ConvTo<Php54Var>();
                    Context.MethodGenerator.Call((Action<Php54Var, Php54Var>)Php54Var.Methods.AddKeyValuePair);
                    //Context.MethodGenerator.Pop();
                }
                else
                {
                    Context.MethodGenerator.Dup();
                    (ParseNode.AstNode as Node).Generate(Context);
                    Context.MethodGenerator.ConvTo<Php54Var>();
                    Context.MethodGenerator.Call((Action<Php54Var>)Php54Var.Methods.AddElement);
                    //Context.MethodGenerator.Pop();
                }
            }
            //throw(new Exception());
        }
コード例 #3
0
ファイル: TernaryOperationNode.cs プロジェクト: soywiz/nphp
        public override void Generate(NodeGenerateContext Context)
        {
            var EndLabel = Context.MethodGenerator.DefineLabel("End");
            var TrueLabel = Context.MethodGenerator.DefineLabel("True");
            var FalseLabel = Context.MethodGenerator.DefineLabel("False");
            var ConditionVar = Context.MethodGenerator.CreateLocal<Php54Var>("ConditionVar");

            // Check condition
            (ConditionParseNode.AstNode as Node).GenerateAs<bool>(Context);
            Context.MethodGenerator.BranchIfFalse(FalseLabel);

            TrueLabel.Mark();
            (TrueParseNode.AstNode as Node).GenerateAs<Php54Var>(Context);
            Context.MethodGenerator.StoreToLocal(ConditionVar);
            Context.MethodGenerator.BranchAlways(EndLabel);

            FalseLabel.Mark();
            (FalseParseNode.AstNode as Node).GenerateAs<Php54Var>(Context);
            Context.MethodGenerator.StoreToLocal(ConditionVar);
            Context.MethodGenerator.BranchAlways(EndLabel);

            EndLabel.Mark();

            Context.MethodGenerator.LoadLocal(ConditionVar);
        }
コード例 #4
0
ファイル: ForNode.cs プロジェクト: soywiz/nphp
        public override void Generate(NodeGenerateContext Context)
        {
            var LoopLabel = Context.MethodGenerator.DefineLabel("Loop");
            var ContinueLabel = Context.MethodGenerator.DefineLabel("Continue");
            var BreakLabel = Context.MethodGenerator.DefineLabel("Break");
            Context.PushContinueBreakNode(new ContinueBreakNode()
            {
                ContinueLabel = ContinueLabel,
                BreakLabel = BreakLabel,
            }, () =>
            {
                Context.MethodGenerator.Comment("InitialSentence");
                (InitialSentence.AstNode as Node).Generate(Context);
                Context.MethodGenerator.ClearStack();

                LoopLabel.Mark();
                {
                    Context.MethodGenerator.Comment("ConditionExpresion");
                    (ConditionExpresion.AstNode as Node).Generate(Context);
                    //Context.MethodGenerator.ConvTo<bool>();
                    Context.MethodGenerator.BranchIfFalse(BreakLabel);
                }
                {
                    Context.MethodGenerator.Comment("LoopSentence");
                    (LoopSentence.AstNode as Node).Generate(Context);

                    ContinueLabel.Mark();
                    Context.MethodGenerator.Comment("PostSentence");
                    (PostSentence.AstNode as Node).Generate(Context);
                    Context.MethodGenerator.ClearStack();
                    Context.MethodGenerator.BranchAlways(LoopLabel);
                }
                BreakLabel.Mark();
            });
        }
コード例 #5
0
ファイル: ReturnNode.cs プロジェクト: soywiz/nphp
 public override void Generate(NodeGenerateContext Context)
 {
     Context.MethodGenerator.LoadScope();
     (ReturnExpression.AstNode as Node).GenerateAs<Php54Var>(Context);
     Context.MethodGenerator.Call((Action<Php54Var>)Php54Scope.Methods.SetReturnValue);
     Context.MethodGenerator.Return();
 }
コード例 #6
0
ファイル: FunctionCallNode.cs プロジェクト: soywiz/nphp
        public override void Generate(NodeGenerateContext Context)
        {
            int ArgumentsCount = Parameters.ChildNodes.Count;

            Context.MethodGenerator.Comment("Call " + FunctionName);

            Context.MethodGenerator.LoadScope();
            Context.MethodGenerator.Call((Func<Php54Scope>)Php54Scope.Methods.NewScope);
            Context.MethodGenerator.Dup();
            Context.MethodGenerator.Push(ArgumentsCount);
            Context.MethodGenerator.Call((Action<int>)Php54Scope.Methods.SetArgumentCount);

            for (int n = 0; n < ArgumentsCount; n++)
            {
                Context.MethodGenerator.Dup();
                Context.MethodGenerator.Push(n);
                {
                    (Parameters.ChildNodes[n].AstNode as Node).Generate(Context);
                    Context.MethodGenerator.ConvTo<Php54Var>();
                }
                Context.MethodGenerator.Call((Action<int, Php54Var>)Php54Scope.Methods.SetArgument);
            }

            Context.MethodGenerator.Dup();
            Context.MethodGenerator.Push(FunctionName);
            Context.MethodGenerator.Call((Action<string>)Php54Scope.Methods.CallFunctionByName);

            Context.MethodGenerator.Call((Func<Php54Var>)Php54Scope.Methods.GetReturnValue);

            //throw (new NotImplementedException());
        }
コード例 #7
0
        public override void Generate(NodeGenerateContext Context)
        {
            var Function = Context.GenerateFunction(() =>
            {
                Context.FunctionName = FunctionName;
                int ArgumentIndex = 0;
                // Load parameters?
                foreach (var ParameterDeclartion in ParametersDeclaration.ChildNodes)
                {
                    var ArgumentName = ParameterDeclartion.FindTokenAndGetText();
                    {
                        //Context.MethodGenerator.Dup();
                        Context.MethodGenerator.LoadScope();
                        Context.MethodGenerator.Push(ArgumentName);
                        Context.MethodGenerator.Push(ArgumentIndex);
                        Context.MethodGenerator.Call((Action<string, int>)Php54Scope.Methods.LoadArgument);
                    }
                    ArgumentIndex++;
                }

                //Context.MethodGenerator.Pop();

                // Code
                CodeStatements.Generate(Context);
            }, Context.DoDebug);
            Context.FunctionScope.Functions[FunctionName] = Function;
            //throw(new NotImplementedException());
            //base.Generate(Context);
        }
コード例 #8
0
ファイル: IfNode.cs プロジェクト: soywiz/nphp
 public override void Generate(NodeGenerateContext Context)
 {
     var EndLabel = Context.MethodGenerator.DefineLabel("End");
     var FalseLabel = Context.MethodGenerator.DefineLabel("False");
     // Check condition
     {
         (ConditionExpresion.AstNode as Node).Generate(Context);
         //Context.MethodGenerator.ConvTo<bool>();
         Context.MethodGenerator.BranchIfFalse(FalseLabel);
     }
     // True
     {
         (TrueSentence.AstNode as Node).Generate(Context);
         Context.MethodGenerator.BranchAlways(EndLabel);
     }
     // False
     FalseLabel.Mark();
     if (FalseSentence != null)
     {
         (FalseSentence.AstNode as Node).Generate(Context);
         Context.MethodGenerator.BranchAlways(EndLabel);
     }
     EndLabel.Mark();
     //base.Generate(Context);
 }
コード例 #9
0
ファイル: NumberNode.cs プロジェクト: soywiz/nphp
        public override void Generate(NodeGenerateContext Context)
        {
            Context.MethodGenerator.Push(Value);
            //Context.MethodGenerator.Call((Func<int, Php54Var>)Php54Var.FromInt);

            //Console.WriteLine("Value: '{0}'", Value);
        }
コード例 #10
0
ファイル: IgnoreNode.cs プロジェクト: soywiz/nphp
 public override void Generate(NodeGenerateContext Context)
 {
     foreach (var Node in parseNode.ChildNodes)
     {
         var AstNode = (Node)Node.AstNode;
         if (AstNode != null) AstNode.Generate(Context);
     }
 }
コード例 #11
0
ファイル: UnaryExpressionNode.cs プロジェクト: soywiz/nphp
        public override void Generate(NodeGenerateContext Context)
        {
            //base.Generate();
            ((Node)Right.AstNode).Generate(Context);
            Context.MethodGenerator.ConvTo<Php54Var>();

            ((Node)UnaryOperator.AstNode).Generate(Context);
        }
コード例 #12
0
ファイル: ForeachNode.cs プロジェクト: soywiz/nphp
        public override void Generate(NodeGenerateContext Context)
        {
            var IteratorLocal = Context.MethodGenerator.CreateLocal<IEnumerator<KeyValuePair<Php54Var, Php54Var>>>("IteratorLocal");
            var StartLoopLabel = Context.MethodGenerator.DefineLabel("StartLoopLabel");
            var EndLoopLabel = Context.MethodGenerator.DefineLabel("EndtLoopLabel");

            Context.PushContinueBreakNode(new ContinueBreakNode()
            {
                ContinueLabel = StartLoopLabel,
                BreakLabel = EndLoopLabel,
            }, () =>
            {

                (IterableExpressionParseNode.AstNode as Node).Generate(Context);
                Context.MethodGenerator.ConvTo<Php54Var>();
                Context.MethodGenerator.Call((Func<IEnumerator<KeyValuePair<Php54Var, Php54Var>>>)Php54Var.Methods.GetArrayIterator);
                Context.MethodGenerator.StoreToLocal(IteratorLocal);

                StartLoopLabel.Mark();
                {
                    // while (iterator.MoveNext())
                    Context.MethodGenerator.LoadLocal(IteratorLocal);
                    Context.MethodGenerator.Call((Func<IEnumerator<KeyValuePair<Php54Var, Php54Var>>, bool>)Php54Var.IteratorMoveNext);
                    Context.MethodGenerator.BranchIfFalse(EndLoopLabel);

                    if (VariableKeyGetParseNode != null)
                    {
                        // as $key
                        (VariableKeyGetParseNode.AstNode as Node).Generate(Context);
                        Context.MethodGenerator.ConvTo<Php54Var>();
                        // iterator.Current
                        Context.MethodGenerator.LoadLocal(IteratorLocal);
                        Context.MethodGenerator.Call((Func<IEnumerator<KeyValuePair<Php54Var, Php54Var>>, Php54Var>)Php54Var.IteratorGetCurrentKey);
                        Context.MethodGenerator.ConvTo<Php54Var>();
                        // $var = iterator.Current
                        Context.MethodGenerator.Call((Action<Php54Var, Php54Var>)Php54Var.Assign);
                    }

                    // $value
                    (VariableValueGetParseNode.AstNode as Node).Generate(Context);
                    Context.MethodGenerator.ConvTo<Php54Var>();
                    // iterator.Current
                    Context.MethodGenerator.LoadLocal(IteratorLocal);
                    Context.MethodGenerator.Call((Func<IEnumerator<KeyValuePair<Php54Var, Php54Var>>, Php54Var>)Php54Var.IteratorGetCurrentValue);
                    Context.MethodGenerator.ConvTo<Php54Var>();
                    // $var = iterator.Current
                    Context.MethodGenerator.Call((Action<Php54Var, Php54Var>)Php54Var.Assign);

                    // <iteration code>
                    (IterationCodeNode.AstNode as Node).Generate(Context);

                    Context.MethodGenerator.BranchAlways(StartLoopLabel);
                }
                EndLoopLabel.Mark();

                Context.MethodGenerator.ClearStack();
            });
        }
コード例 #13
0
ファイル: UnaryPreOperationNode.cs プロジェクト: soywiz/nphp
 public override void Generate(NodeGenerateContext Context)
 {
     switch (Operator)
     {
         case "++": Context.MethodGenerator.Push(+1); Context.MethodGenerator.Call((Func<Php54Var, int, Php54Var>)Php54Var.UnaryPreIncrement); break;
         case "--": Context.MethodGenerator.Push(-1); Context.MethodGenerator.Call((Func<Php54Var, int, Php54Var>)Php54Var.UnaryPreIncrement); break;
         default: throw (new NotImplementedException("Not implemented operator '" + Operator + "'"));
     }
 }
コード例 #14
0
 public override void Generate(NodeGenerateContext Context)
 {
     var ContinueBreak = Context.GetContinueBreakNodeAt(JumpCount);
     switch (Type)
     {
         case "continue": Context.MethodGenerator.BranchAlways(ContinueBreak.ContinueLabel); break;
         case "break": Context.MethodGenerator.BranchAlways(ContinueBreak.BreakLabel); break;
         default: throw(new InvalidOperationException());
     }
 }
コード例 #15
0
ファイル: GetVariableNode.cs プロジェクト: soywiz/nphp
		public override void Generate(NodeGenerateContext Context)
		{
			GetVariableNode.GetVariable(Context, VariableName);

			foreach (var RankTree in RanksParseNode.ChildNodes)
			{
				(RankTree.AstNode as Node).Generate(Context);
				Context.MethodGenerator.ConvTo<Php54Var>();
				Context.MethodGenerator.Call((Func<Php54Var, Php54Var>)Php54Var.Methods.Access);
			}
		}
コード例 #16
0
ファイル: GlobalStaticNode.cs プロジェクト: soywiz/nphp
        public override void Generate(NodeGenerateContext Context)
        {
            var StaticVariable = Context.MethodGenerator.CreateLocal<Php54Var>("StaticVariable");

            // local
            Context.MethodGenerator.LoadScope();
            Context.MethodGenerator.Push((string)VariableName);
            Context.MethodGenerator.Call((Func<string, Php54Var>)Php54Scope.Methods.GetVariable);
            Context.MethodGenerator.StoreToLocal(StaticVariable);

            // local
            Context.MethodGenerator.LoadLocal(StaticVariable);

            // global
            Context.MethodGenerator.LoadScope();
            Context.MethodGenerator.Push((string)VariableName);
            switch (Type)
            {
                case "global":
                    Context.MethodGenerator.Call((Func<Php54Scope, string, Php54Var>)Php54Runtime.GetGlobal);
                    break;
                case "static":
                    Context.MethodGenerator.Call((Func<Php54Scope, string, Php54Var>)Php54Runtime.GetStatic);
                    break;
                default:
                    throw (new NotImplementedException());
            }

            // create reference and assign to local
            Context.MethodGenerator.Call((Func<Php54Var, Php54Var>)Php54Var.CreateRef);
            Context.MethodGenerator.Call((Action<Php54Var, Php54Var>)Php54Var.Assign);

            if (InitializeNode != null)
            {
                var SkipInitialize = Context.MethodGenerator.DefineLabel("SkipInitialize");

                // Check if null
                Context.MethodGenerator.LoadLocal(StaticVariable);
                Context.MethodGenerator.Call((Func<bool>)Php54Var.Methods.IsNull);
                Context.MethodGenerator.BranchIfFalse(SkipInitialize);

                // Initialize.
                {
                    Context.MethodGenerator.LoadLocal(StaticVariable);
                    (InitializeNode.AstNode as Node).GenerateAs<Php54Var>(Context);
                    Context.MethodGenerator.Call((Action<Php54Var, Php54Var>)Php54Var.Assign);
                }

                SkipInitialize.Mark();
            }
        }
コード例 #17
0
ファイル: AssignmentNode.cs プロジェクト: soywiz/nphp
        public override void Generate(NodeGenerateContext Context)
        {
            (LeftValueNode.AstNode as Node).Generate(Context);
            (ValueNode.AstNode as Node).Generate(Context);
            Context.MethodGenerator.ConvTo<Php54Var>();

            switch (Operator) {
                case "=": Context.MethodGenerator.Call((Action<Php54Var, Php54Var>)Php54Var.Assign); break;
                case "+=": Context.MethodGenerator.Call((Action<Php54Var, Php54Var>)Php54Var.AssignAdd); break;
                case "-=": Context.MethodGenerator.Call((Action<Php54Var, Php54Var>)Php54Var.AssignSub); break;
                default:
                    throw(new NotImplementedException("Not Implemented Assignment Operator: " + Operator));
            }
        }
コード例 #18
0
ファイル: SpecialLiteralNode.cs プロジェクト: soywiz/nphp
 public override void Generate(NodeGenerateContext Context)
 {
     switch (Type)
     {
         //case "true": Context.MethodGenerator.Call((Func<Php54Var>)Php54Var.FromTrue); break;
         case "TRUE": Context.MethodGenerator.Push(true); break;
         case "FALSE": Context.MethodGenerator.Push(false); break;
         case "NULL": Context.MethodGenerator.Call((Func<Php54Var>)Php54Var.FromNull); break;
         case "__DIR__": Context.MethodGenerator.Push(Context.CurrentDirectory); break;
         case "__FILE__": Context.MethodGenerator.Push(Context.CurrentFile); break;
         case "__LINE__": Context.MethodGenerator.Push(parseNode.Span.Location.Line + 1); break;
         case "__FUNCTION__": Context.MethodGenerator.Push(Context.FunctionName); break;
         default: throw (new NotImplementedException("Can't handle special id '" + Type + "'"));
     }
 }
コード例 #19
0
ファイル: IncludeNode.cs プロジェクト: soywiz/nphp
 public override void Generate(NodeGenerateContext Context)
 {
     Context.MethodGenerator.LoadScope();
     ExpressionNode.GenerateAs<string>(Context);
     bool IsRequire = false;
     bool IsOnce = false;
     switch (IncludeType)
     {
         case "include": IsRequire = false; IsOnce = false; break;
         case "include_once": IsRequire = false; IsOnce = true; break;
         case "require": IsRequire = true; IsOnce = false; break;
         case "require_once": IsRequire = true; IsOnce = true; break;
     }
     Context.MethodGenerator.Push(IsRequire);
     Context.MethodGenerator.Push(IsOnce);
     Context.MethodGenerator.Call((Action<Php54Scope, string, bool, bool>)Php54Runtime.Include);
 }
コード例 #20
0
ファイル: SwitchSentenceNode.cs プロジェクト: soywiz/nphp
        public override void Generate(NodeGenerateContext Context)
        {
            var EndSwitchLabel = Context.MethodGenerator.DefineLabel("EndSwitch");

            Context.PushContinueBreakNode(new ContinueBreakNode() { BreakLabel = EndSwitchLabel }, () =>
            {
                var ExpressionLocal = Context.MethodGenerator.CreateLocal<Php54Var>("SwitchExpression");
                {
                    (Expression.AstNode as Node).GenerateAs<Php54Var>(Context);
                }
                Context.MethodGenerator.StoreToLocal(ExpressionLocal);

                var DefaultLabel = EndSwitchLabel;

                foreach (var Sentence in Sentences)
                {
                    var CurrentNode = (Sentence.AstNode as Node).GetNonIgnoredNode();
                    //Console.WriteLine(CurrentNode);
                    var CaseNode = (CurrentNode as SwitchCaseSentenceNode);
                    if (CaseNode != null)
                    {
                        if (CaseNode.IsDefault)
                        {
                            DefaultLabel = CaseNode.Label;
                        }
                        else
                        {
                            Context.MethodGenerator.LoadLocal(ExpressionLocal);
                            (CaseNode.Value.AstNode as Node).GenerateAs<Php54Var>(Context);
                            Context.MethodGenerator.Call((Func<Php54Var, Php54Var, bool>)Php54Var.CompareEquals);
                            Context.MethodGenerator.BranchIfTrue(CaseNode.Label);
                        }
                    }
                }

                Context.MethodGenerator.BranchAlways(DefaultLabel);

                foreach (var Sentence in Sentences)
                {
                    (Sentence.AstNode as Node).Generate(Context);
                }

                EndSwitchLabel.Mark();
                //base.Generate(Context);
            });
        }
コード例 #21
0
ファイル: GetVariableNode.cs プロジェクト: soywiz/nphp
		static public void GetVariable(NodeGenerateContext Context, string VariableName)
		{
#if CACHE_VARIABLES
			bool Cached;
			var Local = Context.MethodGenerator.GetCachedLocal(VariableName, out Cached);

			if (!Cached)
			{
				//Console.WriteLine("Cache local variable");
				Context.MethodGenerator.LoadScope();
				Context.MethodGenerator.Push(VariableName);
				Context.MethodGenerator.Call((Func<string, Php54Var>)Php54Scope.Methods.GetVariable);

				Context.MethodGenerator.StoreToLocal(Local);
			}

			Context.MethodGenerator.LoadLocal(Local);
#else
			Context.MethodGenerator.LoadScope();
			Context.MethodGenerator.Push(VariableName);
			Context.MethodGenerator.Call((Func<string, Php54Var>)Php54Scope.Methods.GetVariable);
#endif
		}
コード例 #22
0
ファイル: UnaryOperatorNode.cs プロジェクト: soywiz/nphp
 public override void Generate(NodeGenerateContext Context)
 {
     switch (Operator)
     {
         case "@":
             //Context.MethodGenerator.Call((Func<Php54Var, Php54Var>)Php54Var.UnarySilence);
         break;
         case "+": Context.MethodGenerator.Call((Func<Php54Var, Php54Var>)Php54Var.UnaryAdd); break;
         case "-": Context.MethodGenerator.Call((Func<Php54Var, Php54Var>)Php54Var.UnarySub); break;
         case "~": Context.MethodGenerator.Call((Func<Php54Var, Php54Var>)Php54Var.UnaryBitNot); break;
         case "!": Context.MethodGenerator.Call((Func<Php54Var, Php54Var>)Php54Var.UnaryLogicNot); break;
         case "&": Context.MethodGenerator.Call((Func<Php54Var, Php54Var>)Php54Var.CreateRef); break;
         case "int": Context.MethodGenerator.Call((Func<int>)Php54Var.Methods.CastToInt); break;
         case "bool": Context.MethodGenerator.Call((Func<bool>)Php54Var.Methods.CastToBool); break;
         case "float": Context.MethodGenerator.Call((Func<double>)Php54Var.Methods.CastToFloat); break;
         case "string": Context.MethodGenerator.Call((Func<string>)Php54Var.Methods.CastToString); break;
         //case "array": Context.MethodGenerator.Call((Func<int>)Php54Var.Methods.CastToArray); break;
         //case "object": Context.MethodGenerator.Call((Func<int>)Php54Var.Methods.CastToObject); break;
         //case "unset": Context.MethodGenerator.Call((Func<object>)Php54Var.Methods.CastToUnset); break;
         default: throw (new NotImplementedException("Not implemented operator '" + Operator + "'"));
     }
     //Context.Operator(Operator);
     //Console.WriteLine("Operator: '{0}'", Operator);
 }
コード例 #23
0
ファイル: WhileNode.cs プロジェクト: soywiz/nphp
        public override void Generate(NodeGenerateContext Context)
        {
            var ContinueLabel = Context.MethodGenerator.DefineLabel("Loop");
            var BreakLabel = Context.MethodGenerator.DefineLabel("End");

            Context.PushContinueBreakNode(new ContinueBreakNode()
            {
                ContinueLabel = ContinueLabel,
                BreakLabel = BreakLabel,
            }, () =>
            {
                ContinueLabel.Mark();
                {
                    (ConditionExpresion.AstNode as Node).Generate(Context);
                    Context.MethodGenerator.ConvTo<bool>();
                    Context.MethodGenerator.BranchIfFalse(BreakLabel);
                }
                {
                    (LoopSentence.AstNode as Node).Generate(Context);
                    Context.MethodGenerator.BranchAlways(ContinueLabel);
                }
                BreakLabel.Mark();
            });
        }
コード例 #24
0
ファイル: PostOperationNode.cs プロジェクト: soywiz/nphp
 public override void Generate(NodeGenerateContext Context)
 {
     VariableNode.Generate(Context);
     UnaryPostOperationNode.Generate(Context);
 }
コード例 #25
0
ファイル: ClassNode.cs プロジェクト: soywiz/nphp
 public override void Generate(NodeGenerateContext Context)
 {
     throw new NotImplementedException();
 }
コード例 #26
0
ファイル: BinaryExpressionNode.cs プロジェクト: soywiz/nphp
 public override void Generate(NodeGenerateContext Context)
 {
     BinaryOperator.Generate(Left, Right, Context);
 }
コード例 #27
0
ファイル: StringNode.cs プロジェクト: soywiz/nphp
        public override void Generate(NodeGenerateContext Context)
        {
            // @TODO: Temporal solution. It should have its own grammar!
            if (Interpolate)
            {
                int LastPosition = 0;
                int CurrentPosition = 0;
                int InterpolatedStackElements = 0;
                //var Parts = new List<string>();

                Action<int> EmitString = (EndPosition) =>
                {
                    if (LastPosition != EndPosition)
                    {
                        var Part = UnquotedString.Substr(LastPosition, EndPosition - LastPosition);
                        Context.MethodGenerator.Push(Part);
                        Context.MethodGenerator.Call((Func<string, Php54Var>)Php54Var.FromString);
                        LastPosition = EndPosition;
                        InterpolatedStackElements++;
                    }
                };

                Action<string> EmitVariable = (VariableName) =>
                {
                    //Console.WriteLine(VariableName);
                    GetVariableNode.GetVariable(Context, VariableName);
                    InterpolatedStackElements++;
                };

                for (CurrentPosition = 0; CurrentPosition < UnquotedString.Length; CurrentPosition++)
                {
                    var Char = UnquotedString[CurrentPosition];
                    if (Char == '{')
                    {
                        if (UnquotedString[CurrentPosition + 1] == '$')
                        {
                            EmitString(CurrentPosition);
                            CurrentPosition = CurrentPosition + 2;
                            int m = CurrentPosition;
                            bool Found = false;
                            for (; CurrentPosition < UnquotedString.Length; CurrentPosition++)
                            {
                                if (UnquotedString[CurrentPosition] == '}')
                                {
                                    Found = true;
                                    break;
                                }
                            }
                            if (!Found) throw (new InvalidOperationException());
                            var Variable = UnquotedString.Substr(m, CurrentPosition - m);
                            EmitVariable(Variable);
                            LastPosition = CurrentPosition + 1;
                        }
                    }
                    else if (Char == '$')
                    {
                        EmitString(CurrentPosition);
                        CurrentPosition = CurrentPosition + 1;
                        int m = CurrentPosition;
                        for (; CurrentPosition < UnquotedString.Length; CurrentPosition++)
                        {
                            if (!PhpVariableTerminal.IsValidCharacter(UnquotedString[CurrentPosition])) break;
                        }
                        var Variable = UnquotedString.Substr(m, CurrentPosition - m);
                        EmitVariable(Variable);
                        CurrentPosition--;

                        LastPosition = CurrentPosition + 1;
                    }
                    else
                    {

                    }
                }

                EmitString(CurrentPosition);

                InterpolatedStackElements--;
                for (int n = 0; n < InterpolatedStackElements; n++)
                {
                    Context.MethodGenerator.Call((Func<Php54Var, Php54Var, Php54Var>)Php54Var.Concat);
                }
            }
            else
            {
                Context.MethodGenerator.Push(UnquotedString);
                Context.MethodGenerator.Call((Func<string, Php54Var>)Php54Var.FromString);
            }
            //Console.WriteLine("Value: '{0}'", Value);
        }
コード例 #28
0
ファイル: SwitchCaseSentenceNode.cs プロジェクト: soywiz/nphp
 public override void Generate(NodeGenerateContext Context)
 {
     Label.Mark();
     //base.Generate(Context);
 }
コード例 #29
0
ファイル: SwitchCaseSentenceNode.cs プロジェクト: soywiz/nphp
 public override void PreGenerateNode(NodeGenerateContext Context)
 {
     //Console.WriteLine("Pregenerate case!");
     Label = Context.MethodGenerator.DefineLabel("case");
 }
コード例 #30
0
ファイル: ExpressionSentenceNode.cs プロジェクト: soywiz/nphp
 public override void Generate(NodeGenerateContext Context)
 {
     base.Generate(Context);
     Context.MethodGenerator.ClearStack();
 }