Make const variables actually constant. Addresses #922.

Both local and global variables declared with "const" could be modified,
but now expressions that would modify them should generate an error
message at parse-time.
This commit is contained in:
Jon Siwek 2012-12-13 15:05:29 -06:00
parent 6603b851fe
commit 290c2a0b4d
9 changed files with 120 additions and 10 deletions

View file

@ -210,7 +210,6 @@ static void make_var(ID* id, BroType* t, init_class c, Expr* init,
// defined.
Func* f = new BroFunc(id, 0, 0, 0, 0);
id->SetVal(new Val(f));
id->SetConst();
}
}
@ -233,8 +232,9 @@ Stmt* add_local(ID* id, BroType* t, init_class c, Expr* init,
Ref(id);
Expr* name_expr = new NameExpr(id, dt == VAR_CONST);
Stmt* stmt =
new ExprStmt(new AssignExpr(new NameExpr(id), init, 0, 0,
new ExprStmt(new AssignExpr(name_expr, init, 0, 0,
id->Attrs() ? id->Attrs()->Attrs() : 0 ));
stmt->SetLocationInfo(init->GetLocationInfo());