aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@home.transmeta.com>2003-06-10 12:38:42 -0700
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-07 21:00:51 -0700
commit2e47ece69eb31acdaecb187a23f97861409fd6cf (patch)
tree28f387f8be1328cb69c4a197042023f7ecf861f4
parent0bd178e427936765ce3289ec8532483889f657b6 (diff)
downloadsparse-2e47ece69eb31acdaecb187a23f97861409fd6cf.tar.gz
sparse-2e47ece69eb31acdaecb187a23f97861409fd6cf.tar.xz
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).
-rw-r--r--evaluate.c11
-rw-r--r--inline.c32
2 files changed, 41 insertions, 2 deletions
diff --git a/evaluate.c b/evaluate.c
index 7e449de..451158e 100644
--- a/evaluate.c
+++ b/evaluate.c
@@ -57,6 +57,16 @@ static struct symbol *evaluate_symbol_expression(struct expression *expr)
/* The type of a symbol is the symbol itself! */
expr->ctype = sym;
+ /* Const symbol with a constant initializer? */
+ if (sym->ctype.modifiers & MOD_CONST) {
+ struct expression *value = sym->initializer;
+ if (value && value->type == EXPR_VALUE) {
+ expr->type = EXPR_VALUE;
+ expr->value = value->value;
+ return sym;
+ }
+ }
+
/* enum's can be turned into plain values */
if (sym->type != SYM_ENUM) {
struct expression *addr = alloc_expression(expr->pos, EXPR_SYMBOL);
@@ -1405,6 +1415,7 @@ static int inline_function(struct expression *expr, struct symbol *sym)
if (name) {
a->ident = name->ident;
a->ctype.modifiers = name->ctype.modifiers;
+ name->replace = a;
}
a->ctype.base_type = arg->ctype;
a->initializer = arg;
diff --git a/inline.c b/inline.c
index 0f41e5f..958a3f1 100644
--- a/inline.c
+++ b/inline.c
@@ -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.