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.
This commit is contained in:
parent
8f7941ca37
commit
ac78516b27
4 changed files with 13 additions and 12 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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. */
|
||||
|
|
Loading…
Add table
Reference in a new issue