From: Rémi Bernon rbernon@codeweavers.com
--- tools/widl/parser.l | 57 ++++++++++++++++++++++++++------------------- tools/widl/parser.y | 31 +++--------------------- tools/widl/utils.h | 3 --- 3 files changed, 36 insertions(+), 55 deletions(-)
diff --git a/tools/widl/parser.l b/tools/widl/parser.l index a1be68d8bd9..ce4335b5985 100644 --- a/tools/widl/parser.l +++ b/tools/widl/parser.l @@ -26,13 +26,13 @@
nl \r?\n ws [ \f\t\r] +hd [0-9a-fA-F] cident [a-zA-Z_][0-9a-zA-Z_]* u_suffix (u|U) l_suffix (l|L) int [0-9]+({l_suffix}?{u_suffix}?|{u_suffix}?{l_suffix}?)? -hexd [0-9a-fA-F] -hex 0(x|X){hexd}+({l_suffix}?{u_suffix}?|{u_suffix}?{l_suffix}?)? -uuid {hexd}{8}-{hexd}{4}-{hexd}{4}-{hexd}{4}-{hexd}{12} +hex 0(x|X){hd}+({l_suffix}?{u_suffix}?|{u_suffix}?{l_suffix}?)? +uuid {hd}{8}-{hd}{4}-{hd}{4}-{hd}{4}-{hd}{12} double [0-9]+.[0-9]+([eE][+-]?[0-9]+)*
%x ATTR @@ -101,24 +101,36 @@ static unsigned int xstrtoul(const char *nptr, char **endptr, int base) return val; }
-struct uuid *parse_uuid(const char *u) +static int token_uuid( const char *str, YYSTYPE *yylval ) { - struct uuid* uuid = xmalloc(sizeof(*uuid)); - char b[3]; - /* it would be nice to use UuidFromStringA */ - uuid->Data1 = strtoul(u, NULL, 16); - uuid->Data2 = strtoul(u+9, NULL, 16); - uuid->Data3 = strtoul(u+14, NULL, 16); - b[2] = 0; - memcpy(b, u+19, 2); uuid->Data4[0] = strtoul(b, NULL, 16); - memcpy(b, u+21, 2); uuid->Data4[1] = strtoul(b, NULL, 16); - memcpy(b, u+24, 2); uuid->Data4[2] = strtoul(b, NULL, 16); - memcpy(b, u+26, 2); uuid->Data4[3] = strtoul(b, NULL, 16); - memcpy(b, u+28, 2); uuid->Data4[4] = strtoul(b, NULL, 16); - memcpy(b, u+30, 2); uuid->Data4[5] = strtoul(b, NULL, 16); - memcpy(b, u+32, 2); uuid->Data4[6] = strtoul(b, NULL, 16); - memcpy(b, u+34, 2); uuid->Data4[7] = strtoul(b, NULL, 16); - return uuid; + struct uuid *uuid; + char tmp[3] = {0}; + + if (*str == '"') str++; + + uuid = xmalloc( sizeof(*uuid) ); + uuid->Data1 = strtoul( str , NULL, 16 ); + uuid->Data2 = strtoul( str + 9, NULL, 16 ); + uuid->Data3 = strtoul( str + 14, NULL, 16 ); + memcpy( tmp, str + 19, 2 ); + uuid->Data4[0] = strtoul( tmp, NULL, 16 ); + memcpy( tmp, str + 21, 2 ); + uuid->Data4[1] = strtoul( tmp, NULL, 16 ); + memcpy( tmp, str + 24, 2 ); + uuid->Data4[2] = strtoul( tmp, NULL, 16 ); + memcpy( tmp, str + 26, 2 ); + uuid->Data4[3] = strtoul( tmp, NULL, 16 ); + memcpy( tmp, str + 28, 2 ); + uuid->Data4[4] = strtoul( tmp, NULL, 16 ); + memcpy( tmp, str + 30, 2 ); + uuid->Data4[5] = strtoul( tmp, NULL, 16 ); + memcpy( tmp, str + 32, 2 ); + uuid->Data4[6] = strtoul( tmp, NULL, 16 ); + memcpy( tmp, str + 34, 2 ); + uuid->Data4[7] = strtoul( tmp, NULL, 16 ); + + yylval->uuid = uuid; + return aUUID; }
static int token_str( int token, const char *str, YYSTYPE *yylval ) @@ -196,11 +208,8 @@ static int token_num( int token, const char *yytext, YYSTYPE *yylval ) <ATTR>{ ] { yy_pop_state(); return ']'; }
+ ({uuid}|"{uuid}") { return token_uuid( yytext, yylval ); } {cident} { return attr_token( yytext, yylval ); } - {uuid} { - yylval->uuid = parse_uuid( yytext ); - return aUUID; - } }
<INITIAL>{ diff --git a/tools/widl/parser.y b/tools/widl/parser.y index 031e5482792..a48a8ca54f3 100644 --- a/tools/widl/parser.y +++ b/tools/widl/parser.y @@ -330,7 +330,6 @@ int parser_lex( PARSER_STYPE *yylval ); %type <num> pointer_type threading_type marshaling_behavior version %type <str> libraryhdr callconv cppquote importlib import %type <str> typename m_typename -%type <uuid> uuid_string %type <str> import_start %type <typelib> library_start librarydef %type <statement> statement typedef pragma_warning @@ -630,7 +629,7 @@ attribute | tCONTRACT '(' contract_req ')' { $$ = make_attrp(ATTR_CONTRACT, $3); } | tCONTRACTVERSION '(' contract_ver ')' { $$ = make_attrv(ATTR_CONTRACTVERSION, $3); } | tCONTROL { $$ = make_attr(ATTR_CONTROL); } - | tCUSTOM '(' uuid_string ',' expr_const ')' { $$ = make_custom_attr($3, $5); } + | tCUSTOM '(' aUUID ',' expr_const ')' { $$ = make_custom_attr($3, $5); } | tDECODE { $$ = make_attr(ATTR_DECODE); } | tDEFAULT { $$ = make_attr(ATTR_DEFAULT); } | tDEFAULTBIND { $$ = make_attr(ATTR_DEFAULTBIND); } @@ -720,8 +719,8 @@ attribute | tUIDEFAULT { $$ = make_attr(ATTR_UIDEFAULT); } | tUSESGETLASTERROR { $$ = make_attr(ATTR_USESGETLASTERROR); } | tUSERMARSHAL '(' type ')' { $$ = make_attrp(ATTR_USERMARSHAL, $3); } - | tUUID '(' uuid_string ')' { $$ = make_attrp(ATTR_UUID, $3); } - | tASYNCUUID '(' uuid_string ')' { $$ = make_attrp(ATTR_ASYNCUUID, $3); } + | tUUID '(' aUUID ')' { $$ = make_attrp(ATTR_UUID, $3); } + | tASYNCUUID '(' aUUID ')' { $$ = make_attrp(ATTR_ASYNCUUID, $3); } | tV1ENUM { $$ = make_attr(ATTR_V1ENUM); } | tVARARG { $$ = make_attr(ATTR_VARARG); } | tVERSION '(' version ')' { $$ = make_attrv(ATTR_VERSION, $3); } @@ -730,13 +729,6 @@ attribute | pointer_type { $$ = make_attrv(ATTR_POINTERTYPE, $1); } ;
-uuid_string: - aUUID - | aSTRING { if (!is_valid_uuid($1)) - error_loc("invalid UUID: %s\n", $1); - $$ = parse_uuid($1); } - ; - callconv: tCDECL { $$ = xstrdup("__cdecl"); } | tFASTCALL { $$ = xstrdup("__fastcall"); } | tPASCAL { $$ = xstrdup("__pascal"); } @@ -3258,23 +3250,6 @@ static void check_all_user_types(const statement_list_t *stmts) } }
-int is_valid_uuid(const char *s) -{ - int i; - - for (i = 0; i < 36; ++i) - if (i == 8 || i == 13 || i == 18 || i == 23) - { - if (s[i] != '-') - return FALSE; - } - else - if (!isxdigit(s[i])) - return FALSE; - - return s[i] == '\0'; -} - static statement_t *make_statement(enum statement_type type) { statement_t *stmt = xmalloc(sizeof(*stmt)); diff --git a/tools/widl/utils.h b/tools/widl/utils.h index f042f0e064c..2a994e9697d 100644 --- a/tools/widl/utils.h +++ b/tools/widl/utils.h @@ -35,9 +35,6 @@ size_t strappend(char **buf, size_t *len, size_t pos, const char* fmt, ...) __at
size_t widl_getline(char **linep, size_t *lenp, FILE *fp);
-struct uuid *parse_uuid(const char *u); -int is_valid_uuid(const char *s); - /* buffer management */
extern void add_output_to_resources( const char *type, const char *name );