mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-12-15 15:11:32 +00:00
Add TRUE and FALSE terminals to the zcc grammar
- I can't believe I completely forgot to let the parser handle true and false literals. - Consolidate all the %include blocks in zcc-parse.lemon into a single one, because Lemon all of a sudden decided it didn't like me having more than one in the grammar file. - Added a PBool type to represent boolean values with.
This commit is contained in:
parent
1948642758
commit
a0dbcb5d5b
3 changed files with 44 additions and 24 deletions
src
|
@ -66,6 +66,7 @@ PVoidType *TypeVoid;
|
|||
PInt *TypeSInt8, *TypeUInt8;
|
||||
PInt *TypeSInt16, *TypeUInt16;
|
||||
PInt *TypeSInt32, *TypeUInt32;
|
||||
PBool *TypeBool;
|
||||
PFloat *TypeFloat32, *TypeFloat64;
|
||||
PString *TypeString;
|
||||
PName *TypeName;
|
||||
|
@ -307,6 +308,7 @@ void PType::StaticInit()
|
|||
RUNTIME_CLASS(PErrorType)->TypeTableType = RUNTIME_CLASS(PErrorType);
|
||||
RUNTIME_CLASS(PVoidType)->TypeTableType = RUNTIME_CLASS(PVoidType);
|
||||
RUNTIME_CLASS(PInt)->TypeTableType = RUNTIME_CLASS(PInt);
|
||||
RUNTIME_CLASS(PBool)->TypeTableType = RUNTIME_CLASS(PBool);
|
||||
RUNTIME_CLASS(PFloat)->TypeTableType = RUNTIME_CLASS(PFloat);
|
||||
RUNTIME_CLASS(PString)->TypeTableType = RUNTIME_CLASS(PString);
|
||||
RUNTIME_CLASS(PName)->TypeTableType = RUNTIME_CLASS(PName);
|
||||
|
@ -334,6 +336,7 @@ void PType::StaticInit()
|
|||
TypeTable.AddType(TypeUInt16 = new PInt(2, true));
|
||||
TypeTable.AddType(TypeSInt32 = new PInt(4, false));
|
||||
TypeTable.AddType(TypeUInt32 = new PInt(4, true));
|
||||
TypeTable.AddType(TypeBool = new PBool);
|
||||
TypeTable.AddType(TypeFloat32 = new PFloat(4));
|
||||
TypeTable.AddType(TypeFloat64 = new PFloat(8));
|
||||
TypeTable.AddType(TypeString = new PString);
|
||||
|
@ -561,6 +564,10 @@ int PInt::GetRegType() const
|
|||
return REGT_INT;
|
||||
}
|
||||
|
||||
/* PBool ******************************************************************/
|
||||
|
||||
IMPLEMENT_CLASS(PBool)
|
||||
|
||||
/* PFloat *****************************************************************/
|
||||
|
||||
IMPLEMENT_CLASS(PFloat)
|
||||
|
|
|
@ -230,6 +230,13 @@ protected:
|
|||
PInt();
|
||||
};
|
||||
|
||||
class PBool : public PInt
|
||||
{
|
||||
DECLARE_CLASS(PBool, PInt);
|
||||
public:
|
||||
PBool() : PInt(sizeof(bool), true) {}
|
||||
};
|
||||
|
||||
class PFloat : public PBasicType
|
||||
{
|
||||
DECLARE_CLASS(PFloat, PBasicType);
|
||||
|
@ -643,6 +650,7 @@ extern PVoidType *TypeVoid;
|
|||
extern PInt *TypeSInt8, *TypeUInt8;
|
||||
extern PInt *TypeSInt16, *TypeUInt16;
|
||||
extern PInt *TypeSInt32, *TypeUInt32;
|
||||
extern PBool *TypeBool;
|
||||
extern PFloat *TypeFloat32, *TypeFloat64;
|
||||
extern PString *TypeString;
|
||||
extern PName *TypeName;
|
||||
|
|
|
@ -43,6 +43,25 @@ static void SetNodeLine(ZCC_TreeNode *name, int line)
|
|||
name->Type = type; \
|
||||
name->IntVal = val
|
||||
|
||||
struct ClassFlagsBlock {
|
||||
VM_UWORD Flags;
|
||||
ZCC_Identifier *Replaces;
|
||||
};
|
||||
|
||||
struct StateOpts {
|
||||
ZCC_Expression *Offset;
|
||||
bool Bright;
|
||||
};
|
||||
|
||||
struct VarOrFun
|
||||
{
|
||||
ZCC_VarName *VarNames;
|
||||
ZCC_FuncParamDecl *FuncParams;
|
||||
ZCC_CompoundStmt *FuncBody;
|
||||
ENamedName FuncName;
|
||||
int FuncFlags;
|
||||
int SourceLoc;
|
||||
};
|
||||
}
|
||||
|
||||
%token_prefix ZCC_
|
||||
|
@ -164,12 +183,6 @@ class_ancestry(X) ::= . { X = NULL; }
|
|||
class_ancestry(X) ::= COLON dottable_id(A). { X = A; }
|
||||
|
||||
%type class_flags{ClassFlagsBlock}
|
||||
%include {
|
||||
struct ClassFlagsBlock {
|
||||
VM_UWORD Flags;
|
||||
ZCC_Identifier *Replaces;
|
||||
};
|
||||
}
|
||||
class_flags(X) ::= . { X.Flags = 0; X.Replaces = NULL; }
|
||||
class_flags(X) ::= class_flags(A) ABSTRACT. { X.Flags = A.Flags | 0/*FIXME*/; X.Replaces = A.Replaces; }
|
||||
class_flags(X) ::= class_flags(A) NATIVE. { X.Flags = A.Flags | 0/*FIXME*/; X.Replaces = A.Replaces; }
|
||||
|
@ -369,12 +382,6 @@ enumerator(X) ::= IDENTIFIER(A) EQ expr(B). /* Expression must be constant. */
|
|||
%type state_call {ZCC_ExprFuncCall *}
|
||||
%type state_call_params {ZCC_FuncParm *}
|
||||
|
||||
%include {
|
||||
struct StateOpts {
|
||||
ZCC_Expression *Offset;
|
||||
bool Bright;
|
||||
};
|
||||
}
|
||||
%type state_opts {StateOpts}
|
||||
|
||||
states_def(X) ::= STATES(T) scanner_mode LBRACE states_body(A) RBRACE.
|
||||
|
@ -618,18 +625,6 @@ array_size(X) ::= array_size(A) array_size_expr(B).
|
|||
X = A;
|
||||
}
|
||||
|
||||
%include
|
||||
{
|
||||
struct VarOrFun
|
||||
{
|
||||
ZCC_VarName *VarNames;
|
||||
ZCC_FuncParamDecl *FuncParams;
|
||||
ZCC_CompoundStmt *FuncBody;
|
||||
ENamedName FuncName;
|
||||
int FuncFlags;
|
||||
int SourceLoc;
|
||||
};
|
||||
}
|
||||
%type variables_or_function {VarOrFun}
|
||||
|
||||
/* Multiple type names are only valid for functions. */
|
||||
|
@ -1232,6 +1227,16 @@ constant(X) ::= NAMECONST(A).
|
|||
floatconst->IntVal = A.Int;
|
||||
X = floatconst;
|
||||
}
|
||||
constant(X) ::= FALSE(A).
|
||||
{
|
||||
NEW_INTCONST_NODE(boolconst, TypeBool, false, A);
|
||||
X = boolconst;
|
||||
}
|
||||
constant(X) ::= TRUE(A).
|
||||
{
|
||||
NEW_INTCONST_NODE(boolconst, TypeBool, true, A);
|
||||
X = boolconst;
|
||||
}
|
||||
|
||||
/************ Statements ************/
|
||||
|
||||
|
|
Loading…
Reference in a new issue