mirror of
https://github.com/cc65/cc65.git
synced 2024-12-23 04:30:10 +00:00
Check for const in function parameters (first level only).
Place local static const data into the RODATA segment. git-svn-id: svn://svn.cc65.org/cc65/trunk@253 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
85417b6d1b
commit
d171b3dac9
@ -152,7 +152,8 @@ static char* ErrMsg [ERR_COUNT-1] = {
|
|||||||
"Variable has unknown size",
|
"Variable has unknown size",
|
||||||
"Unknown identifier: `%s'",
|
"Unknown identifier: `%s'",
|
||||||
"Duplicate qualifier: `%s'",
|
"Duplicate qualifier: `%s'",
|
||||||
"Assignment to const",
|
"Assignment discards `const' qualifier",
|
||||||
|
"Passing argument %u discards `const' qualifier",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -148,6 +148,7 @@ enum Errors {
|
|||||||
ERR_UNKNOWN_IDENT,
|
ERR_UNKNOWN_IDENT,
|
||||||
ERR_DUPLICATE_QUALIFIER,
|
ERR_DUPLICATE_QUALIFIER,
|
||||||
ERR_CONST_ASSIGN,
|
ERR_CONST_ASSIGN,
|
||||||
|
ERR_CONST_PARAM,
|
||||||
ERR_COUNT /* Error count */
|
ERR_COUNT /* Error count */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -580,6 +580,16 @@ static void callfunction (struct expent* lval)
|
|||||||
* convert the actual argument to the type needed.
|
* convert the actual argument to the type needed.
|
||||||
*/
|
*/
|
||||||
if (!Ellipsis) {
|
if (!Ellipsis) {
|
||||||
|
/* If the left side is not const and the right is const, print
|
||||||
|
* an error. Note: This is an incomplete check, since other parts
|
||||||
|
* of the type string may have a const qualifier, but it catches
|
||||||
|
* some errors and is cheap here. We will redo it the right way
|
||||||
|
* as soon as the parser is rewritten. ####
|
||||||
|
*/
|
||||||
|
if (!IsConst (Param->Type) && IsConst (lval2.e_tptr)) {
|
||||||
|
Error (ERR_CONST_PARAM, ParamCount);
|
||||||
|
}
|
||||||
|
|
||||||
/* Promote the argument if needed */
|
/* Promote the argument if needed */
|
||||||
assignadjust (Param->Type, &lval2);
|
assignadjust (Param->Type, &lval2);
|
||||||
/* If we have a prototype, chars may be pushed as chars */
|
/* If we have a prototype, chars may be pushed as chars */
|
||||||
|
@ -191,7 +191,7 @@ static void ParseOneDecl (const DeclSpec* Spec)
|
|||||||
/* Setup the type flags for the assignment */
|
/* Setup the type flags for the assignment */
|
||||||
flags = Size == 1? CF_FORCECHAR : CF_NONE;
|
flags = Size == 1? CF_FORCECHAR : CF_NONE;
|
||||||
|
|
||||||
/* Get the expression into the primary */
|
/* Get the expression into the primary */
|
||||||
if (evalexpr (flags, hie1, &lval) == 0) {
|
if (evalexpr (flags, hie1, &lval) == 0) {
|
||||||
/* Constant expression. Adjust the types */
|
/* Constant expression. Adjust the types */
|
||||||
assignadjust (Decl.Type, &lval);
|
assignadjust (Decl.Type, &lval);
|
||||||
@ -268,20 +268,24 @@ static void ParseOneDecl (const DeclSpec* Spec)
|
|||||||
/* Static data */
|
/* Static data */
|
||||||
if (curtok == TOK_ASSIGN) {
|
if (curtok == TOK_ASSIGN) {
|
||||||
|
|
||||||
/* Initialization ahead, switch to data segment */
|
/* Initialization ahead, switch to data segment */
|
||||||
g_usedata ();
|
if (IsConst (Decl.Type)) {
|
||||||
|
g_userodata ();
|
||||||
|
} else {
|
||||||
|
g_usedata ();
|
||||||
|
}
|
||||||
|
|
||||||
/* Define the variable label */
|
/* Define the variable label */
|
||||||
SymData = GetLabel ();
|
SymData = GetLabel ();
|
||||||
g_defloclabel (SymData);
|
g_defloclabel (SymData);
|
||||||
|
|
||||||
/* Skip the '=' */
|
/* Skip the '=' */
|
||||||
NextToken ();
|
NextToken ();
|
||||||
|
|
||||||
/* Allow initialization of static vars */
|
/* Allow initialization of static vars */
|
||||||
ParseInit (Decl.Type);
|
ParseInit (Decl.Type);
|
||||||
|
|
||||||
/* Mark the variable as referenced */
|
/* Mark the variable as referenced */
|
||||||
SC |= SC_REF;
|
SC |= SC_REF;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user