correct identification of functions that return struct pointers, and beginning of logic to parse inline function bodies

svn path=/trunk/; revision=6543
This commit is contained in:
Royce Mitchell III 2003-11-06 14:28:24 +00:00
parent 0fadf54b2f
commit 999225b038
4 changed files with 88 additions and 12 deletions

View file

@ -12,6 +12,9 @@ typedef enum
T_VARIABLE, T_VARIABLE,
T_FUNCTION, T_FUNCTION,
T_FUNCTION_PTR, T_FUNCTION_PTR,
T_IF,
T_WHILE,
T_DO,
T_STRUCT T_STRUCT
} Type; } Type;

View file

@ -60,12 +60,14 @@ bool is_libc_include ( const string& inc )
{ {
string s ( inc ); string s ( inc );
strlwr ( &s[0] ); strlwr ( &s[0] );
if ( s == "basetsd.h" )
return true;
if ( s == "except.h" )
return true;
if ( s == "limits.h" ) if ( s == "limits.h" )
return true; return true;
if ( s == "stdarg.h" ) if ( s == "stdarg.h" )
return true; return true;
if ( s == "basetsd.h" )
return true;
return false; return false;
} }
@ -78,7 +80,7 @@ BOOL FileEnumProc ( PWIN32_FIND_DATA pwfd, const char* filename, long lParam )
void main() 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 ) bool import_file ( const char* filename )
@ -91,8 +93,6 @@ bool import_file ( const char* filename )
return true; return true;
} }
printf ( "%s\n", filename );
string s; string s;
if ( !File::LoadIntoString ( s, filename ) ) if ( !File::LoadIntoString ( s, filename ) )
{ {
@ -100,6 +100,8 @@ bool import_file ( const char* filename )
exit(0); exit(0);
} }
printf ( "%s\n", filename );
// strip comments from the file... // strip comments from the file...
strip_comments ( s, true ); strip_comments ( s, true );
@ -408,20 +410,34 @@ char* findend ( char* p, bool& externc )
Type identify ( const vector<string>& tokens, int off ) Type identify ( const vector<string>& 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; 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 parens = 0;
int brackets = 0;
for ( int i = off; i < tokens.size(); i++ ) for ( int i = off; i < tokens.size(); i++ )
{ {
if ( tokens[i] == "(" ) if ( tokens[i] == "(" && !brackets )
parens++; parens++;
else if ( tokens[i] == "{" )
brackets++;
else if ( (tokens[i] == "struct" || tokens[i] == "union") && !parens ) else if ( (tokens[i] == "struct" || tokens[i] == "union") && !parens )
{ {
for ( int j = i + 1; j < tokens.size(); j++ ) for ( int j = i + 1; j < tokens.size(); j++ )
{ {
if ( tokens[j] == "{" ) if ( tokens[j] == "{" )
return T_STRUCT; return T_STRUCT;
else if ( tokens[j] == ";" ) else if ( tokens[j] == "(" || tokens[j] == ";" || tokens[j] == "*" )
break; break;
} }
} }
@ -585,6 +601,8 @@ int parse_param ( const vector<string>& tokens, int off, vector<string>& names,
int parse_function ( const vector<string>& tokens, int off, vector<string>& names, vector<string>& dependencies ) int parse_function ( const vector<string>& tokens, int off, vector<string>& names, vector<string>& dependencies )
{ {
vector<string> fauxnames;
while ( tokens[off+1] != "(" ) while ( tokens[off+1] != "(" )
depend ( tokens[off++], dependencies ); depend ( tokens[off++], dependencies );
name ( tokens[off++], names ); name ( tokens[off++], names );
@ -594,14 +612,26 @@ int parse_function ( const vector<string>& tokens, int off, vector<string>& name
while ( tokens[off] != ")" ) while ( tokens[off] != ")" )
{ {
off++; off++;
vector<string> fauxnames;
off = parse_param ( tokens, off, fauxnames, dependencies ); off = parse_param ( tokens, off, fauxnames, dependencies );
ASSERT ( tokens[off] == "," || tokens[off] == ")" ); ASSERT ( tokens[off] == "," || tokens[off] == ")" );
} }
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; return off;
} }

View file

@ -62,6 +62,7 @@ LINK32=link.exe
# PROP Use_Debug_Libraries 1 # PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug" # PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug" # PROP Intermediate_Dir "Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir "" # 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 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 # ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c

View file

@ -44,7 +44,7 @@ void tokenize ( const string& text, vector<string>& tokens )
ASSERT(0); ASSERT(0);
break; break;
default: default:
p++; end++;
break; break;
} }
} }
@ -53,6 +53,8 @@ void tokenize ( const string& text, vector<string>& tokens )
end++; end++;
break; break;
} }
else
end++;
} }
tokens.push_back ( string ( p, end-p ) ); tokens.push_back ( string ( p, end-p ) );
p = end; p = end;
@ -123,6 +125,46 @@ void tokenize ( const string& text, vector<string>& tokens )
tokens.push_back ( ";" ); tokens.push_back ( ";" );
p++; p++;
break; 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 '=': case '=':
switch ( p[1] ) switch ( p[1] )
{ {
@ -204,7 +246,7 @@ void tokenize ( const string& text, vector<string>& tokens )
} }
break; break;
case '#': case '#':
while ( *p != '\n' ) while ( *p && *p != '\n' )
p++; p++;
break; break;
default: default: