예제 #1
0
 /// <summary>
 /// Creates a new Symbol Table
 /// </summary>
 public Table(Table reference, Global.Scope scopeType, string identifier)
 {
     ParentOf = new List<Table>();
     dictionary = new Dictionary<Tuple<string, List<ASTType>>, Symbol>(new TableFunctionComparator());
     this.reference = reference;
     if (reference != null)
         reference.ParentOf.Add(this);
     this.scopeType = scopeType;
     this.identifier = identifier;
     symbolToTableVisitor = new SymbolToTableVisitor(dictionary);
 }
예제 #2
0
 public void TestLookup()
 {
     Table swiftTable = new Table(null, 0, null);
     BuiltinFunctionSymbol printSymbol = new BuiltinFunctionSymbol("print");
     List<ParameterDeclaration> lst = new List<ParameterDeclaration>();
     ParameterDeclaration par = new ParameterDeclaration(null, new Int64Type(), null);
     lst.Add(par);
     printSymbol.Parameters = lst;
     printSymbol.ReturnValue = new TupleType();
     swiftTable.Insert(printSymbol);
     Assert.IsNotNull(swiftTable.Lookup("print", new List<ASTType>() { new Int64Type() }));
 }
        public static Table CreateBuiltinSymbols()
        {
            Table swiftTable = new Table(null, Global.Scope.BuiltinScope, "Builtin");
            // print(string)
            BuiltinFunctionSymbol printSymbol = new BuiltinFunctionSymbol("print");
            List<ParameterDeclaration> lst = new List<ParameterDeclaration>();
            ParameterDeclaration par = new ParameterDeclaration(null, new StringType(), null);
            lst.Add(par);
            printSymbol.Parameters = lst;
            printSymbol.ReturnValue = new TupleType();
            printSymbol.OccupiedParamRegisters = 1;
            swiftTable.Insert(printSymbol);

            // print(int8)
            printSymbol = new BuiltinFunctionSymbol("print");
            lst = new List<ParameterDeclaration>();
            par = new ParameterDeclaration(null, new Int8Type(), null);
            lst.Add(par);
            printSymbol.Parameters = lst;
            printSymbol.ReturnValue = new TupleType();
            printSymbol.OccupiedParamRegisters = 1;
            swiftTable.Insert(printSymbol);

            // print(int16)
            printSymbol = new BuiltinFunctionSymbol("print");
            lst = new List<ParameterDeclaration>();
            par = new ParameterDeclaration(null, new Int16Type(), null);
            lst.Add(par);
            printSymbol.Parameters = lst;
            printSymbol.ReturnValue = new TupleType();
            printSymbol.OccupiedParamRegisters = 1;
            swiftTable.Insert(printSymbol);

            // print(int32)
            printSymbol = new BuiltinFunctionSymbol("print");
            lst = new List<ParameterDeclaration>();
            par = new ParameterDeclaration(null, new Int32Type(), null);
            lst.Add(par);
            printSymbol.Parameters = lst;
            printSymbol.ReturnValue = new TupleType();
            printSymbol.OccupiedParamRegisters = 1;
            swiftTable.Insert(printSymbol);

            // print(int64)
            printSymbol = new BuiltinFunctionSymbol("print");
            lst = new List<ParameterDeclaration>();
            par = new ParameterDeclaration(null, new Int64Type(), null);
            lst.Add(par);
            printSymbol.Parameters = lst;
            printSymbol.ReturnValue = new TupleType();
            printSymbol.OccupiedParamRegisters = 1;
            swiftTable.Insert(printSymbol);

            // print(uint8)
            printSymbol = new BuiltinFunctionSymbol("print");
            lst = new List<ParameterDeclaration>();
            par = new ParameterDeclaration(null, new UInt8Type(), null);
            lst.Add(par);
            printSymbol.Parameters = lst;
            printSymbol.ReturnValue = new TupleType();
            printSymbol.OccupiedParamRegisters = 1;
            swiftTable.Insert(printSymbol);

            // print(uint16)
            printSymbol = new BuiltinFunctionSymbol("print");
            lst = new List<ParameterDeclaration>();
            par = new ParameterDeclaration(null, new UInt16Type(), null);
            lst.Add(par);
            printSymbol.Parameters = lst;
            printSymbol.ReturnValue = new TupleType();
            printSymbol.OccupiedParamRegisters = 1;
            swiftTable.Insert(printSymbol);

            // print(uint32)
            printSymbol = new BuiltinFunctionSymbol("print");
            lst = new List<ParameterDeclaration>();
            par = new ParameterDeclaration(null, new UInt32Type(), null);
            lst.Add(par);
            printSymbol.Parameters = lst;
            printSymbol.ReturnValue = new TupleType();
            printSymbol.OccupiedParamRegisters = 1;
            swiftTable.Insert(printSymbol);

            // print(uint64)
            printSymbol = new BuiltinFunctionSymbol("print");
            lst = new List<ParameterDeclaration>();
            par = new ParameterDeclaration(null, new UInt64Type(), null);
            lst.Add(par);
            printSymbol.Parameters = lst;
            printSymbol.ReturnValue = new TupleType();
            printSymbol.OccupiedParamRegisters = 1;
            swiftTable.Insert(printSymbol);

            return swiftTable;
        }