diff --git a/reactos/apps/utils/sdkparse/Type.h b/reactos/apps/utils/sdkparse/Type.h index db42f33a535..708194c4dcb 100644 --- a/reactos/apps/utils/sdkparse/Type.h +++ b/reactos/apps/utils/sdkparse/Type.h @@ -12,6 +12,9 @@ typedef enum T_VARIABLE, T_FUNCTION, T_FUNCTION_PTR, + T_IF, + T_WHILE, + T_DO, T_STRUCT } Type; diff --git a/reactos/apps/utils/sdkparse/sdkparse.cpp b/reactos/apps/utils/sdkparse/sdkparse.cpp index 450d870a1b6..10f5e5909df 100644 --- a/reactos/apps/utils/sdkparse/sdkparse.cpp +++ b/reactos/apps/utils/sdkparse/sdkparse.cpp @@ -60,12 +60,14 @@ 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; - if ( s == "basetsd.h" ) - return true; return false; } @@ -78,7 +80,7 @@ BOOL FileEnumProc ( PWIN32_FIND_DATA pwfd, const char* filename, long lParam ) void main() { - EnumFilesInDirectory ( "c:/cvs/reactos/include", "*.h", FileEnumProc, 0, TRUE, FALSE ); + EnumFilesInDirectory ( "c:/cvs/reactos/apps/utils/sdkparse/include", "*.h", FileEnumProc, 0, TRUE, FALSE ); } bool import_file ( const char* filename ) @@ -91,8 +93,6 @@ bool import_file ( const char* filename ) return true; } - printf ( "%s\n", filename ); - string s; if ( !File::LoadIntoString ( s, filename ) ) { @@ -100,6 +100,8 @@ bool import_file ( const char* filename ) exit(0); } + printf ( "%s\n", filename ); + // strip comments from the file... strip_comments ( s, true ); @@ -408,20 +410,34 @@ char* findend ( char* p, bool& externc ) Type identify ( const vector& tokens, int off ) { - if ( tokens[0] == "typedef_tident" ) + /*if ( tokens.size() >= (off+6) ) + { + if ( tokens[off+5] == "NtCurrentTeb" ) + _CrtDbgBreak(); + }*/ + if ( tokens[off] == "typedef_tident" ) return T_TIDENT; + else if ( tokens[off] == "if" ) + return T_IF; + else if ( tokens[off] == "while" ) + return T_WHILE; + else if ( tokens[off] == "do" ) + return T_DO; int parens = 0; + int brackets = 0; for ( int i = off; i < tokens.size(); i++ ) { - if ( tokens[i] == "(" ) + if ( tokens[i] == "(" && !brackets ) parens++; + else if ( tokens[i] == "{" ) + brackets++; else if ( (tokens[i] == "struct" || tokens[i] == "union") && !parens ) { for ( int j = i + 1; j < tokens.size(); j++ ) { if ( tokens[j] == "{" ) return T_STRUCT; - else if ( tokens[j] == ";" ) + else if ( tokens[j] == "(" || tokens[j] == ";" || tokens[j] == "*" ) break; } } @@ -585,6 +601,8 @@ int parse_param ( const vector& tokens, int off, vector& names, int parse_function ( const vector& tokens, int off, vector& names, vector& dependencies ) { + vector fauxnames; + while ( tokens[off+1] != "(" ) depend ( tokens[off++], dependencies ); name ( tokens[off++], names ); @@ -594,14 +612,26 @@ int parse_function ( const vector& tokens, int off, vector& name while ( tokens[off] != ")" ) { off++; - vector fauxnames; off = parse_param ( tokens, off, fauxnames, dependencies ); ASSERT ( tokens[off] == "," || tokens[off] == ")" ); } off++; - ASSERT ( tokens[off] == ";" ); + // is this just a function *declaration* ? + if ( tokens[off] == ";" ) + return off; + + // we have a function body... + ASSERT ( tokens[off] == "{" ); + off++; + + while ( tokens[off] != "}" ) + { + Type t = identify ( tokens, off ); + off = parse_type ( t, tokens, off, fauxnames, dependencies ); + } + return off; } diff --git a/reactos/apps/utils/sdkparse/sdkparse.dsp b/reactos/apps/utils/sdkparse/sdkparse.dsp index 728d566b683..d46550fb584 100644 --- a/reactos/apps/utils/sdkparse/sdkparse.dsp +++ b/reactos/apps/utils/sdkparse/sdkparse.dsp @@ -62,6 +62,7 @@ LINK32=link.exe # PROP Use_Debug_Libraries 1 # PROP Output_Dir "Debug" # PROP Intermediate_Dir "Debug" +# PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c # ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c diff --git a/reactos/apps/utils/sdkparse/tokenize.cpp b/reactos/apps/utils/sdkparse/tokenize.cpp index 89c8beb49ec..8a8995def39 100644 --- a/reactos/apps/utils/sdkparse/tokenize.cpp +++ b/reactos/apps/utils/sdkparse/tokenize.cpp @@ -44,7 +44,7 @@ void tokenize ( const string& text, vector& tokens ) ASSERT(0); break; default: - p++; + end++; break; } } @@ -53,6 +53,8 @@ void tokenize ( const string& text, vector& tokens ) end++; break; } + else + end++; } tokens.push_back ( string ( p, end-p ) ); p = end; @@ -123,6 +125,46 @@ void tokenize ( const string& text, vector& tokens ) tokens.push_back ( ";" ); p++; break; + case '\\': + switch ( p[1] ) + { + case '\n': + tokens.push_back ( string ( p, 2 ) ); + p += 2; + break; + default: + ASSERT(0); // shouldn't hit here, I think + tokens.push_back ( "\\" ); + p++; + break; + } + break; + case '|': + switch ( p[1] ) + { + case '|': + tokens.push_back ( string ( p, 2 ) ); + p += 2; + break; + default: + tokens.push_back ( "|" ); + p++; + break; + } + break; + case '&': + switch ( p[1] ) + { + case '&': + tokens.push_back ( string ( p, 2 ) ); + p += 2; + break; + default: + tokens.push_back ( "&" ); + p++; + break; + } + break; case '=': switch ( p[1] ) { @@ -204,7 +246,7 @@ void tokenize ( const string& text, vector& tokens ) } break; case '#': - while ( *p != '\n' ) + while ( *p && *p != '\n' ) p++; break; default: