#include "nexttok.h"
#include "objfile.h"
#include "segment.h"
+#include "struct.h"
#include "symbol.h"
#include "symtab.h"
#include "toklist.h"
-static int FuncBlank (void)
+static ExprNode* FuncBlank (void)
/* Handle the .BLANK builtin function */
{
+ int Result = 1;
+
/* Assume no tokens if the closing brace follows (this is not correct in
* all cases, since the token may be the closing brace, but this will
* give a syntax error anyway and may not be handled by .BLANK.
*/
- if (Tok == TOK_RPAREN) {
- /* No tokens */
- return 1;
- } else {
+ if (Tok != TOK_RPAREN) {
/* Skip any tokens */
int Braces = 0;
while (!TokIsSep (Tok)) {
}
return 0;
}
+ return GenLiteralExpr (Result);
}
-static int FuncConst (void)
+static ExprNode* FuncConst (void)
/* Handle the .CONST builtin function */
{
/* Read an expression */
ExprNode* Expr = Expression ();
/* Check the constness of the expression */
- int Result = IsConstExpr (Expr, 0);
+ ExprNode* Result = GenLiteralExpr (IsConstExpr (Expr, 0));
/* Free the expression */
FreeExpr (Expr);
/* Done */
return Result;
-}
+}
-static int FuncDefined (void)
+static ExprNode* FuncDefined (void)
/* Handle the .DEFINED builtin function */
{
/* Parse the symbol name and search for the symbol */
SymEntry* Sym = ParseScopedSymName (SYM_FIND_EXISTING);
/* Check if the symbol is defined */
- return (Sym != 0 && SymIsDef (Sym));
+ return GenLiteralExpr (Sym != 0 && SymIsDef (Sym));
}
-static int DoMatch (enum TC EqualityLevel)
+static ExprNode* DoMatch (enum TC EqualityLevel)
/* Handle the .MATCH and .XMATCH builtin functions */
{
int Result;
return 0;
}
- /* Compare the tokens if the result is not already known */
+ /* Compare the tokens if the result is not already known */
if (Result != 0) {
if (Node == 0) {
/* The second list is larger than the first one */
}
/* Done, return the result */
- return Result;
+ return GenLiteralExpr (Result);
}
-static int FuncMatch (void)
+static ExprNode* FuncMatch (void)
/* Handle the .MATCH function */
{
return DoMatch (tcSameToken);
-static int FuncReferenced (void)
+static ExprNode* FuncReferenced (void)
/* Handle the .REFERENCED builtin function */
{
/* Parse the symbol name and search for the symbol */
SymEntry* Sym = ParseScopedSymName (SYM_FIND_EXISTING);
/* Check if the symbol is referenced */
- return (Sym != 0 && SymIsRef (Sym));
+ return GenLiteralExpr (Sym != 0 && SymIsRef (Sym));
+}
+
+
+
+static ExprNode* FuncSizeOf (void)
+/* Handle the .SIZEOF function */
+{
+ long Size;
+
+ /* Get the struct for the scoped struct name */
+ SymTable* Struct = ParseScopedSymTable (SYM_FIND_EXISTING);
+
+ /* Check if the given symbol is really a struct */
+ if (GetSymTabType (Struct) != ST_STRUCT) {
+ Error ("Argument to .SIZEOF is not a struct");
+ Size = 1;
+ } else {
+ Size = GetStructSize (Struct);
+ }
+
+ /* Return the size */
+ return GenLiteralExpr (Size);
}
-static int FuncStrAt (void)
+static ExprNode* FuncStrAt (void)
/* Handle the .STRAT function */
{
char Str [sizeof(SVal)];
long Index;
+ unsigned char C;
/* String constant expected */
if (Tok != TOK_STRCON) {
return 0;
}
- /* Return the char, handle as unsigned. Be sure to translate it into
+ /* Get the char, handle as unsigned. Be sure to translate it into
* the target character set.
*/
- return (unsigned char) TgtTranslateChar (Str [(size_t)Index]);
+ C = TgtTranslateChar (Str [(size_t)Index]);
+
+ /* Return the char expression */
+ return GenLiteralExpr (C);
}
-static int FuncStrLen (void)
+static ExprNode* FuncStrLen (void)
/* Handle the .STRLEN function */
{
+ int Len;
+
/* String constant expected */
if (Tok != TOK_STRCON) {
if (Tok != TOK_RPAREN) {
NextTok ();
}
- return 0;
+ Len = 0;
} else {
/* Get the length of the string */
- int Len = strlen (SVal);
+ Len = strlen (SVal);
/* Skip the string */
NextTok ();
-
- /* Return the length */
- return Len;
-
}
+
+ /* Return the length */
+ return GenLiteralExpr (Len);
}
-static int FuncTCount (void)
+static ExprNode* FuncTCount (void)
/* Handle the .TCOUNT function */
{
/* We have a list of tokens that ends with the closing paren. Skip
}
/* Return the number of tokens */
- return Count;
+ return GenLiteralExpr (Count);
}
-static int FuncXMatch (void)
+static ExprNode* FuncXMatch (void)
/* Handle the .XMATCH function */
{
return DoMatch (tcIdentical);
-static ExprNode* Function (int (*F) (void))
+static ExprNode* Function (ExprNode* (*F) (void))
/* Handle builtin functions */
{
- long Result;
+ ExprNode* E;
/* Skip the keyword */
NextTok ();
NextTok ();
/* Call the function itself */
- Result = F ();
+ E = F ();
/* Closing brace must follow */
ConsumeRParen ();
- /* Return an expression node with the boolean code */
- return GenLiteralExpr (Result);
+ /* Return the result of the actual function */
+ return E;
}
N = Function (FuncReferenced);
break;
+ case TOK_SIZEOF:
+ N = Function (FuncSizeOf);
+ break;
+
case TOK_STRAT:
N = Function (FuncStrAt);
break;