コード例 #1
0
ファイル: TypeChecker.mine.cs プロジェクト: AustinWise/CSC431
        private static Type getFun(SymbolTable stable, CommonTree funId, List<Type> argTypes)
        {
            String sym = funId.Text;
            int line = funId.Line;
            if (!stable.exists(sym))
            {
                error(line, "function '" + sym + "' does not exist");
                return null;
            }

            Type fType = stable.getType(sym);
            if (!fType.isFun())
            {
                error(line, "'" + sym + "' is not a function");
                return null;
            }

            List<Type> formals = fType.getArgs();
            if (formals.Count != argTypes.Count)
            {
                error(line, "argument number mis-match when calling '" + sym + "' (need " + formals.Count + ", have " + argTypes.Count + ")");
                return null;
            }

            for (int i = 0; i < formals.Count; i++)
            {
                Type t1, t2;
                t1 = formals[i];
                t2 = argTypes[i];

                if (!t1.canAssign(t2))
                {
                    error(line, "arg " + i + " to function '" + sym + "' is not right");
                    return null;
                }
            }

            return fType.getReturnType();
        }
コード例 #2
0
ファイル: TypeChecker.mine.cs プロジェクト: AustinWise/CSC431
 private static Type getVar(SymbolTable stable, CommonTree sym)
 {
     if (stable.exists(sym.Text))
     {
         Type t = stable.getType(sym.Text);
         if (t.isFun())
             error(sym.Line, "sym '" + sym.Text + "' is a fun and that does not fly");
         return t;
     }
     error(sym.Line, "could not find symbol '" + sym.Text + "'");
     return null;
 }