コード例 #1
0
        public void TestBase()
        {
            var context0 = Substitute.For<ILineContext>();
            context0.ToXML().Returns(new XElement("LineContext", new XAttribute[] { new XAttribute("pos", 0), new XAttribute("line", 0) }));
            var context1 = Substitute.For<ILineContext>();
            context1.ToXML().Returns(new XElement("LineContext", new XAttribute[] { new XAttribute("pos", 1), new XAttribute("line", 2)}));
            var context2 = Substitute.For<ILineContext>();
            context2.ToXML().Returns(new XElement("LineContext", new XAttribute[] { new XAttribute("pos", 3), new XAttribute("line", 4) }));
            Exp exp1 = Substitute.For<Exp>();
            Exp exp2 = Substitute.For<Exp>();
            Base node = new Base(context0);
            FunctionCallExp func = new FunctionCallExp(context0);
            func.Name = new Identifier("funcName");
            ParameterCall param1 = new ParameterCall(context1, exp1);
            param1.Name = "param1";
            ParameterCall param2 = new ParameterCall(context2, exp2);
            param2.Name = "param2";
            func.Args.Add(param1);
            func.Args.Add(param2);
            node.Children.Add(func);
            Assert.AreEqual(
@"<Base>
  <FunctionCallExp Name=""funcName"">
    <ParameterCall Name=""param1"" />
    <ParameterCall Name=""param2"" />
  </FunctionCallExp>
</Base>", node.ToXML(new XMLParser.XMLProperties(false, false)).ToString());
        }
コード例 #2
0
 private void executeBuiltinFunction(FunctionCallExp n)
 {
     switch (n.Name.Name)
     {
         case "print":
             if (n.Args[0].Value.accept(typeVisitor) is Int8Type)
             {
                 if (!stringTable.ContainsKey("%o"))
                     stringTable.Add("%o", ".LC" + stringTable.Count);
                 Add(new Lea(new RegisterOffset(Global.Registers.INSTRUCTIONPOINTER, stringTable["%o"]), new ParamRegister(0)));
             }
             if (n.Args[0].Value.accept(typeVisitor) is Int64Type)
             {
                 if (!stringTable.ContainsKey("%d"))
                     stringTable.Add("%d", ".LC" + stringTable.Count);
                 Add(new Lea(new RegisterOffset(Global.Registers.INSTRUCTIONPOINTER, stringTable["%d"]), new ParamRegister(0)));
             }
             else if (n.Args[0].Value.accept(typeVisitor) is StringType)
             {
                 /*if (!stringTable.ContainsKey("%s"))
                     stringTable.Add("%s", ".LC" + stringTable.Count);
                 n.Args[0].Value.accept(this);
                 Add(new Lea(new RegisterOffset(Global.Registers.INSTRUCTIONPOINTER, stringTable["%s"]), new ParamRegister(0)));*/
             }
             Add(new Call("printf")); break;
     }
 }
コード例 #3
0
 public override void visit(FunctionCallExp n)
 {
     parameterNum = 0;
     foreach (ParameterCall call in n.Args)
         call.Value.accept(this);
     int count = n.Args.Count;
     bool builtin = (tables[0].Lookup(n.Name.Name, n.Args) is BuiltinFunctionSymbol);
     int occupiedParamRegisters = 0;
     if (builtin)
         occupiedParamRegisters = ((BuiltinFunctionSymbol) tables[scope].Lookup(n.Name.Name, n.Args)).OccupiedParamRegisters;
     if (!(n.Args[0].Value is StringLiteral))
         for (int i = 0; i < count; i++)
             Add(new Move(stack.Pop(), new ParamRegister(count - 1 + occupiedParamRegisters - i)));
     if (builtin)
         executeBuiltinFunction(n);
 }
コード例 #4
0
 public abstract void visit(FunctionCallExp n);
コード例 #5
0
 public override void visit(FunctionCallExp n)
 {
     n.Scope.Lookup(n.Name.Name, n.Args).SetReferenced();
 }
コード例 #6
0
 public void visit(FunctionCallExp n)
 {
     throw new NotImplementedException();
 }
コード例 #7
0
 public virtual void visit(FunctionCallExp n)
 {
     // Do nothing; leave the implementation to the main class
 }
コード例 #8
0
 public override void visit(FunctionCallExp n)
 {
     n.Scope = Scope;
     foreach (ParameterCall call in n.Args)
         call.Value.accept(this);
 }
コード例 #9
0
 private void EatFunctionCall()
 {
     FunctionCallExp node = new FunctionCallExp(context[0]);
     node.Name = new Identifier(tokens[0].value);
     CutData(1);
     while (tokens[0].type != Global.DataType.CLOSE_ROUND_BRACKET)
     {
         List<Token> arg = new List<Token>();
         List<ILineContext> argContext = new List<ILineContext>();
         /*while (token.type != Global.DataType.COMMA && token.type != Global.DataType.CLOSE_ROUND_BRACKET)
         {
             arg.Add(token);
             argContext.Add(context[i]);
             token = tokens[++i];
         }*/
         CutData(1);
         node.Args.Add(EatFunctionArgument());
     }
     astBase.Children.Add(node);
 }
コード例 #10
0
 public ASTType visit(FunctionCallExp n)
 {
     throw new NotImplementedException();
 }