X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-psi;a=blobdiff_plain;f=src%2Fparser_proc.y;h=99054b671fc61223fa5f101c5fa54c538f13ba2c;hp=f3a51f46ef3c319b5875304872c7f972f33b7d8a;hb=ea0162a1698563a49de50456cd3f2cc18b83a05e;hpb=61918592ab618c073b9846783ce79fed9f26c5f7 diff --git a/src/parser_proc.y b/src/parser_proc.y index f3a51f4..99054b6 100644 --- a/src/parser_proc.y +++ b/src/parser_proc.y @@ -15,7 +15,11 @@ %extra_argument {PSI_Parser *P} /* TOKEN is defined inside syntax_error */ %syntax_error { - PSI_ParserSyntaxError(P, P->psi.file.fn, P->line, "Unexpected token '%s'", TOKEN->text); + if (TOKEN) { + PSI_ParserSyntaxError(P, P->psi.file.fn, P->line, "Unexpected token '%s'", TOKEN->text); + } else { + PSI_ParserSyntaxError(P, P->psi.file.fn, P->line, "Unexpected end of input"); + } } %nonassoc NAME. @@ -92,6 +96,12 @@ decl_typedef(def) ::= TYPEDEF decl_type(type) NAME(ALIAS) EOS. { def = init_decl_typedef(ALIAS->text, type); free(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)); + free(V); + free(ALIAS); +} decl_typedef(def) ::= TYPEDEF STRUCT(S) NAME(N) NAME(ALIAS) EOS. { def = init_decl_typedef(ALIAS->text, init_decl_type(S->type, N->text)); free(ALIAS); @@ -155,8 +165,8 @@ decl_vars(vars) ::= decl_vars(vars_) COMMA decl_var(var). { %type decl_arg {decl_arg*} %destructor decl_arg {free_decl_arg($$);} -decl_arg(arg_) ::= decl_type(type) decl_var(var). { - arg_ = var->arg = init_decl_arg(type, var); +decl_arg(arg_) ::= const_decl_type(type) decl_var(var). { + arg_ = init_decl_arg(type, var); } /* void pointers need a specific rule */ decl_arg(arg_) ::= VOID(T) pointers(p) NAME(N). { @@ -164,7 +174,14 @@ decl_arg(arg_) ::= VOID(T) pointers(p) NAME(N). { init_decl_type(T->type, T->text), init_decl_var(N->text, p, 0) ); - arg_->var->arg = arg_; + free(T); + free(N); +} +decl_arg(arg_) ::= CONST VOID(T) pointers(p) NAME(N). { + arg_ = init_decl_arg( + init_decl_type(T->type, T->text), + init_decl_var(N->text, p, 0) + ); free(T); free(N); } @@ -212,6 +229,15 @@ decl_type(type_) ::= decl_type_token(T). { type_ = init_decl_type(T->type, T->text); free(T); } +/* unsigned, urgh */ +decl_type(type_) ::= UNSIGNED NAME(T). { + type_ = init_decl_type(T->type, T->text); + type_->name = realloc(type_->name, T->size + sizeof("unsigned")); + memmove(type_->name + sizeof("unsigned"), type_->name, T->size); + memcpy(type_->name, "unsigned", sizeof("unsigned")-1); + type_->name[sizeof("unsigned")] = ' '; + type_->name[T->size + sizeof("unsigned")] = 0; +} /* we have to support plain int here because we have it in our lexer rules */ decl_type(type_) ::= INT(T). { type_ = init_decl_type(PSI_T_NAME, T->text); @@ -224,6 +250,15 @@ decl_type(type_) ::= STRUCT(S) NAME(T). { free(T); } +%type const_decl_type {decl_type*} +%destructor const_decl_type {free_decl_type($$);} +const_decl_type(type) ::= decl_type(type_). { + type = type_; +} +const_decl_type(type) ::= CONST decl_type(type_). { + type = type_; +} + %type impl {impl*} %destructor impl {free_impl($$);} impl(impl) ::= impl_func(func) LBRACE impl_stmts(stmts) RBRACE. {