X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-psi;a=blobdiff_plain;f=src%2Fparser_proc.y;h=b4150ae6b5ee82b4331a3729aed13a4f235bc88c;hp=d82a90f6f9d2986a03d4e161d1e962544f34f234;hb=772c1e688a51b32331fae7993429b3a03d766d8d;hpb=5abcb8724ac7046d62203ea643e9ce69f63a6a8a diff --git a/src/parser_proc.y b/src/parser_proc.y index d82a90f..b4150ae 100644 --- a/src/parser_proc.y +++ b/src/parser_proc.y @@ -28,7 +28,7 @@ void psi_error(int, const char *, int, const char *, ...); %nonassoc NAME. %left PLUS MINUS. %left SLASH ASTERISK. -%fallback NAME TEMP FREE SET LET RETURN LIB INT LONG SIGNED UNSIGNED. +%fallback NAME TEMP FREE SET LET RETURN LIB CHAR SHORT INT LONG SIGNED UNSIGNED. file ::= blocks. @@ -104,8 +104,8 @@ decl_typedef(def) ::= TYPEDEF decl_type(type) NAME(ALIAS) EOS. { def->token = ALIAS; } /* support opaque types */ -decl_typedef(def) ::= TYPEDEF VOID(V) NAME(ALIAS) EOS. { - def = init_decl_typedef(ALIAS->text, init_decl_type(V->type, V->text)); +decl_typedef(def) ::= TYPEDEF VOID(V) indirection(i) NAME(ALIAS) EOS. { + def = init_decl_typedef(ALIAS->text, init_decl_type(i?PSI_T_POINTER:V->type, V->text)); def->token = ALIAS; def->type->token = V; } @@ -237,38 +237,47 @@ struct_layout(layout) ::= COLON COLON LPAREN NUMBER(POS) COMMA NUMBER(SIZ) RPARE free(SIZ); } -%token_class decl_type_token FLOAT DOUBLE INT8 UINT8 INT16 UINT16 INT32 UINT32 INT64 UINT64 NAME. -%type decl_type {decl_type*} -%destructor decl_type {free_decl_type($$);} -decl_type(type_) ::= decl_type_token(T). { - type_ = init_decl_type(T->type, T->text); - type_->token = T; +/* un/signed, urgh */ +decl_scalar_type(type_) ::= CHAR(C). { + type_ = C; +} +decl_scalar_type(type_) ::= SHORT(S) INT(I). { + type_ = PSI_TokenCat(2, S, I); + free(S); + free(I); } -/* unsigned, urgh */ -decl_type(type_) ::= UNSIGNED(U) NAME(N). { +decl_scalar_type(type_) ::= SHORT(S). { + type_ = S; +} +decl_scalar_type(type_) ::= LONG(L) INT(I). { + type_ = PSI_TokenCat(2, L, I); + free(L); + free(I); +} +decl_scalar_type(type_) ::= LONG(L1) LONG(L2) INT(I). { + type_ = PSI_TokenCat(3, L1, L2, I); + free(L1); + free(L2); + free(I); +} +decl_scalar_type(type_) ::= LONG(L1) LONG(L2). { + type_ = PSI_TokenCat(2, L1, L2); + free(L1); + free(L2); +} +decl_type(type_) ::= UNSIGNED(U) decl_scalar_type(N). { PSI_Token *T = PSI_TokenCat(2, U, N); type_ = init_decl_type(T->type, T->text); type_->token = T; free(U); free(N); } -decl_type(type_) ::= SIGNED NAME(T). { +decl_type(type_) ::= SIGNED(S) decl_scalar_type(N). { + PSI_Token *T = PSI_TokenCat(2, S, N); type_ = init_decl_type(T->type, T->text); type_->token = T; - type_->name = realloc(type_->name, T->size + sizeof("signed")); - memmove(type_->name + sizeof("signed"), type_->name, T->size); - memcpy(type_->name, "signed", sizeof("signed")-1); - type_->name[sizeof("signed")] = ' '; - type_->name[T->size + sizeof("signed")] = 0; -} -/* we have to support plain int, long here because we have it in our lexer rules */ -decl_type(type_) ::= INT(T). { - type_ = init_decl_type(PSI_T_NAME, T->text); - type_->token = T; -} -decl_type(type_) ::= LONG INT(T). { - type_ = init_decl_type(PSI_T_NAME, T->text); - type_->token = T; + free(S); + free(N); } /* structs ! */ decl_type(type_) ::= STRUCT(S) NAME(T). { @@ -276,6 +285,21 @@ decl_type(type_) ::= STRUCT(S) NAME(T). { type_->token = T; free(S); } +decl_type(type_) ::= LONG(L) DOUBLE(D). { + PSI_Token *T = PSI_TokenCat(2, L, D); + type_ = init_decl_type(T->type, T->text); + type_->token = T; + free(L); + free(D); +} +%token_class decl_type_token FLOAT DOUBLE INT8 UINT8 INT16 UINT16 INT32 UINT32 INT64 UINT64 NAME. +%type decl_type {decl_type*} +%destructor decl_type {free_decl_type($$);} +decl_type(type_) ::= decl_type_token(T). { + type_ = init_decl_type(T->type, T->text); + type_->token = T; +} + %type const_decl_type {decl_type*} %destructor const_decl_type {free_decl_type($$);}