コード例 #1
0
void SemanticEval::evaluateReturnCmd(ExpressionValue& ev, int line) {
  if(currentScope == SymbolTable::GlobalScope) {
    //tentando retornar no bloco principal
    ErrorHandler::self()->add("Bloco principal não deve ter retorno", line);
  } else {
    //currentScope eh o nome da funcao atual
    try {
      SymbolType sctype = stable.getSymbol(SymbolTable::GlobalScope, currentScope).type;
      
      if(!ev.isCompatibleWidth(sctype)) {
          stringstream msg;
          msg << "Expressão de retorno deve ser compatível com o tipo \"" 
            << sctype.toString() <<  "\"";
          ErrorHandler::self()->add(msg.str(), line);
      } //else ok!
    } catch(SymbolTableException& e) {
      cerr << "Erro interno: SemanticEval::evaluateReturnCmd exception\n";
    }
  } 
}