Define a field as const, and it'll warn whenever you store to it.

git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@978 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
Spoike 2005-04-23 19:55:49 +00:00
parent 434fedf8a5
commit d8b6a19487

View file

@ -1742,6 +1742,13 @@ QCC_def_t *QCC_PR_Statement ( QCC_opcode_t *op, QCC_def_t *var_a, QCC_def_t *var
} }
} }
if ((op - pr_opcodes >= OP_LOAD_F && op - pr_opcodes <= OP_LOAD_FNC) ||
op - pr_opcodes == OP_LOAD_I)
{
if (var_b->constant == 2)
var_c->constant = true;
}
if (!var_c) if (!var_c)
{ {
if (var_a) if (var_a)
@ -7178,7 +7185,8 @@ void QCC_PR_ParseDefs (char *classname)
int i; int i;
pbool shared=false; pbool shared=false;
pbool externfnc=false; pbool externfnc=false;
pbool constant = true; pbool isconstant = false;
pbool isvar = false;
pbool noref = false; pbool noref = false;
pbool nosave = false; pbool nosave = false;
pbool allocatenew = true; pbool allocatenew = true;
@ -7448,9 +7456,9 @@ void QCC_PR_ParseDefs (char *classname)
QCC_PR_ParseError (ERR_NOSHAREDLOCALS, "Cannot have shared locals"); QCC_PR_ParseError (ERR_NOSHAREDLOCALS, "Cannot have shared locals");
} }
else if (QCC_PR_CheckKeyword(keyword_const, "const")) else if (QCC_PR_CheckKeyword(keyword_const, "const"))
constant = true; isconstant = true;
else if (QCC_PR_CheckKeyword(keyword_var, "var")) else if (QCC_PR_CheckKeyword(keyword_var, "var"))
constant = false; isvar = false;
else if (QCC_PR_CheckKeyword(keyword_noref, "noref")) else if (QCC_PR_CheckKeyword(keyword_noref, "noref"))
noref=true; noref=true;
else if (QCC_PR_CheckKeyword(keyword_nosave, "nosave")) else if (QCC_PR_CheckKeyword(keyword_nosave, "nosave"))
@ -7796,7 +7804,10 @@ void QCC_PR_ParseDefs (char *classname)
else if (type->type == ev_function) else if (type->type == ev_function)
{ {
def->constant = constant; if (isvar)
def->constant = false;
else
def->constant = true;
if (QCC_PR_CheckToken("0")) if (QCC_PR_CheckToken("0"))
{ {
def->constant = 0; def->constant = 0;
@ -7860,7 +7871,7 @@ void QCC_PR_ParseDefs (char *classname)
continue; continue;
} }
if (!def->constant) if (!def->constant)
QCC_PR_ParseError(0, "Functions must be constant"); QCC_PR_ParseError(0, "Initialised functions must be constant");
def->references++; def->references++;
pr_scope = def; pr_scope = def;
@ -7901,7 +7912,10 @@ void QCC_PR_ParseDefs (char *classname)
int arraypart, partnum; int arraypart, partnum;
QCC_type_t *parttype; QCC_type_t *parttype;
def->initialized = 1; def->initialized = 1;
def->constant = constant; if (isvar)
def->constant = true;
else
def->constant = false;
// if (constant) // if (constant)
// QCC_PR_ParseError("const used on a struct isn't useful"); // QCC_PR_ParseError("const used on a struct isn't useful");
@ -8070,7 +8084,11 @@ void QCC_PR_ParseDefs (char *classname)
else if (type->type == ev_integer) //handle these differently, because they may need conversions else if (type->type == ev_integer) //handle these differently, because they may need conversions
{ {
def->constant = constant; if (isvar)
def->constant = false;
else
def->constant = true;
def->initialized = 1; def->initialized = 1;
memcpy (qcc_pr_globals + def->ofs, &pr_immediate, 4*type_size[pr_immediate_type->type]); memcpy (qcc_pr_globals + def->ofs, &pr_immediate, 4*type_size[pr_immediate_type->type]);
QCC_PR_Lex (); QCC_PR_Lex ();
@ -8100,7 +8118,10 @@ void QCC_PR_ParseDefs (char *classname)
d->type = type_string; d->type = type_string;
d->name = "IMMEDIATE"; d->name = "IMMEDIATE";
d->constant = constant; if (isvar)
d->constant = false;
else
d->constant = true;
d->initialized = 1; d->initialized = 1;
d->scope = NULL; d->scope = NULL;
@ -8121,7 +8142,10 @@ void QCC_PR_ParseDefs (char *classname)
} }
else if (arraysize<=1) else if (arraysize<=1)
{ {
def->constant = constant; if (isvar)
def->constant = false;
else
def->constant = true;
def->initialized = 1; def->initialized = 1;
(((int *)qcc_pr_globals)[def->ofs]) = QCC_CopyString(pr_immediate_string); (((int *)qcc_pr_globals)[def->ofs]) = QCC_CopyString(pr_immediate_string);
QCC_PR_Lex (); QCC_PR_Lex ();
@ -8157,13 +8181,17 @@ void QCC_PR_ParseDefs (char *classname)
} }
else if (arraysize<=1) else if (arraysize<=1)
{ {
def->constant = constant; if (isvar)
def->constant = false;
else
def->constant = true;
def->initialized = 1; def->initialized = 1;
if (pr_immediate_type->type != ev_float) if (pr_immediate_type->type != ev_float)
QCC_PR_ParseError (ERR_BADIMMEDIATETYPE, "wrong immediate type for %s", name); QCC_PR_ParseError (ERR_BADIMMEDIATETYPE, "wrong immediate type for %s", name);
if (constant && opt_dupconstdefs) if (def->constant && opt_dupconstdefs)
{ {
if (def->ofs == oldglobals) if (def->ofs == oldglobals)
{ {
@ -8209,7 +8237,10 @@ void QCC_PR_ParseDefs (char *classname)
} }
else if (arraysize<=1) else if (arraysize<=1)
{ {
def->constant = constant; if (isvar)
def->constant = false;
else
def->constant = true;
def->initialized = 1; def->initialized = 1;
(((float *)qcc_pr_globals)[def->ofs+0]) = pr_immediate.vector[0]; (((float *)qcc_pr_globals)[def->ofs+0]) = pr_immediate.vector[0];
(((float *)qcc_pr_globals)[def->ofs+1]) = pr_immediate.vector[1]; (((float *)qcc_pr_globals)[def->ofs+1]) = pr_immediate.vector[1];
@ -8244,7 +8275,6 @@ void QCC_PR_ParseDefs (char *classname)
def->name = name; def->name = name;
def->initialized = true; def->initialized = true;
} }
constant = true;
} }
else if (pr_token_type != tt_immediate) else if (pr_token_type != tt_immediate)
QCC_PR_ParseError (ERR_BADIMMEDIATETYPE, "not an immediate for %s - %s", name, pr_token); QCC_PR_ParseError (ERR_BADIMMEDIATETYPE, "not an immediate for %s - %s", name, pr_token);
@ -8253,10 +8283,21 @@ void QCC_PR_ParseDefs (char *classname)
else else
memcpy (qcc_pr_globals + def->ofs, &pr_immediate, 4*type_size[pr_immediate_type->type]); memcpy (qcc_pr_globals + def->ofs, &pr_immediate, 4*type_size[pr_immediate_type->type]);
def->constant = constant; if (isvar)
def->constant = false;
else
def->constant = true;
def->initialized = true; def->initialized = true;
QCC_PR_Lex (); QCC_PR_Lex ();
} }
else
{
if (isconstant && type->type == ev_field)
def->constant = 2; //special flag on fields, 2, makes the pointer obtained from them also constant.
else
def->constant = isconstant;
}
} while (QCC_PR_CheckToken (",")); } while (QCC_PR_CheckToken (","));