diff options
author | 2003-06-10 12:38:42 -0700 | |
---|---|---|
committer | 2005-04-07 21:00:51 -0700 | |
commit | 2e47ece69eb31acdaecb187a23f97861409fd6cf (patch) | |
tree | 28f387f8be1328cb69c4a197042023f7ecf861f4 /inline.c | |
parent | Start doing real expression copying for the inliner. We need to (diff) | |
download | sparse-2e47ece69eb31acdaecb187a23f97861409fd6cf.tar.gz sparse-2e47ece69eb31acdaecb187a23f97861409fd6cf.tar.bz2 sparse-2e47ece69eb31acdaecb187a23f97861409fd6cf.zip |
Add cheesy C++-like "const variable" evaluation. It's not C, but
it _should_ be
Make beginnings of a statement copier, to start testing trival
inline function replacement.
The return symbol replacement doesn't work, but the theory is
there.
NOTE! I'm getting more and more convinced that the symbol replacement
is a bad idea, and is should be doable some other way (ie by looking
up symbols at _evaluation_ time rather than having to switch them around
when inlining).
Diffstat (limited to 'inline.c')
-rw-r--r-- | inline.c | 32 |
1 files changed, 30 insertions, 2 deletions
@@ -15,8 +15,6 @@ #include "symbol.h" #include "expression.h" -#define copy_one_statement(stmt) (stmt) - static struct expression * dup_expression(struct expression *expr) { struct expression *dup = alloc_expression(expr->pos, expr->type); @@ -116,6 +114,36 @@ static struct expression * copy_expression(struct expression *expr) return expr; } +static struct statement * dup_statement(struct statement *stmt) +{ + struct statement *dup = alloc_statement(stmt->pos, stmt->type); + *dup = *stmt; + return dup; +} + +static struct statement *copy_one_statement(struct statement *stmt) +{ + if (!stmt) + return NULL; + switch(stmt->type) { + case STMT_NONE: + break; + case STMT_RETURN: { + struct expression *retval = copy_expression(stmt->ret_value); + struct symbol *sym = stmt->ret_target->replace; + + stmt = dup_statement(stmt); + stmt->ret_value = retval; + stmt->ret_target = sym; + break; + } + default: + break; + } + return stmt; +} + + /* * Copy a stateemnt tree from 'src' to 'dst', where both * source and destination are of type STMT_COMPOUND. |