예제 #1
0
 public override Node Transform(ParseScope Scope)
 {
     ResultType = Type.Void;
     LocalScope = Scope.Push(ScopeType.Block);
     Statements = new List<Node>(Statements.Select(s => s.Transform(LocalScope)).Where(n => n != null));
     return this;
 }
예제 #2
0
        public override Node Transform(ParseScope Scope)
        {
            if (HasBeenTransformed) return this;

            ResultType = Scope.FindType("COMPLEXSTRING");

            Function = new Declaration();
            Function.Type = DeclarationType.Lambda;
            Function.Terms = new List<DeclarationTerm>();
            Function.ReturnTypeName = "STRING";
            Function.ReturnType = Scope.FindType("STRING");
            Function.DeclarationScope = Scope.Push(ScopeType.Function);
            Function.DeclarationScope.Owner = Function;

            Pieces = new List<Node>(Pieces.Select(s => s.Transform(Function.DeclarationScope)).Where(n => n != null));

            if (Pieces.Count < 1)
                Pieces.Insert(0, new StringLiteral(Source, "").Transform(Function.DeclarationScope));

            if (Pieces.Count == 1)
            {
                Function.Body = new LambdaBlock(new Ast.Return(Source) { Value = Pieces[0] });
                Function.Body.Transform(Function.DeclarationScope);
            }
            else
            {
                var stringType = Scope.FindType("STRING");

                var binOp = Convert(Pieces[0], stringType, Scope);
                for (int i = 1; i < Pieces.Count; ++i)
                    binOp = new RawBinaryOperator(Source, VirtualMachine.InstructionSet.ADD, binOp,
                        Convert(Pieces[i], stringType, Function.DeclarationScope), stringType);

                Function.Body = new LambdaBlock(new Ast.Return(Source) { Value = binOp });
                Function.Body.Transform(Function.DeclarationScope);
            }

            Scope.AddChildLambda(Function);

            HasBeenTransformed = true;
            return this;
        }