示例#1
0
void SymbolCheckVisitor::visit(ASTFunction& ast)
{
   ScopedScope scope(mScopeStack);
   ScopedValue<ASTFunction*> scopedfunction(&mpFunction, &ast, mpFunction);
   ASSERT_PTR(mpFunction);

   visitChildren(ast); // <-- arguments

   if ( ast.isConstructor() && ast.getName() != mpClass->getName() )
   {
      error(E0005, UTEXT("Function ") + ast.getName() + UTEXT(" must have a return type (or equal class name as constructor)."), ast);
   }

   if ( ast.hasBody() )
   {
      if ( ast.getModifiers().isAbstract() )
      {
         error(E0006, UTEXT("Abstract function ") + ast.getName() + UTEXT(" should not have a body."), ast);
      }
      else
      {
         checkReturn(ast);

         ast.getBody().accept(*this);
      }
   }
   else if ( !ast.getModifiers().isAbstract() && !ast.getModifiers().isPureNative() )
   {
      error(E0007, UTEXT("Function ") + ast.getName() + UTEXT(" requires a body."), ast);
   }

   mCurrentType.clear();
}
示例#2
0
void OOCheckVisitor::visit(ASTFunction& ast)
{
   mpFunction = &ast;

   ScopedScope scope(mScopeStack);

   ast.getArgumentNodes().accept(*this);

   if ( ast.hasAnnotations() )
   {
      if ( ast.getAnnotations().contains(UTEXT("override")) )
      {
         // check if the base class still has this function
      }
   }

   if ( ast.isConstructor() )
   {
      // abstract classes can not have native constructors
      /*
      if ( ast.getModifiers().isNative() && mpClass->getModifiers().isAbstract() )
      {
         mContext.getLog().error("Abstract class " + mpClass->getFullName() + " can not have native constructors.");
      }
      */
   }
   else
   {
      if ( mpClass->hasBaseClass() )
      {
         ASTClass& baseclass = mpClass->getBaseClass();
         ASTFunction* pbasefunc = baseclass.findExactMatch(ast.getName(), ast.getSignature());
         if ( pbasefunc != NULL )
         {
            ast.setBaseFunction(*pbasefunc);
         }
      }
   }

   if ( ast.hasBody() )
   {
      mHasNativeCall = false;

      ast.getBody().accept(*this);

      if ( mHasNativeCall )
      {
         ast.getModifiers().setNative(true);
      }
   }
}