MCPcopy Create free account
hub / github.com/EmbeddedRPC/erpc / handleBinaryOp

Method handleBinaryOp

erpcgen/src/SymbolScanner.cpp:322–577  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

320}
321
322AstNode *SymbolScanner::handleBinaryOp(AstNode *node, bottom_up)
323{
324 Log::debug("binop: %s\n", node->getDescription().c_str());
325
326 Token &tok = node->getToken();
327
328 // Get the left operand.
329 AstNode *left = (*node)[0];
330 assert(left);
331 Token &leftTok = left->getToken();
332
333 smart_ptr<Value> leftValue;
334 IntegerValue *leftInt;
335 FloatValue *leftFloat;
336
337 if (leftTok.isIdentifierTok())
338 {
339 leftValue = getValueFromSymbol(leftTok);
340 leftInt = dynamic_cast<IntegerValue *>(leftValue.get());
341 leftFloat = dynamic_cast<FloatValue *>(leftValue.get());
342 }
343 else if (leftTok.isNumberTok())
344 {
345 leftInt = dynamic_cast<IntegerValue *>(leftTok.getValue());
346 leftFloat = dynamic_cast<FloatValue *>(leftTok.getValue());
347 }
348 else
349 {
350 throw semantic_error(
351 format_string("expression \"%s\" invalid as binary operand", leftTok.getValue()->toString().c_str()));
352 }
353
354 // Get the right operand.
355 AstNode *right = (*node)[1];
356 assert(right);
357 Token &rightTok = right->getToken();
358
359 smart_ptr<Value> rightValue;
360 IntegerValue *rightInt;
361 FloatValue *rightFloat;
362
363 if (rightTok.isIdentifierTok())
364 {
365 rightValue = getValueFromSymbol(rightTok);
366 rightInt = dynamic_cast<IntegerValue *>(rightValue.get());
367 rightFloat = dynamic_cast<FloatValue *>(rightValue.get());
368 }
369 else if (rightTok.isNumberTok())
370 {
371 rightInt = dynamic_cast<IntegerValue *>(rightTok.getValue());
372 rightFloat = dynamic_cast<FloatValue *>(rightTok.getValue());
373 }
374 else
375 {
376 throw semantic_error(
377 format_string("expression \"%s\" invalid as binary operand", rightTok.getValue()->toString().c_str()));
378 }
379

Callers

nothing calls this directly

Calls 14

semantic_errorClass · 0.85
format_stringFunction · 0.85
internal_errorClass · 0.85
getTokenMethod · 0.80
isIdentifierTokMethod · 0.80
isNumberTokMethod · 0.80
getTokenNameMethod · 0.80
getIntTypeMethod · 0.80
TokenClass · 0.70
getDescriptionMethod · 0.45
getMethod · 0.45
getValueMethod · 0.45

Tested by

no test coverage detected