diff options
author | Iain Buclaw <ibuclaw@gdcproject.org> | 2020-12-23 18:04:47 +0100 |
---|---|---|
committer | Iain Buclaw <ibuclaw@gdcproject.org> | 2020-12-30 11:27:52 +0100 |
commit | ac78516b2758a1a0598c45d0464d18d15661c853 (patch) | |
tree | 95583273941cb437277001299771b83ca1419e4f | |
parent | 8f7941ca37001773a36add8119791725aeb823ba (diff) | |
download | gcc-ac78516b2758a1a0598c45d0464d18d15661c853.zip gcc-ac78516b2758a1a0598c45d0464d18d15661c853.tar.gz gcc-ac78516b2758a1a0598c45d0464d18d15661c853.tar.bz2 |
d: Give the result of evaluated expressions a location
CST trees that were converted back to a D front-end AST node lost all
location information of the original expression. Now this is propagated
on to the literal expression.
gcc/d/ChangeLog:
* d-tree.h (d_eval_constant_expression): Add location argument.
* d-builtins.cc (d_eval_constant_expression): Give generated constants
a proper file location.
* d-compiler.cc (Compiler::paintAsType): Pass expression location to
d_eval_constant_expression.
* d-frontend.cc (eval_builtin): Likewise.
-rw-r--r-- | gcc/d/d-builtins.cc | 17 | ||||
-rw-r--r-- | gcc/d/d-compiler.cc | 4 | ||||
-rw-r--r-- | gcc/d/d-frontend.cc | 2 | ||||
-rw-r--r-- | gcc/d/d-tree.h | 2 |
4 files changed, 13 insertions, 12 deletions
diff --git a/gcc/d/d-builtins.cc b/gcc/d/d-builtins.cc index 72e2d3a..9c629c7 100644 --- a/gcc/d/d-builtins.cc +++ b/gcc/d/d-builtins.cc @@ -332,11 +332,12 @@ build_frontend_type (tree type) } /* Attempt to convert GCC evaluated CST to a D Frontend Expression. + LOC is the location in the source file where this CST is being evaluated. This is used for getting the CTFE value out of a const-folded builtin, returns NULL if it cannot convert CST. */ Expression * -d_eval_constant_expression (tree cst) +d_eval_constant_expression (const Loc &loc, tree cst) { STRIP_TYPE_NOPS (cst); Type *type = build_frontend_type (TREE_TYPE (cst)); @@ -353,23 +354,23 @@ d_eval_constant_expression (tree cst) real_value re = TREE_REAL_CST (TREE_REALPART (cst)); real_value im = TREE_REAL_CST (TREE_IMAGPART (cst)); complex_t value = complex_t (ldouble (re), ldouble (im)); - return ComplexExp::create (Loc (), value, type); + return ComplexExp::create (loc, value, type); } else if (code == INTEGER_CST) { dinteger_t value = TREE_INT_CST_LOW (cst); - return IntegerExp::create (Loc (), value, type); + return IntegerExp::create (loc, value, type); } else if (code == REAL_CST) { real_value value = TREE_REAL_CST (cst); - return RealExp::create (Loc (), ldouble (value), type); + return RealExp::create (loc, ldouble (value), type); } else if (code == STRING_CST) { const void *string = TREE_STRING_POINTER (cst); size_t len = TREE_STRING_LENGTH (cst); - return StringExp::create (Loc (), CONST_CAST (void *, string), len); + return StringExp::create (loc, CONST_CAST (void *, string), len); } else if (code == VECTOR_CST) { @@ -380,17 +381,17 @@ d_eval_constant_expression (tree cst) for (size_t i = 0; i < nunits; i++) { Expression *elem - = d_eval_constant_expression (VECTOR_CST_ELT (cst, i)); + = d_eval_constant_expression (loc, VECTOR_CST_ELT (cst, i)); if (elem == NULL) return NULL; (*elements)[i] = elem; } - Expression *e = ArrayLiteralExp::create (Loc (), elements); + Expression *e = ArrayLiteralExp::create (loc, elements); e->type = type->isTypeVector ()->basetype; - return VectorExp::create (Loc (), e, type); + return VectorExp::create (loc, e, type); } } diff --git a/gcc/d/d-compiler.cc b/gcc/d/d-compiler.cc index ffa7f78..f737d8d 100644 --- a/gcc/d/d-compiler.cc +++ b/gcc/d/d-compiler.cc @@ -133,7 +133,7 @@ Compiler::paintAsType (UnionExp *, Expression *expr, Type *type) cst = native_interpret_expr (vectype, buffer, len); - Expression *e = d_eval_constant_expression (cst); + Expression *e = d_eval_constant_expression (expr->loc, cst); gcc_assert (e != NULL && e->op == TOKvector); return e->isVectorExp ()->e1; @@ -143,7 +143,7 @@ Compiler::paintAsType (UnionExp *, Expression *expr, Type *type) /* Normal interpret cast. */ cst = native_interpret_expr (build_ctype (type), buffer, len); - Expression *e = d_eval_constant_expression (cst); + Expression *e = d_eval_constant_expression (expr->loc, cst); gcc_assert (e != NULL); return e; diff --git a/gcc/d/d-frontend.cc b/gcc/d/d-frontend.cc index da34e90..9133530 100644 --- a/gcc/d/d-frontend.cc +++ b/gcc/d/d-frontend.cc @@ -195,7 +195,7 @@ eval_builtin (Loc loc, FuncDeclaration *fd, Expressions *arguments) /* Builtin should be successfully evaluated. Will only return NULL if we can't convert it. */ if (TREE_CONSTANT (result) && TREE_CODE (result) != CALL_EXPR) - e = d_eval_constant_expression (result); + e = d_eval_constant_expression (loc, result); return e; } diff --git a/gcc/d/d-tree.h b/gcc/d/d-tree.h index 31fe518..f5cf9d3 100644 --- a/gcc/d/d-tree.h +++ b/gcc/d/d-tree.h @@ -496,7 +496,7 @@ extern void d_init_builtins (void); extern void d_register_builtin_type (tree, const char *); extern void d_build_builtins_module (Module *); extern void d_maybe_set_builtin (Module *); -extern Expression *d_eval_constant_expression (tree); +extern Expression *d_eval_constant_expression (const Loc &, tree); extern void d_init_versions (void); /* In d-codegen.cc. */ |