MCPcopy Create free account
hub / github.com/csyonghe/Spire / EvaluateInfixOp

Function EvaluateInfixOp

Source/SpireCore/Preprocessor.cpp:1106–1160  ·  view source on GitHub ↗

Evaluate one infix operation in a preprocessor conditional expression

Source from the content-addressed store, hash-verified

1104// Evaluate one infix operation in a preprocessor
1105// conditional expression
1106static PreprocessorExpressionValue EvaluateInfixOp(
1107 PreprocessorDirectiveContext* context,
1108 Token const& opToken,
1109 PreprocessorExpressionValue left,
1110 PreprocessorExpressionValue right)
1111{
1112 switch (opToken.Type)
1113 {
1114 default:
1115// SPIRE_INTERNAL_ERROR(getSink(preprocessor), opToken);
1116 return 0;
1117 break;
1118
1119 case TokenType::OpMul: return left * right;
1120 case TokenType::OpDiv:
1121 {
1122 if (right == 0)
1123 {
1124 if (!context->parseError)
1125 {
1126 GetSink(context)->diagnose(opToken.Position, Diagnostics::divideByZeroInPreprocessorExpression);
1127 }
1128 return 0;
1129 }
1130 return left / right;
1131 }
1132 case TokenType::OpMod:
1133 {
1134 if (right == 0)
1135 {
1136 if (!context->parseError)
1137 {
1138 GetSink(context)->diagnose(opToken.Position, Diagnostics::divideByZeroInPreprocessorExpression);
1139 }
1140 return 0;
1141 }
1142 return left % right;
1143 }
1144 case TokenType::OpAdd: return left + right;
1145 case TokenType::OpSub: return left - right;
1146 case TokenType::OpLsh: return left << right;
1147 case TokenType::OpRsh: return left >> right;
1148 case TokenType::OpLess: return left < right ? 1 : 0;
1149 case TokenType::OpGreater: return left > right ? 1 : 0;
1150 case TokenType::OpLeq: return left <= right ? 1 : 0;
1151 case TokenType::OpGeq: return left <= right ? 1 : 0;
1152 case TokenType::OpEql: return left == right ? 1 : 0;
1153 case TokenType::OpNeq: return left != right ? 1 : 0;
1154 case TokenType::OpBitAnd: return left & right;
1155 case TokenType::OpBitOr: return left | right;
1156 case TokenType::OpBitXor: return left ^ right;
1157 case TokenType::OpAnd: return left && right;
1158 case TokenType::OpOr: return left || right;
1159 }
1160}
1161
1162// Parse the rest of an infix preprocessor expression with
1163// precedence greater than or equal to the given `precedence` argument.

Calls 2

GetSinkFunction · 0.85
diagnoseMethod · 0.80

Tested by

no test coverage detected