[PATCH 2/3] widl: Restrict some keywords to WinRT mode only.

Rémi Bernon rbernon at codeweavers.com
Wed Nov 4 12:49:28 CST 2020


Signed-off-by: Rémi Bernon <rbernon at codeweavers.com>
---
 tools/widl/parser.l | 339 ++++++++++++++++++++++----------------------
 1 file changed, 170 insertions(+), 169 deletions(-)

diff --git a/tools/widl/parser.l b/tools/widl/parser.l
index f2c09cd8051..b715342ad59 100644
--- a/tools/widl/parser.l
+++ b/tools/widl/parser.l
@@ -248,67 +248,68 @@ int parser_wrap(void)
 struct keyword {
 	const char *kw;
 	int token;
+	int winrt_only : 1;
 };
 
 /* This table MUST be alphabetically sorted on the kw field */
 static const struct keyword keywords[] = {
-	{"FALSE",			tFALSE},
-	{"NULL",			tNULL},
-	{"TRUE",			tTRUE},
-	{"__cdecl",			tCDECL},
-	{"__fastcall",			tFASTCALL},
-	{"__int32",			tINT32},
-	{"__int3264",			tINT3264},
-	{"__int64",			tINT64},
-	{"__pascal",			tPASCAL},
-	{"__stdcall",			tSTDCALL},
-	{"_cdecl",			tCDECL},
-	{"_fastcall",			tFASTCALL},
-	{"_pascal",			tPASCAL},
-	{"_stdcall",			tSTDCALL},
-	{"boolean",			tBOOLEAN},
-	{"byte",			tBYTE},
-	{"case",			tCASE},
-	{"cdecl",			tCDECL},
-	{"char",			tCHAR},
-	{"coclass",			tCOCLASS},
-	{"const",			tCONST},
-	{"cpp_quote",			tCPPQUOTE},
-	{"default",			tDEFAULT},
-	{"dispinterface",		tDISPINTERFACE},
-	{"double",			tDOUBLE},
-	{"enum",			tENUM},
-	{"error_status_t",		tERRORSTATUST},
-	{"extern",			tEXTERN},
-	{"float",			tFLOAT},
-	{"handle_t",			tHANDLET},
-	{"hyper",			tHYPER},
-	{"import",			tIMPORT},
-	{"importlib",			tIMPORTLIB},
-	{"inline",			tINLINE},
-	{"int",				tINT},
-	{"interface",			tINTERFACE},
-	{"library",			tLIBRARY},
-	{"long",			tLONG},
-	{"methods",			tMETHODS},
-	{"module",			tMODULE},
-	{"namespace",			tNAMESPACE},
-	{"pascal",			tPASCAL},
-	{"properties",			tPROPERTIES},
-	{"register",			tREGISTER},
-	{"short",			tSHORT},
-	{"signed",			tSIGNED},
-	{"sizeof",			tSIZEOF},
-        {"small",			tSMALL},
-	{"static",			tSTATIC},
-	{"stdcall",			tSTDCALL},
-	{"struct",			tSTRUCT},
-	{"switch",			tSWITCH},
-	{"typedef",			tTYPEDEF},
-	{"union",			tUNION},
-	{"unsigned",			tUNSIGNED},
-	{"void",			tVOID},
-	{"wchar_t",			tWCHAR},
+	{"FALSE",           tFALSE,          0},
+	{"NULL",            tNULL,           0},
+	{"TRUE",            tTRUE,           0},
+	{"__cdecl",         tCDECL,          0},
+	{"__fastcall",      tFASTCALL,       0},
+	{"__int32",         tINT32,          0},
+	{"__int3264",       tINT3264,        0},
+	{"__int64",         tINT64,          0},
+	{"__pascal",        tPASCAL,         0},
+	{"__stdcall",       tSTDCALL,        0},
+	{"_cdecl",          tCDECL,          0},
+	{"_fastcall",       tFASTCALL,       0},
+	{"_pascal",         tPASCAL,         0},
+	{"_stdcall",        tSTDCALL,        0},
+	{"boolean",         tBOOLEAN,        0},
+	{"byte",            tBYTE,           0},
+	{"case",            tCASE,           0},
+	{"cdecl",           tCDECL,          0},
+	{"char",            tCHAR,           0},
+	{"coclass",         tCOCLASS,        0},
+	{"const",           tCONST,          0},
+	{"cpp_quote",       tCPPQUOTE,       0},
+	{"default",         tDEFAULT,        0},
+	{"dispinterface",   tDISPINTERFACE,  0},
+	{"double",          tDOUBLE,         0},
+	{"enum",            tENUM,           0},
+	{"error_status_t",  tERRORSTATUST,   0},
+	{"extern",          tEXTERN,         0},
+	{"float",           tFLOAT,          0},
+	{"handle_t",        tHANDLET,        0},
+	{"hyper",           tHYPER,          0},
+	{"import",          tIMPORT,         0},
+	{"importlib",       tIMPORTLIB,      0},
+	{"inline",          tINLINE,         0},
+	{"int",             tINT,            0},
+	{"interface",       tINTERFACE,      0},
+	{"library",         tLIBRARY,        0},
+	{"long",            tLONG,           0},
+	{"methods",         tMETHODS,        0},
+	{"module",          tMODULE,         0},
+	{"namespace",       tNAMESPACE,      1},
+	{"pascal",          tPASCAL,         0},
+	{"properties",      tPROPERTIES,     0},
+	{"register",        tREGISTER,       0},
+	{"short",           tSHORT,          0},
+	{"signed",          tSIGNED,         0},
+	{"sizeof",          tSIZEOF,         0},
+	{"small",           tSMALL,          0},
+	{"static",          tSTATIC,         0},
+	{"stdcall",         tSTDCALL,        0},
+	{"struct",          tSTRUCT,         0},
+	{"switch",          tSWITCH,         0},
+	{"typedef",         tTYPEDEF,        0},
+	{"union",           tUNION,          0},
+	{"unsigned",        tUNSIGNED,       0},
+	{"void",            tVOID,           0},
+	{"wchar_t",         tWCHAR,          0},
 };
 #define NKEYWORDS (sizeof(keywords)/sizeof(keywords[0]))
 
