| 1430 | } |
| 1431 | |
| 1432 | void cDirectInterpretASTVisitor::VisitObjectCall(cASTObjectCall& node) |
| 1433 | { |
| 1434 | node.GetObject()->Accept(*this); |
| 1435 | |
| 1436 | if (m_rtype.type != TYPE(OBJECT_REF)) |
| 1437 | INTERPRET_ERROR(TYPE_CAST, mapType(m_rtype.type), mapType(TYPE(OBJECT_REF))); |
| 1438 | |
| 1439 | cASNativeObject* nobj = m_rvalue.as_nobj; |
| 1440 | |
| 1441 | int mid = -1; |
| 1442 | if (!nobj->LookupMethod(node.GetName(), mid)) |
| 1443 | INTERPRET_ERROR(NOBJ_METHOD_LOOKUP_FAILED, *node.GetName(), *m_rtype.info); |
| 1444 | |
| 1445 | int arity = nobj->GetArity(mid); |
| 1446 | // Setup arguments |
| 1447 | cASCPPParameter* args = new cASCPPParameter[arity]; |
| 1448 | if (arity) { |
| 1449 | tListIterator<cASTNode> cit = node.GetArguments()->Iterator(); |
| 1450 | cASTNode* an = NULL; |
| 1451 | for (int i = 0; i < arity; i++) { |
| 1452 | an = cit.Next(); |
| 1453 | an->Accept(*this); |
| 1454 | |
| 1455 | switch (nobj->GetArgumentType(mid, i).type) { |
| 1456 | case TYPE(BOOL): args[i].Set(asBool(m_rtype, m_rvalue, node)); break; |
| 1457 | case TYPE(CHAR): args[i].Set(asChar(m_rtype, m_rvalue, node)); break; |
| 1458 | case TYPE(FLOAT): args[i].Set(asFloat(m_rtype, m_rvalue, node)); break; |
| 1459 | case TYPE(INT): args[i].Set(asInt(m_rtype, m_rvalue, node)); break; |
| 1460 | case TYPE(STRING): args[i].Set(asString(m_rtype, m_rvalue, node)); break; |
| 1461 | |
| 1462 | default: |
| 1463 | INTERPRET_ERROR(INTERNAL); |
| 1464 | } |
| 1465 | } |
| 1466 | } |
| 1467 | |
| 1468 | // Call the function |
| 1469 | cASCPPParameter rvalue = nobj->CallMethod(mid, args); |
| 1470 | |
| 1471 | // Handle the return value |
| 1472 | m_rtype = nobj->GetReturnType(mid); |
| 1473 | switch (m_rtype.type) { |
| 1474 | case TYPE(BOOL): m_rvalue.as_bool = rvalue.Get<bool>(); break; |
| 1475 | case TYPE(CHAR): m_rvalue.as_char = rvalue.Get<char>(); break; |
| 1476 | case TYPE(FLOAT): m_rvalue.as_float = rvalue.Get<double>(); break; |
| 1477 | case TYPE(INT): m_rvalue.as_int = rvalue.Get<int>(); break; |
| 1478 | case TYPE(STRING): m_rvalue.as_string = rvalue.Get<cString*>(); break; |
| 1479 | case TYPE(OBJECT_REF): m_rvalue.as_nobj = rvalue.Get<cASNativeObject*>(); break; |
| 1480 | case TYPE(VOID): break; |
| 1481 | |
| 1482 | default: |
| 1483 | INTERPRET_ERROR(INTERNAL); |
| 1484 | } |
| 1485 | |
| 1486 | // Clean up arguments |
| 1487 | for (int i = 0; i < arity; i++) { |
| 1488 | switch (nobj->GetArgumentType(mid, i).type) { |
| 1489 | case TYPE(BOOL): break; |
nothing calls this directly
no test coverage detected