/* common */
#include "check.h"
-#include "print.h"
+#include "debugflag.h"
#include "shift.h"
#include "xmalloc.h"
{
ED->Flags = ED_OK;
ED->AddrSize = ADDR_SIZE_DEFAULT;
- ED->Val = 0;
+ ED->Val = 0;
ED->SymCount = 0;
ED->SymLimit = 0;
ED->SymRef = 0;
static int ED_IsValid (const ExprDesc* D)
-/* Return true if the expression is valid, that is, the TOO_COMPLEX flag is
- * not set
+/* Return true if the expression is valid, that is, neither the ERROR nor the
+ * TOO_COMPLEX flags are set.
*/
{
- return ((D->Flags & ED_TOO_COMPLEX) == 0);
+ return ((D->Flags & (ED_ERROR | ED_TOO_COMPLEX)) == 0);
+}
+
+
+
+static int ED_HasError (const ExprDesc* D)
+/* Return true if the expression has an error. */
+{
+ return ((D->Flags & ED_ERROR) != 0);
}
+static void ED_SetError (ExprDesc* D)
+/* Set the TOO_COMPLEX and ERROR flags for D */
+{
+ D->Flags |= (ED_ERROR | ED_TOO_COMPLEX);
+}
+
+
+
static void ED_UpdateAddrSize (ExprDesc* ED, unsigned char AddrSize)
/* Update the address size of the expression */
{
/*****************************************************************************/
-/* Code */
+/* Code */
/*****************************************************************************/
if (SymHasExpr (Sym)) {
if (SymHasUserMark (Sym)) {
- if (Verbosity > 0) {
- DumpExpr (Expr, SymResolve);
- }
LIError (&Sym->DefLines,
"Circular reference in definition of symbol `%m%p'",
GetSymName (Sym));
- ED_Invalidate (D);
+ ED_SetError (D);
} else {
unsigned char AddrSize;
StudyExprInternal (GetSymExpr (Sym), D);
SymUnmarkUser (Sym);
+ /* If requested and if the expression is valid, dump it */
+ if (Debug > 0 && !ED_HasError (D)) {
+ DumpExpr (Expr, SymResolve);
+ }
+
/* If the symbol has an explicit address size, use it. This may
* lead to range errors later (maybe even in the linker stage), if
* the user lied about the address size, but for now we trust him.
if (ED_IsValid (D)) {
if (D->Right == 0) {
Error ("Division by zero");
- ED_Invalidate (D);
+ ED_SetError (D);
} else {
D->Val /= D->Right;
}
if (ED_IsValid (D)) {
if (D->Right == 0) {
Error ("Modulo operation with zero");
- ED_Invalidate (D);
+ ED_SetError (D);
} else {
D->Val %= D->Right;
}
/* Study this expression node */
switch (Expr->Op) {
- case EXPR_LITERAL:
+ case EXPR_LITERAL:
StudyLiteral (Expr, D);
- break;
+ break;
- case EXPR_SYMBOL:
+ case EXPR_SYMBOL:
StudySymbol (Expr, D);
break;
- case EXPR_SECTION:
+ case EXPR_SECTION:
StudySection (Expr, D);
- break;
+ break;
- case EXPR_ULABEL:
+ case EXPR_ULABEL:
StudyULabel (Expr, D);
break;
- case EXPR_PLUS:
+ case EXPR_PLUS:
StudyPlus (Expr, D);
- break;
+ break;
- case EXPR_MINUS:
- StudyMinus (Expr, D);
- break;
+ case EXPR_MINUS:
+ StudyMinus (Expr, D);
+ break;
case EXPR_MUL:
StudyMul (Expr, D);
break;
default:
- Internal ("Unknown Op type: %u", Expr->Op);
- break;
+ Internal ("Unknown Op type: %u", Expr->Op);
+ break;
}
}
printf ("%u sections:\n", D->SecCount);
#endif
}
-
-
-