From bc1542edeff8cf48a4b73e1ca5a73207552335db Mon Sep 17 00:00:00 2001 From: Royce Mitchell III Date: Tue, 11 Nov 2003 15:31:48 +0000 Subject: [PATCH] handle __asm__, #elif, and #error svn path=/trunk/; revision=6617 --- reactos/apps/utils/sdkparse/Type.h | 1 + reactos/apps/utils/sdkparse/sdkparse.cpp | 88 ++++++++++++++++++++---- 2 files changed, 74 insertions(+), 15 deletions(-) diff --git a/reactos/apps/utils/sdkparse/Type.h b/reactos/apps/utils/sdkparse/Type.h index 708194c4dcb..dcdde61a144 100644 --- a/reactos/apps/utils/sdkparse/Type.h +++ b/reactos/apps/utils/sdkparse/Type.h @@ -6,6 +6,7 @@ typedef enum { T_UNKNOWN = -1, + T_ASM, T_TIDENT, T_MACRO, T_DEFINE, diff --git a/reactos/apps/utils/sdkparse/sdkparse.cpp b/reactos/apps/utils/sdkparse/sdkparse.cpp index 9f02a3cd2c9..adcce1c094b 100644 --- a/reactos/apps/utils/sdkparse/sdkparse.cpp +++ b/reactos/apps/utils/sdkparse/sdkparse.cpp @@ -45,6 +45,7 @@ Type process ( const string& element, vector& names, bool& isTypedef, ve void process_preprocessor ( const char* filename, Header& h, const string& element ); void process_c ( Header& h, const string& element ); int parse_type ( Type t, const vector& tokens, int off, vector& names, vector& dependencies ); +int parse_asm ( const vector& tokens, int off, vector& names, vector& dependencies ); int parse_tident ( const vector& tokens, int off, vector& names, vector& dependencies ); int parse_variable ( const vector& tokens, int off, vector& names, vector& dependencies ); int parse_struct ( const vector& tokens, int off, vector& names, vector& dependencies ); @@ -53,18 +54,24 @@ int parse_function_ptr ( const vector& tokens, int off, vector& int parse_ifwhile ( const vector& tokens, int off, vector& names, vector& dependencies ); int parse_do ( const vector& tokens, int off, vector& names, vector& dependencies ); +const char* libc_includes[] = +{ + "basestd.h", + "except.h", + "limits.h", + "stdarg.h", + "stdlib.h" +}; + bool is_libc_include ( const string& inc ) { string s ( inc ); strlwr ( &s[0] ); - if ( s == "basetsd.h" ) - return true; - if ( s == "except.h" ) - return true; - if ( s == "limits.h" ) - return true; - if ( s == "stdarg.h" ) - return true; + for ( int i = 0; i < sizeof(libc_includes)/sizeof(libc_includes[0]); i++ ) + { + if ( s == libc_includes[i] ) + return true; + } return false; } @@ -77,8 +84,11 @@ BOOL FileEnumProc ( PWIN32_FIND_DATA pwfd, const char* filename, long lParam ) void main() { - //import_file ( "test.h" ); +#if 1 + import_file ( "../test.h" ); +#else EnumFilesInDirectory ( "c:/cvs/reactos/apps/utils/sdkparse/include", "*.h", FileEnumProc, 0, TRUE, FALSE ); +#endif } bool import_file ( const char* filename ) @@ -273,6 +283,26 @@ void process_preprocessor ( const char* filename, Header& h, const string& eleme h.ifs.pop_back(); h.ifspreproc.pop_back(); } + else if ( preproc == "elif" ) + { + string& oldpre = h.ifspreproc.back(); + string old = h.ifs.back(); + string condold; + if ( oldpre == "ifdef" ) + condold = string("!defined(") + old + ")"; + else if ( oldpre == "ifndef" ) + condold = string("defined(") + old + ")"; + else if ( oldpre == "if" ) + condold = string("!(") + old + ")"; + else + { + printf ( "unrecognized preproc '%s'\n", oldpre.c_str() ); + ASSERT(0); + return; + } + h.ifs.back() = string("(") + element + ") && " + condold; + h.ifspreproc.back() = "if"; + } else if ( preproc == "else" ) { string& oldpre = h.ifspreproc.back(); @@ -299,6 +329,10 @@ void process_preprocessor ( const char* filename, Header& h, const string& eleme { h.pragmas.push_back ( element ); } + else if ( preproc == "error" ) + { + // FIXME - how to handle these + } else { printf ( "process_preprocessor() choked on '%s'\n", preproc.c_str() ); @@ -373,8 +407,8 @@ char* skipsemi ( char* p ) char* findend ( char* p, bool& externc ) { - if ( !strncmp ( p, "static inline struct _TEB * NtCurrentTeb", 40 ) ) - _CrtDbgBreak(); + //if ( !strncmp ( p, "static inline struct _TEB * NtCurrentTeb", 40 ) ) + // _CrtDbgBreak(); // special-case for 'extern "C"' if ( !strncmp ( p, "extern", 6 ) ) { @@ -420,7 +454,18 @@ char* findend ( char* p, bool& externc ) && !__iscsym(pStruct[-1]) && !__iscsym(pStruct[strlen(structs[i])]) ) { - isStruct = true; + // make sure there's at most one identifier followed + // by a { + pStruct += strlen(structs[i]); + pStruct = skip_ws ( pStruct ); + if ( __iscsymf(*pStruct) ) + { + while ( __iscsym(*pStruct) ) + pStruct++; + pStruct = skip_ws ( pStruct ); + } + if ( *pStruct == '{' ) + isStruct = true; break; } } @@ -449,7 +494,9 @@ Type identify ( const vector& tokens, int off ) if ( tokens[off+2] == "_OBJECTS_AND_SID" ) _CrtDbgBreak(); }*/ - if ( tokens[off] == "typedef_tident" ) + if ( tokens[off] == "__asm__" ) + return T_ASM; + else if ( tokens[off] == "typedef_tident" ) return T_TIDENT; else if ( tokens[off] == "if" ) return T_IF; @@ -514,6 +561,8 @@ int parse_type ( Type t, const vector& tokens, int off, vector& { switch ( t ) { + case T_ASM: + return parse_asm ( tokens, off, names, dependencies ); case T_TIDENT: return parse_tident ( tokens, off, names, dependencies ); case T_VARIABLE: @@ -563,6 +612,16 @@ void depend ( const string& ident, vector& dependencies ) dependencies.push_back ( ident ); } +int parse_asm ( const vector& tokens, int off, vector& names, vector& dependencies ) +{ + TOKASSERT ( tokens[off] == "__asm__" ); + off++; + while ( tokens[off] != ";" ) + off++; + ASSERT ( tokens[off] == ";" ); + return off + 1; +} + int parse_tident ( const vector& tokens, int off, vector& names, vector& dependencies ) { TOKASSERT ( tokens[off] == "typedef_tident" ); @@ -580,8 +639,7 @@ int parse_variable ( const vector& tokens, int off, vector& name while ( tokens[off] != ";" ) name ( tokens[off++], names ); TOKASSERT ( tokens[off] == ";" ); - off++; - return off; + return off + 1; } int parse_struct ( const vector& tokens, int off, vector& names, vector& dependencies )