1
0
mirror of https://github.com/cc65/cc65.git synced 2024-06-08 15:29:37 +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:
cuz 2000-08-01 19:05:24 +00:00
parent 85417b6d1b
commit d171b3dac9
4 changed files with 28 additions and 12 deletions

View File

@ -152,7 +152,8 @@ static char* ErrMsg [ERR_COUNT-1] = {
"Variable has unknown size",
"Unknown identifier: `%s'",
"Duplicate qualifier: `%s'",
"Assignment to const",
"Assignment discards `const' qualifier",
"Passing argument %u discards `const' qualifier",
};

View File

@ -148,6 +148,7 @@ enum Errors {
ERR_UNKNOWN_IDENT,
ERR_DUPLICATE_QUALIFIER,
ERR_CONST_ASSIGN,
ERR_CONST_PARAM,
ERR_COUNT /* Error count */
};

View File

@ -580,6 +580,16 @@ static void callfunction (struct expent* lval)
* convert the actual argument to the type needed.
*/
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 */
assignadjust (Param->Type, &lval2);
/* If we have a prototype, chars may be pushed as chars */

View File

@ -191,7 +191,7 @@ static void ParseOneDecl (const DeclSpec* Spec)
/* Setup the type flags for the assignment */
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) {
/* Constant expression. Adjust the types */
assignadjust (Decl.Type, &lval);
@ -268,20 +268,24 @@ static void ParseOneDecl (const DeclSpec* Spec)
/* Static data */
if (curtok == TOK_ASSIGN) {
/* Initialization ahead, switch to data segment */
g_usedata ();
/* Initialization ahead, switch to data segment */
if (IsConst (Decl.Type)) {
g_userodata ();
} else {
g_usedata ();
}
/* Define the variable label */
SymData = GetLabel ();
g_defloclabel (SymData);
/* Define the variable label */
SymData = GetLabel ();
g_defloclabel (SymData);
/* Skip the '=' */
NextToken ();
/* Skip the '=' */
NextToken ();
/* Allow initialization of static vars */
ParseInit (Decl.Type);
/* Allow initialization of static vars */
ParseInit (Decl.Type);
/* Mark the variable as referenced */
/* Mark the variable as referenced */
SC |= SC_REF;
} else {