MCPcopy Create free account
hub / github.com/WheretIB/nullc / NodeBinaryOp

Method NodeBinaryOp

NULLC/SyntaxTree.cpp:1266–1314  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1264// Node that applies binary operation on two values
1265
1266NodeBinaryOp::NodeBinaryOp(CmdID cmd)
1267{
1268 // Binary operation
1269 cmdID = cmd;
1270
1271 second = TakeLastNode();
1272 first = TakeLastNode();
1273
1274 bool logicalOp = (cmd >= cmdLess && cmd <= cmdNEqual) || (cmd >= cmdLogAnd && cmd <= cmdLogXor);
1275
1276 // Binary operations on complex types are not present at the moment
1277 if(first->typeInfo->type == TypeInfo::TYPE_COMPLEX || second->typeInfo->type == TypeInfo::TYPE_COMPLEX)
1278 ThrowError(CodeInfo::lastKnownStartPos, "ERROR: operation %s is not supported on '%s' and '%s'", binCommandToText[cmdID - cmdAdd], first->typeInfo->GetFullTypeName(), second->typeInfo->GetFullTypeName());
1279 if((first->typeInfo->refLevel != 0 || second->typeInfo->refLevel != 0) && !(first->typeInfo->refLevel == second->typeInfo->refLevel && logicalOp))
1280 ThrowError(CodeInfo::lastKnownStartPos, "ERROR: operation %s is not supported on '%s' and '%s'", binCommandToText[cmdID - cmdAdd], first->typeInfo->GetFullTypeName(), second->typeInfo->GetFullTypeName());
1281 if((first->typeInfo->firstVariable || second->typeInfo->firstVariable) && first->typeInfo != second->typeInfo)
1282 ThrowError(CodeInfo::lastKnownStartPos, "ERROR: operation %s is not supported on '%s' and '%s'", binCommandToText[cmdID - cmdAdd], first->typeInfo->GetFullTypeName(), second->typeInfo->GetFullTypeName());
1283
1284 if(first->typeInfo == typeVoid)
1285 ThrowError(CodeInfo::lastKnownStartPos, "ERROR: first operand returns void");
1286 if(second->typeInfo == typeVoid)
1287 ThrowError(CodeInfo::lastKnownStartPos, "ERROR: second operand returns void");
1288
1289 if((first->typeInfo == typeDouble || first->typeInfo == typeFloat || second->typeInfo == typeDouble || second->typeInfo == typeFloat) && (cmd >= cmdShl && cmd <= cmdLogXor))
1290 ThrowError(CodeInfo::lastKnownStartPos, "ERROR: binary operations are not available on floating-point numbers");
1291
1292 if(typeVoid->refType && first->typeInfo == typeVoid->refType)
1293 {
1294 first->typeInfo = second->typeInfo;
1295 }
1296 if(typeVoid->refType && second->typeInfo == typeVoid->refType)
1297 {
1298 second->typeInfo = first->typeInfo;
1299 }
1300
1301 // Find the type or resulting value
1302 typeInfo = ChooseBinaryOpResultType(first->typeInfo, second->typeInfo);
1303
1304 if(first->nodeType == typeNodeNumber && first->typeInfo != typeInfo)
1305 ((NodeNumber*)first)->ConvertTo(typeInfo);
1306 if(second->nodeType == typeNodeNumber && second->typeInfo != typeInfo)
1307 ((NodeNumber*)second)->ConvertTo(typeInfo);
1308
1309 typeInfo = logicalOp ? typeBool : typeInfo;
1310 if(typeInfo == typeBool && !logicalOp && !(cmd >= cmdBitAnd && cmd <= cmdBitXor))
1311 typeInfo = typeInt;
1312
1313 nodeType = typeNodeBinaryOp;
1314}
1315NodeBinaryOp::~NodeBinaryOp()
1316{
1317}

Callers

nothing calls this directly

Calls 5

TakeLastNodeFunction · 0.85
ThrowErrorFunction · 0.85
ChooseBinaryOpResultTypeFunction · 0.85
GetFullTypeNameMethod · 0.80
ConvertToMethod · 0.80

Tested by

no test coverage detected