示例#1
0
        public void Visit(Ast.Expr.FuncCall f)
        {
            foreach (var e in f.Item.ExprList)
            {
                Visit(e);
            }
            if (f.Item.Decl == null)
            {
                return;
            }
            Ast.Stmt.Funcdef fd = (Ast.Stmt.Funcdef)f.Item.Decl.Value;
            // Compare param types to decl types
            var formalList      = SeqModule.ToList(fd.Item.FormalList);
            var actualList      = SeqModule.ToList(f.Item.ExprList);
            var actualAndFormal = ListModule.Zip(actualList, formalList);

            foreach (var af in actualAndFormal)
            {
                if (af.Item1.ActualType != af.Item2.Formal.Type)
                {
                    m_errorList.Add("Type Error: Cannot use actual paramater of type " + af.Item1.ActualType +
                                    " for formal paramater of type " + af.Item2.Formal.Type);
                }
            }
            f.ActualType = fd.Item.Formal.Type;
        }
示例#2
0
 public void Visit(Ast.Stmt.Return r)
 {
     Visit(r.Item.Expr.Value);
     Ast.Stmt.Funcdef fd = (Ast.Stmt.Funcdef)r.Item.Decl.Value;
     Ast.Expr         e  = r.Item.Expr.Value;
     if (fd.Item.Formal.Type != e.ActualType)
     {
         m_errorList.Add("Type Error: Cannot return " + e.ActualType +
                         " from function " + fd.Item.Formal.Name +
                         " returning " + fd.Item.Formal.Type);
     }
 }
示例#3
0
 public void Visit(Ast.Stmt.Return r)
 {
     Visit(r.Item.Expr.Value);
     if (this.m_FunctionStack.Count == 0)
     {
         r.Item.Decl = (Ast.Stmt.Funcdef)Ast.Stmt.Funcdef.NewFuncdef(new Ast.FuncdefType(new System.Tuple <Ast.Formal, FSharpList <Ast.VardefType>, Ast.Stmt>(new Ast.Formal("$global", Ast.Type.IntType), null, null)));
         // FuncionStack is no longer needed, anything after returning $global is not allowed
     }
     else
     {
         r.Item.Decl = this.m_FunctionStack.Peek();
     }
     Ast.Stmt.Funcdef fd = (Ast.Stmt.Funcdef)r.Item.Decl.Value;
     //System.Console.WriteLine("Return " + fd.Item.Formal.Name);
 }
示例#4
0
 public void Visit(Ast.Stmt.Funcdef f)
 {
     this.m_FunctionStack.Push(f);
     //System.Console.WriteLine("Push " + f);
     this.m_symbolTable.Insert(f.Item.Formal.Name, f);
     // Add formal params to defs
     this.m_symbolTable.PushNewScope();
     foreach (var formal in f.Item.FormalList)
     {
         Ast.Stmt.Vardef vd = (Ast.Stmt.Vardef)Ast.Stmt.Vardef.NewVardef(new Ast.VardefType(new System.Tuple <Ast.Formal, FSharpOption <Ast.Expr> >(formal.Formal, new FSharpOption <Ast.Expr>(null))));
         this.m_symbolTable.Insert(vd.Item.Formal.Name, vd);
     }
     Visit(f.Item.Body);
     this.m_FunctionStack.Pop();
     //System.Console.WriteLine("Pop " + f);
     this.m_symbolTable.PopScope();
 }
示例#5
0
 public void Visit(Ast.Stmt.Funcdef f)
 {
     Visit(f.Item.Body);
 }