@@ -317,116 +318,116 @@ static const struct keyword keywords[] = {
  */
 static const struct keyword attr_keywords[] =
 {
-        {"aggregatable",                tAGGREGATABLE},
-        {"all_nodes",                   tALLNODES},
-        {"allocate",                    tALLOCATE},
-        {"annotation",                  tANNOTATION},
-        {"apartment",                   tAPARTMENT},
-        {"appobject",                   tAPPOBJECT},
-        {"async",                       tASYNC},
-        {"async_uuid",                  tASYNCUUID},
-        {"auto_handle",                 tAUTOHANDLE},
-        {"bindable",                    tBINDABLE},
-        {"both",                        tBOTH},
-        {"broadcast",                   tBROADCAST},
-        {"byte_count",                  tBYTECOUNT},
-        {"call_as",                     tCALLAS},
-        {"callback",                    tCALLBACK},
-        {"code",                        tCODE},
-        {"comm_status",                 tCOMMSTATUS},
-        {"context_handle",              tCONTEXTHANDLE},
-        {"context_handle_noserialize",  tCONTEXTHANDLENOSERIALIZE},
-        {"context_handle_serialize",    tCONTEXTHANDLENOSERIALIZE},
-        {"control",                     tCONTROL},
-        {"decode",                      tDECODE},
-        {"defaultbind",                 tDEFAULTBIND},
-        {"defaultcollelem",             tDEFAULTCOLLELEM},
-        {"defaultvalue",                tDEFAULTVALUE},
-        {"defaultvtable",               tDEFAULTVTABLE},
-        {"disable_consistency_check",   tDISABLECONSISTENCYCHECK},
-        {"displaybind",                 tDISPLAYBIND},
-        {"dllname",                     tDLLNAME},
-        {"dont_free",                   tDONTFREE},
-        {"dual",                        tDUAL},
-        {"enable_allocate",             tENABLEALLOCATE},
-        {"encode",                      tENCODE},
-        {"endpoint",                    tENDPOINT},
-        {"entry",                       tENTRY},
-        {"explicit_handle",             tEXPLICITHANDLE},
-        {"fault_status",                tFAULTSTATUS},
-        {"force_allocate",              tFORCEALLOCATE},
-        {"free",                        tFREE},
-        {"handle",                      tHANDLE},
-        {"helpcontext",                 tHELPCONTEXT},
-        {"helpfile",                    tHELPFILE},
-        {"helpstring",                  tHELPSTRING},
-        {"helpstringcontext",           tHELPSTRINGCONTEXT},
-        {"helpstringdll",               tHELPSTRINGDLL},
-        {"hidden",                      tHIDDEN},
-        {"id",                          tID},
-        {"idempotent",                  tIDEMPOTENT},
-        {"ignore",                      tIGNORE},
-        {"iid_is",                      tIIDIS},
-        {"immediatebind",               tIMMEDIATEBIND},
-        {"implicit_handle",             tIMPLICITHANDLE},
-        {"in",                          tIN},
-        {"in_line",                     tIN_LINE},
-        {"input_sync",                  tINPUTSYNC},
-        {"lcid",                        tLCID},
-        {"length_is",                   tLENGTHIS},
-        {"licensed",                    tLICENSED},
-        {"local",                       tLOCAL},
-        {"maybe",                       tMAYBE},
-        {"message",                     tMESSAGE},
-        {"neutral",                     tNEUTRAL},
-        {"nocode",                      tNOCODE},
-        {"nonbrowsable",                tNONBROWSABLE},
-        {"noncreatable",                tNONCREATABLE},
-        {"nonextensible",               tNONEXTENSIBLE},
-        {"notify",                      tNOTIFY},
-        {"notify_flag",                 tNOTIFYFLAG},
-        {"object",                      tOBJECT},
-        {"odl",                         tODL},
-        {"oleautomation",               tOLEAUTOMATION},
-        {"optimize",                    tOPTIMIZE},
-        {"optional",                    tOPTIONAL},
-        {"out",                         tOUT},
-        {"partial_ignore",              tPARTIALIGNORE},
-        {"pointer_default",             tPOINTERDEFAULT},
-        {"progid",                      tPROGID},
-        {"propget",                     tPROPGET},
-        {"propput",                     tPROPPUT},
-        {"propputref",                  tPROPPUTREF},
-        {"proxy",                       tPROXY},
-        {"ptr",                         tPTR},
-        {"public",                      tPUBLIC},
-        {"range",                       tRANGE},
-        {"readonly",                    tREADONLY},
-        {"ref",                         tREF},
-        {"represent_as",                tREPRESENTAS},
-        {"requestedit",                 tREQUESTEDIT},
-        {"restricted",                  tRESTRICTED},
-        {"retval",                      tRETVAL},
-        {"single",                      tSINGLE},
-        {"single_node",                 tSINGLENODE},
-        {"size_is",                     tSIZEIS},
-        {"source",                      tSOURCE},
-        {"strict_context_handle",       tSTRICTCONTEXTHANDLE},
-        {"string",                      tSTRING},
-        {"switch_is",                   tSWITCHIS},
-        {"switch_type",                 tSWITCHTYPE},
-        {"threading",                   tTHREADING},
-        {"transmit_as",                 tTRANSMITAS},
-        {"uidefault",                   tUIDEFAULT},
-        {"unique",                      tUNIQUE},
-        {"user_marshal",                tUSERMARSHAL},
-        {"usesgetlasterror",            tUSESGETLASTERROR},
-        {"uuid",                        tUUID},
-        {"v1_enum",                     tV1ENUM},
-        {"vararg",                      tVARARG},
-        {"version",                     tVERSION},
-        {"vi_progid",                   tVIPROGID},
-        {"wire_marshal",                tWIREMARSHAL},
+	{"aggregatable",                tAGGREGATABLE,              0},
+	{"all_nodes",                   tALLNODES,                  0},
+	{"allocate",                    tALLOCATE,                  0},
+	{"annotation",                  tANNOTATION,                0},
+	{"apartment",                   tAPARTMENT,                 0},
+	{"appobject",                   tAPPOBJECT,                 0},
+	{"async",                       tASYNC,                     0},
+	{"async_uuid",                  tASYNCUUID,                 0},
+	{"auto_handle",                 tAUTOHANDLE,                0},
+	{"bindable",                    tBINDABLE,                  0},
+	{"both",                        tBOTH,                      0},
+	{"broadcast",                   tBROADCAST,                 0},
+	{"byte_count",                  tBYTECOUNT,                 0},
+	{"call_as",                     tCALLAS,                    0},
+	{"callback",                    tCALLBACK,                  0},
+	{"code",                        tCODE,                      0},
+	{"comm_status",                 tCOMMSTATUS,                0},
+	{"context_handle",              tCONTEXTHANDLE,             0},
+	{"context_handle_noserialize",  tCONTEXTHANDLENOSERIALIZE,  0},
+	{"context_handle_serialize",    tCONTEXTHANDLENOSERIALIZE,  0},
+	{"control",                     tCONTROL,                   0},
+	{"decode",                      tDECODE,                    0},
+	{"defaultbind",                 tDEFAULTBIND,               0},
+	{"defaultcollelem",             tDEFAULTCOLLELEM,           0},
+	{"defaultvalue",                tDEFAULTVALUE,              0},
+	{"defaultvtable",               tDEFAULTVTABLE,             0},
+	{"disable_consistency_check",   tDISABLECONSISTENCYCHECK,   0},
+	{"displaybind",                 tDISPLAYBIND,               0},
+	{"dllname",                     tDLLNAME,                   0},
+	{"dont_free",                   tDONTFREE,                  0},
+	{"dual",                        tDUAL,                      0},
+	{"enable_allocate",             tENABLEALLOCATE,            0},
+	{"encode",                      tENCODE,                    0},
+	{"endpoint",                    tENDPOINT,                  0},
+	{"entry",                       tENTRY,                     0},
+	{"explicit_handle",             tEXPLICITHANDLE,            0},
+	{"fault_status",                tFAULTSTATUS,               0},
+	{"force_allocate",              tFORCEALLOCATE,             0},
+	{"free",                        tFREE,                      0},
+	{"handle",                      tHANDLE,                    0},
+	{"helpcontext",                 tHELPCONTEXT,               0},
+	{"helpfile",                    tHELPFILE,                  0},
+	{"helpstring",                  tHELPSTRING,                0},
+	{"helpstringcontext",           tHELPSTRINGCONTEXT,         0},
+	{"helpstringdll",               tHELPSTRINGDLL,             0},
+	{"hidden",                      tHIDDEN,                    0},
+	{"id",                          tID,                        0},
+	{"idempotent",                  tIDEMPOTENT,                0},
+	{"ignore",                      tIGNORE,                    0},
+	{"iid_is",                      tIIDIS,                     0},
+	{"immediatebind",               tIMMEDIATEBIND,             0},
+	{"implicit_handle",             tIMPLICITHANDLE,            0},
+	{"in",                          tIN,                        0},
+	{"in_line",                     tIN_LINE,                   0},
+	{"input_sync",                  tINPUTSYNC,                 0},
+	{"lcid",                        tLCID,                      0},
+	{"length_is",                   tLENGTHIS,                  0},
+	{"licensed",                    tLICENSED,                  0},
+	{"local",                       tLOCAL,                     0},
+	{"maybe",                       tMAYBE,                     0},
+	{"message",                     tMESSAGE,                   0},
+	{"neutral",                     tNEUTRAL,                   0},
+	{"nocode",                      tNOCODE,                    0},
+	{"nonbrowsable",                tNONBROWSABLE,              0},
+	{"noncreatable",                tNONCREATABLE,              0},
+	{"nonextensible",               tNONEXTENSIBLE,             0},
+	{"notify",                      tNOTIFY,                    0},
+	{"notify_flag",                 tNOTIFYFLAG,                0},
+	{"object",                      tOBJECT,                    0},
+	{"odl",                         tODL,                       0},
+	{"oleautomation",               tOLEAUTOMATION,             0},
+	{"optimize",                    tOPTIMIZE,                  0},
+	{"optional",                    tOPTIONAL,                  0},
+	{"out",                         tOUT,                       0},
+	{"partial_ignore",              tPARTIALIGNORE,             0},
+	{"pointer_default",             tPOINTERDEFAULT,            0},
+	{"progid",                      tPROGID,                    0},
+	{"propget",                     tPROPGET,                   0},
+	{"propput",                     tPROPPUT,                   0},
+	{"propputref",                  tPROPPUTREF,                0},
+	{"proxy",                       tPROXY,                     0},
+	{"ptr",                         tPTR,                       0},
+	{"public",                      tPUBLIC,                    0},
+	{"range",                       tRANGE,                     0},
+	{"readonly",                    tREADONLY,                  0},
+	{"ref",                         tREF,                       0},
+	{"represent_as",                tREPRESENTAS,               0},
+	{"requestedit",                 tREQUESTEDIT,               0},
+	{"restricted",                  tRESTRICTED,                0},
+	{"retval",                      tRETVAL,                    0},
+	{"single",                      tSINGLE,                    0},
+	{"single_node",                 tSINGLENODE,                0},
+	{"size_is",                     tSIZEIS,                    0},
+	{"source",                      tSOURCE,                    0},
+	{"strict_context_handle",       tSTRICTCONTEXTHANDLE,       0},
+	{"string",                      tSTRING,                    0},
+	{"switch_is",                   tSWITCHIS,                  0},
+	{"switch_type",                 tSWITCHTYPE,                0},
+	{"threading",                   tTHREADING,                 0},
+	{"transmit_as",                 tTRANSMITAS,                0},
+	{"uidefault",                   tUIDEFAULT,                 0},
+	{"unique",                      tUNIQUE,                    0},
+	{"user_marshal",                tUSERMARSHAL,               0},
+	{"usesgetlasterror",            tUSESGETLASTERROR,          0},
+	{"uuid",                        tUUID,                      0},
+	{"v1_enum",                     tV1ENUM,                    0},
+	{"vararg",                      tVARARG,                    0},
+	{"version",                     tVERSION,                   0},
+	{"vi_progid",                   tVIPROGID,                  0},
+	{"wire_marshal",                tWIREMARSHAL,               0},
 };
 
 /* attributes TODO:
@@ -449,7 +450,7 @@ static int kw_token(const char *kw)
 	struct keyword key, *kwp;
 	key.kw = kw;
 	kwp = bsearch(&key, keywords, NKEYWORDS, sizeof(keywords[0]), kw_cmp_func);
-	if (kwp && (winrt_mode || kwp->token != tNAMESPACE)) {
+	if (kwp && (!kwp->winrt_only || winrt_mode)) {
 		parser_lval.str = xstrdup(kwp->kw);
 		return kwp->token;
 	}
@@ -463,7 +464,7 @@ static int attr_token(const char *kw)
         key.kw = kw;
         kwp = bsearch(&key, attr_keywords, sizeof(attr_keywords)/sizeof(attr_keywords[0]),
                       sizeof(attr_keywords[0]), kw_cmp_func);
-        if (kwp) {
+        if (kwp && (!kwp->winrt_only || winrt_mode)) {
             parser_lval.str = xstrdup(kwp->kw);
             return kwp->token;
         }
-- 
2.29.2




More information about the wine-devel mailing list