Beispiel #1
0
        private static Type getFieldType(StructTypes stypes, Type maybeStruct, CommonTree fieldId)
        {
            String sym = fieldId.Text;
            if (!maybeStruct.isStruct())
            {
                error(fieldId.Line, "invalid selector '" + sym + "'");
                return null;
            }

            StructTypes.StructDef def = stypes.get(maybeStruct.getStructType());

            if (!def.hasField(sym))
            {
                error(fieldId.Line, "struct type '" + def.getName() + "' does not have a field '" + sym + "'");
                return null;
            }

            return def.getFieldType(sym);
        }
Beispiel #2
0
        public static TransformStep<Tuple<CommonTokenStream, CommonTree>> TypeCheck()
        {
            return new TransformStep<Tuple<CommonTokenStream, CommonTree>>(t =>
            {
                CommonTreeNodeStream nodes = new CommonTreeNodeStream(t.Item2);
                nodes.TokenStream = t.Item1;
                TypeChecker tparser = new TypeChecker(nodes);
                tparser.TraceDestination = Console.Out;

                StructTypes stypes = new StructTypes();
                SymbolTable stable = new SymbolTable();

                Program.Stypes.Value = stypes;
                Program.Stable.Value = stable;

                tparser.Program(stypes, stable);

                if (tparser.NumberOfSyntaxErrors != 0)
                    throw new EvilException(EvilSystem.Typecheck, "Type check tree walking errors.");

                return t;
            });
        }
Beispiel #3
0
 public void Program(StructTypes stypes, SymbolTable stable)
 {
     this.program(stypes, stable);
 }
Beispiel #4
0
 private static Type getStruct(StructTypes stypes, CommonTree sym)
 {
     if (stypes.isDefined(sym.Text))
         return Type.structType(sym.Text);
     error(sym.Line, "could not find type '" + sym.Text + "'");
     return null;
 }