- added automatic type deduction capabilities for local variables. If you type 'let variable = value;' the type of 'variable' will be deduced from the given value. This is mostly of interest for type casting pointers, because 'let p = Classtype(objectvar);' does not require writing the class type name twice.
This commit is contained in:
parent
67bdac5227
commit
f722967abe
10 changed files with 42 additions and 3 deletions
|
|
@ -704,6 +704,7 @@ type_name1(X) ::= NAME(T). { X.Int = ZCC_Name; X.SourceLoc = T.SourceLoc; }
|
|||
type_name1(X) ::= SOUND(T). { X.Int = ZCC_Sound; X.SourceLoc = T.SourceLoc; }
|
||||
type_name1(X) ::= STATE(T). { X.Int = ZCC_State; X.SourceLoc = T.SourceLoc; }
|
||||
type_name1(X) ::= COLOR(T). { X.Int = ZCC_Color; X.SourceLoc = T.SourceLoc; }
|
||||
type_name1(X) ::= LET(T). { X.Int = ZCC_Let; X.SourceLoc = T.SourceLoc; }
|
||||
|
||||
type_name(X) ::= type_name1(A).
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1449,6 +1449,10 @@ PType *ZCCCompiler::DetermineType(PType *outertype, ZCC_TreeNode *field, FName n
|
|||
retval = TypeSound;
|
||||
break;
|
||||
|
||||
case ZCC_Let:
|
||||
retval = TypeAuto;
|
||||
break;
|
||||
|
||||
case ZCC_UserType:
|
||||
// statelabel et.al. are not tokens - there really is no need to, it works just as well as an identifier. Maybe the same should be done for some other types, too?
|
||||
switch (btype->UserType->Id)
|
||||
|
|
|
|||
|
|
@ -201,6 +201,7 @@ static void InitTokenMap()
|
|||
TOKENDEF2(TK_State, ZCC_STATE, NAME_State);
|
||||
TOKENDEF2(TK_Color, ZCC_COLOR, NAME_Color);
|
||||
TOKENDEF2(TK_Sound, ZCC_SOUND, NAME_Sound);
|
||||
TOKENDEF2(TK_Let, ZCC_LET, NAME_let);
|
||||
|
||||
TOKENDEF (TK_Identifier, ZCC_IDENTIFIER);
|
||||
TOKENDEF (TK_StringConst, ZCC_STRCONST);
|
||||
|
|
|
|||
|
|
@ -131,6 +131,7 @@ enum EZCCBuiltinType
|
|||
ZCC_Sound,
|
||||
|
||||
ZCC_UserType,
|
||||
ZCC_Let,
|
||||
|
||||
ZCC_NUM_BUILT_IN_TYPES
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue