Merge pull request #2115 from nickrolfe/builtin_complex

C++: support `__builtin_complex`
This commit is contained in:
Matthew Gretton-Dann
2019-10-14 14:40:43 +01:00
committed by GitHub
9 changed files with 4250 additions and 386 deletions

View File

@@ -519,3 +519,18 @@ class BuiltInChooseExpr extends BuiltInOperation, @builtinchooseexpr {
class VectorFillOperation extends UnaryOperation, @vec_fill {
override string getOperator() { result = "(vector fill)" }
}
/**
* The GNU `__builtin_complex` operation.
*/
class BuiltInComplexOperation extends BuiltInOperation, @builtincomplex {
override string toString() { result = "__builtin_complex" }
override string getCanonicalQLClass() { result = "BuiltInComplexOperation" }
/** Gets the operand corresponding to the real part of the complex number. */
Expr getRealOperand() { this.hasChild(result, 0) }
/** Gets the operand corresponding to the imaginary part of the complex number. */
Expr getImaginaryOperand() { this.hasChild(result, 1) }
}

View File

@@ -1515,6 +1515,7 @@ case @expr.kind of
| 322 = @builtinaddressof
| 323 = @vec_fill
| 324 = @builtinconvertvector
| 325 = @builtincomplex
;
new_allocated_type(

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,4 @@
| complex.c:3:23:3:51 | __builtin_complex | file://:0:0:0:0 | _Complex double | complex.c:3:41:3:44 | real | file://:0:0:0:0 | double | complex.c:3:47:3:50 | imag | file://:0:0:0:0 | double |
| complex.c:4:23:4:57 | __builtin_complex | file://:0:0:0:0 | _Complex double | complex.c:4:41:4:47 | 2.71828000000000003 | file://:0:0:0:0 | double | complex.c:4:50:4:56 | 3.141589999999999883 | file://:0:0:0:0 | double |
| complex.c:8:22:8:52 | __builtin_complex | file://:0:0:0:0 | _Complex float | complex.c:8:40:8:44 | realf | file://:0:0:0:0 | float | complex.c:8:47:8:51 | imagf | file://:0:0:0:0 | float |
| complex.c:9:22:9:52 | __builtin_complex | file://:0:0:0:0 | _Complex float | complex.c:9:40:9:44 | 1.230000019 | file://:0:0:0:0 | float | complex.c:9:47:9:51 | 4.559999943 | file://:0:0:0:0 | float |

View File

@@ -0,0 +1,7 @@
import cpp
from BuiltInComplexOperation bico, Expr real, Expr imag
where
real = bico.getRealOperand() and
imag = bico.getImaginaryOperand()
select bico, bico.getType(), real, real.getType(), imag, imag.getType()

View File

@@ -0,0 +1,10 @@
void builtin_double(double real, double imag) {
_Complex double a = __builtin_complex(real, imag);
_Complex double b = __builtin_complex(2.71828, 3.14159);
}
void builtin_float(float realf, float imagf) {
_Complex float c = __builtin_complex(realf, imagf);
_Complex float d = __builtin_complex(1.23f, 4.56f);
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,2 @@
description: Add support for __builtin_complex
compatibility: backwards