Renamed StaticConstExpr() and StaticConstAbsIntExpr() with clearer comments.

This commit is contained in:
acqn
2020-08-30 00:26:52 +08:00
parent 492ee7fc45
commit 60c59f59a3
8 changed files with 37 additions and 37 deletions

View File

@@ -135,7 +135,7 @@ static void ParseByteArg (StrBuf* T, unsigned Arg)
ConsumeComma (); ConsumeComma ();
/* Evaluate the expression */ /* Evaluate the expression */
ExprDesc Expr = StaticConstAbsIntExpr (hie1); ExprDesc Expr = NoCodeConstAbsIntExpr (hie1);
/* Check the range but allow negative values if the type is signed */ /* Check the range but allow negative values if the type is signed */
if (IsSignUnsigned (Expr.Type)) { if (IsSignUnsigned (Expr.Type)) {
@@ -168,7 +168,7 @@ static void ParseWordArg (StrBuf* T, unsigned Arg)
ConsumeComma (); ConsumeComma ();
/* Evaluate the expression */ /* Evaluate the expression */
ExprDesc Expr = StaticConstAbsIntExpr (hie1); ExprDesc Expr = NoCodeConstAbsIntExpr (hie1);
/* Check the range but allow negative values if the type is signed */ /* Check the range but allow negative values if the type is signed */
if (IsSignUnsigned (Expr.Type)) { if (IsSignUnsigned (Expr.Type)) {
@@ -201,7 +201,7 @@ static void ParseLongArg (StrBuf* T, unsigned Arg attribute ((unused)))
ConsumeComma (); ConsumeComma ();
/* Evaluate the expression */ /* Evaluate the expression */
ExprDesc Expr = StaticConstAbsIntExpr (hie1); ExprDesc Expr = NoCodeConstAbsIntExpr (hie1);
/* Convert into a hex number */ /* Convert into a hex number */
xsprintf (Buf, sizeof (Buf), "$%08lX", Expr.IVal & 0xFFFFFFFF); xsprintf (Buf, sizeof (Buf), "$%08lX", Expr.IVal & 0xFFFFFFFF);
@@ -325,7 +325,7 @@ static void ParseStrArg (StrBuf* T, unsigned Arg attribute ((unused)))
break; break;
default: default:
Expr = StaticConstAbsIntExpr (hie1); Expr = NoCodeConstAbsIntExpr (hie1);
xsprintf (Buf, sizeof (Buf), "%ld", Expr.IVal); xsprintf (Buf, sizeof (Buf), "%ld", Expr.IVal);
SB_AppendStr (T, Buf); SB_AppendStr (T, Buf);
break; break;

View File

@@ -622,7 +622,7 @@ static SymEntry* ParseEnumDecl (const char* Name)
if (CurTok.Tok == TOK_ASSIGN) { if (CurTok.Tok == TOK_ASSIGN) {
NextToken (); NextToken ();
ExprDesc Expr = StaticConstAbsIntExpr (hie1); ExprDesc Expr = NoCodeConstAbsIntExpr (hie1);
EnumVal = Expr.IVal; EnumVal = Expr.IVal;
MemberType = Expr.Type; MemberType = Expr.Type;
IsSigned = IsSignSigned (MemberType); IsSigned = IsSignSigned (MemberType);
@@ -772,7 +772,7 @@ static int ParseFieldWidth (Declaration* Decl)
/* Read the width */ /* Read the width */
NextToken (); NextToken ();
ExprDesc Expr = StaticConstAbsIntExpr (hie1); ExprDesc Expr = NoCodeConstAbsIntExpr (hie1);
if (Expr.IVal < 0) { if (Expr.IVal < 0) {
Error ("Negative width in bit-field"); Error ("Negative width in bit-field");
@@ -1859,7 +1859,7 @@ static void Declarator (const DeclSpec* Spec, Declaration* D, declmode_t Mode)
/* Read the size if it is given */ /* Read the size if it is given */
if (CurTok.Tok != TOK_RBRACK) { if (CurTok.Tok != TOK_RBRACK) {
ExprDesc Expr = StaticConstAbsIntExpr (hie1); ExprDesc Expr = NoCodeConstAbsIntExpr (hie1);
if (Expr.IVal <= 0) { if (Expr.IVal <= 0) {
if (D->Ident[0] != '\0') { if (D->Ident[0] != '\0') {
Error ("Size of array '%s' is invalid", D->Ident); Error ("Size of array '%s' is invalid", D->Ident);
@@ -2220,7 +2220,7 @@ static ExprDesc ParseScalarInitInternal (Type* T)
} }
/* Get the expression and convert it to the target type */ /* Get the expression and convert it to the target type */
ExprDesc ED = StaticConstExpr (hie1); ExprDesc ED = NoCodeConstExpr (hie1);
TypeConversion (&ED, T); TypeConversion (&ED, T);
/* Close eventually opening braces */ /* Close eventually opening braces */
@@ -2253,7 +2253,7 @@ static unsigned ParsePointerInit (Type* T)
unsigned BraceCount = OpeningCurlyBraces (0); unsigned BraceCount = OpeningCurlyBraces (0);
/* Expression */ /* Expression */
ExprDesc ED = StaticConstExpr (hie1); ExprDesc ED = NoCodeConstExpr (hie1);
TypeConversion (&ED, T); TypeConversion (&ED, T);
/* Output the data */ /* Output the data */
@@ -2598,7 +2598,7 @@ static unsigned ParseVoidInit (Type* T)
/* Allow an arbitrary list of values */ /* Allow an arbitrary list of values */
Size = 0; Size = 0;
do { do {
ExprDesc Expr = StaticConstExpr (hie1); ExprDesc Expr = NoCodeConstExpr (hie1);
switch (GetUnderlyingTypeCode (&Expr.Type[0])) { switch (GetUnderlyingTypeCode (&Expr.Type[0])) {
case T_SCHAR: case T_SCHAR:

View File

@@ -3150,14 +3150,14 @@ static void hieAndPP (ExprDesc* Expr)
** called recursively from the preprocessor. ** called recursively from the preprocessor.
*/ */
{ {
*Expr = StaticConstAbsIntExpr (hie2); *Expr = NoCodeConstAbsIntExpr (hie2);
while (CurTok.Tok == TOK_BOOL_AND) { while (CurTok.Tok == TOK_BOOL_AND) {
/* Skip the && */ /* Skip the && */
NextToken (); NextToken ();
/* Get rhs */ /* Get rhs */
ExprDesc Expr2 = StaticConstAbsIntExpr (hie2); ExprDesc Expr2 = NoCodeConstAbsIntExpr (hie2);
/* Combine the two */ /* Combine the two */
Expr->IVal = (Expr->IVal && Expr2.IVal); Expr->IVal = (Expr->IVal && Expr2.IVal);
@@ -3171,14 +3171,14 @@ static void hieOrPP (ExprDesc *Expr)
** called recursively from the preprocessor. ** called recursively from the preprocessor.
*/ */
{ {
*Expr = StaticConstAbsIntExpr (hieAndPP); *Expr = NoCodeConstAbsIntExpr (hieAndPP);
while (CurTok.Tok == TOK_BOOL_OR) { while (CurTok.Tok == TOK_BOOL_OR) {
/* Skip the && */ /* Skip the && */
NextToken (); NextToken ();
/* Get rhs */ /* Get rhs */
ExprDesc Expr2 = StaticConstAbsIntExpr (hieAndPP); ExprDesc Expr2 = NoCodeConstAbsIntExpr (hieAndPP);
/* Combine the two */ /* Combine the two */
Expr->IVal = (Expr->IVal || Expr2.IVal); Expr->IVal = (Expr->IVal || Expr2.IVal);
@@ -4047,11 +4047,11 @@ void BoolExpr (void (*Func) (ExprDesc*), ExprDesc* Expr)
ExprDesc StaticConstExpr (void (*Func) (ExprDesc*)) ExprDesc NoCodeConstExpr (void (*Func) (ExprDesc*))
/* Will evaluate an expression via the given function. If the result is not a /* Get an expression evaluated via the given function. If the result is not a
** static constant expression, a diagnostic will be printed, and the value is ** constant expression without runtime code generated, a diagnostic will be
** replaced by a constant one to make sure there are no internal errors that ** printed, and the value is replaced by a constant one to make sure there are
** result from this input error. ** no internal errors that result from this input error.
*/ */
{ {
ExprDesc Expr; ExprDesc Expr;
@@ -4071,11 +4071,11 @@ ExprDesc StaticConstExpr (void (*Func) (ExprDesc*))
ExprDesc StaticConstAbsIntExpr (void (*Func) (ExprDesc*)) ExprDesc NoCodeConstAbsIntExpr (void (*Func) (ExprDesc*))
/* Will evaluate an expression via the given function. If the result is not a /* Get an expression evaluated via the given function. If the result is not a
** static constant numeric integer value, a diagnostic will be printed, and the ** constant numeric integer value without runtime code generated, a diagnostic
** value is replaced by a constant one to make sure there are no internal ** will be printed, and the value is replaced by a constant one to make sure
** errors that result from this input error. ** there are no internal errors that result from this input error.
*/ */
{ {
ExprDesc Expr; ExprDesc Expr;

View File

@@ -61,18 +61,18 @@ void BoolExpr (void (*Func) (ExprDesc*), ExprDesc* Expr);
** are no internal errors that result from this input error. ** are no internal errors that result from this input error.
*/ */
ExprDesc StaticConstExpr (void (*Func) (ExprDesc*)); ExprDesc NoCodeConstExpr (void (*Func) (ExprDesc*));
/* Get an expression evaluated via the given function. If the result is not a /* Get an expression evaluated via the given function. If the result is not a
** static constant expression, a diagnostic will be printed, and the value is ** constant expression without runtime code generated, a diagnostic will be
** replaced by a constant one to make sure there are no internal errors that ** printed, and the value is replaced by a constant one to make sure there are
** result from this input error. ** no internal errors that result from this input error.
*/ */
ExprDesc StaticConstAbsIntExpr (void (*Func) (ExprDesc*)); ExprDesc NoCodeConstAbsIntExpr (void (*Func) (ExprDesc*));
/* Get an expression evaluate via the given function. If the result is not a /* Get an expression evaluated via the given function. If the result is not a
** static constant numeric integer value, a diagnostic will be printed, and the ** constant numeric integer value without runtime code generated, a diagnostic
** value is replaced by a constant one to make sure there are no internal ** will be printed, and the value is replaced by a constant one to make sure
** errors that result from this input error. ** there are no internal errors that result from this input error.
*/ */
void hie10 (ExprDesc* lval); void hie10 (ExprDesc* lval);

View File

@@ -1076,7 +1076,7 @@ static int DoIf (int Skip)
NextToken (); NextToken ();
/* Call the expression parser */ /* Call the expression parser */
ExprDesc Expr = StaticConstExpr (hie1); ExprDesc Expr = NoCodeConstExpr (hie1);
/* End preprocessing mode */ /* End preprocessing mode */
Preprocessing = 0; Preprocessing = 0;

View File

@@ -44,7 +44,7 @@
/* Set when the preprocessor calls StaticConstExpr() recursively */ /* Set when the preprocessor calls NoCodeConstExpr() recursively */
extern unsigned char Preprocessing; extern unsigned char Preprocessing;

View File

@@ -65,7 +65,7 @@ void ParseStaticAssert ()
} }
/* Parse assertion condition */ /* Parse assertion condition */
Expr = StaticConstAbsIntExpr (hie1); Expr = NoCodeConstAbsIntExpr (hie1);
failed = !Expr.IVal; failed = !Expr.IVal;
/* If there is a comma, we also have an error message. The message is optional because we /* If there is a comma, we also have an error message. The message is optional because we

View File

@@ -216,7 +216,7 @@ void CaseLabel (void)
NextToken (); NextToken ();
/* Read the selector expression */ /* Read the selector expression */
CaseExpr = StaticConstAbsIntExpr (hie1); CaseExpr = NoCodeConstAbsIntExpr (hie1);
Val = CaseExpr.IVal; Val = CaseExpr.IVal;
/* Now check if we're inside a switch statement */ /* Now check if we're inside a switch statement */