| 260 | String SpireStdLib::code; |
| 261 | |
| 262 | String SpireStdLib::GetCode() |
| 263 | { |
| 264 | if (code.Length() > 0) |
| 265 | return code; |
| 266 | StringBuilder sb; |
| 267 | // generate operator overloads |
| 268 | Operator floatUnaryOps[] = { Operator::Neg, Operator::Not, Operator::PreInc, Operator::PreDec }; |
| 269 | Operator intUnaryOps[] = { Operator::Neg, Operator::Not, Operator::BitNot, Operator::PreInc, Operator::PreDec}; |
| 270 | Operator floatOps[] = { Operator::Mul, Operator::Div, |
| 271 | Operator::Add, Operator::Sub, Operator::And, Operator::Or, |
| 272 | Operator::Eql, Operator::Neq, Operator::Greater, Operator::Less, Operator::Geq, Operator::Leq }; |
| 273 | Operator intOps[] = { Operator::Mul, Operator::Div, Operator::Mod, |
| 274 | Operator::Add, Operator::Sub, |
| 275 | Operator::Lsh, Operator::Rsh, |
| 276 | Operator::Eql, Operator::Neq, Operator::Greater, Operator::Less, Operator::Geq, Operator::Leq, |
| 277 | Operator::BitAnd, Operator::BitXor, Operator::BitOr, |
| 278 | Operator::And, |
| 279 | Operator::Or }; |
| 280 | String floatTypes[] = { "float", "vec2", "vec3", "vec4" }; |
| 281 | String intTypes[] = { "int", "ivec2", "ivec3", "ivec4" }; |
| 282 | String uintTypes[] = { "uint", "uvec2", "uvec3", "uvec4" }; |
| 283 | |
| 284 | sb << "__intrinsic vec3 operator * (vec3, mat3);\n"; |
| 285 | sb << "__intrinsic vec3 operator * (mat3, vec3);\n"; |
| 286 | |
| 287 | sb << "__intrinsic vec4 operator * (vec4, mat4);\n"; |
| 288 | sb << "__intrinsic vec4 operator * (mat4, vec4);\n"; |
| 289 | |
| 290 | sb << "__intrinsic mat3 operator * (mat3, mat3);\n"; |
| 291 | sb << "__intrinsic mat4 operator * (mat4, mat4);\n"; |
| 292 | |
| 293 | sb << "__intrinsic bool operator && (bool, bool);\n"; |
| 294 | sb << "__intrinsic bool operator || (bool, bool);\n"; |
| 295 | |
| 296 | for (auto type : intTypes) |
| 297 | { |
| 298 | sb << "__intrinsic bool operator && (bool, " << type << ");\n"; |
| 299 | sb << "__intrinsic bool operator || (bool, " << type << ");\n"; |
| 300 | sb << "__intrinsic bool operator && (" << type << ", bool);\n"; |
| 301 | sb << "__intrinsic bool operator || (" << type << ", bool);\n"; |
| 302 | } |
| 303 | |
| 304 | for (auto op : intUnaryOps) |
| 305 | { |
| 306 | String opName = GetOperatorFunctionName(op); |
| 307 | for (int i = 0; i < 4; i++) |
| 308 | { |
| 309 | auto itype = intTypes[i]; |
| 310 | auto utype = uintTypes[i]; |
| 311 | for (int j = 0; j < 2; j++) |
| 312 | { |
| 313 | auto retType = (op == Operator::Not) ? "bool" : j == 0 ? itype : utype; |
| 314 | sb << "__intrinsic " << retType << " operator " << opName << "(" << (j == 0 ? itype : utype) << ");\n"; |
| 315 | } |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | for (auto op : floatUnaryOps) |
nothing calls this directly
no test coverage detected