mirror of
https://github.com/reactos/reactos.git
synced 2025-08-05 14:53:40 +00:00
handle __asm__, #elif, and #error
svn path=/trunk/; revision=6617
This commit is contained in:
parent
fe56ee2b4d
commit
bc1542edef
2 changed files with 74 additions and 15 deletions
|
@ -6,6 +6,7 @@
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
T_UNKNOWN = -1,
|
T_UNKNOWN = -1,
|
||||||
|
T_ASM,
|
||||||
T_TIDENT,
|
T_TIDENT,
|
||||||
T_MACRO,
|
T_MACRO,
|
||||||
T_DEFINE,
|
T_DEFINE,
|
||||||
|
|
|
@ -45,6 +45,7 @@ Type process ( const string& element, vector<string>& names, bool& isTypedef, ve
|
||||||
void process_preprocessor ( const char* filename, Header& h, const string& element );
|
void process_preprocessor ( const char* filename, Header& h, const string& element );
|
||||||
void process_c ( Header& h, const string& element );
|
void process_c ( Header& h, const string& element );
|
||||||
int parse_type ( Type t, const vector<string>& tokens, int off, vector<string>& names, vector<string>& dependencies );
|
int parse_type ( Type t, const vector<string>& tokens, int off, vector<string>& names, vector<string>& dependencies );
|
||||||
|
int parse_asm ( const vector<string>& tokens, int off, vector<string>& names, vector<string>& dependencies );
|
||||||
int parse_tident ( const vector<string>& tokens, int off, vector<string>& names, vector<string>& dependencies );
|
int parse_tident ( const vector<string>& tokens, int off, vector<string>& names, vector<string>& dependencies );
|
||||||
int parse_variable ( const vector<string>& tokens, int off, vector<string>& names, vector<string>& dependencies );
|
int parse_variable ( const vector<string>& tokens, int off, vector<string>& names, vector<string>& dependencies );
|
||||||
int parse_struct ( const vector<string>& tokens, int off, vector<string>& names, vector<string>& dependencies );
|
int parse_struct ( const vector<string>& tokens, int off, vector<string>& names, vector<string>& dependencies );
|
||||||
|
@ -53,18 +54,24 @@ int parse_function_ptr ( const vector<string>& tokens, int off, vector<string>&
|
||||||
int parse_ifwhile ( const vector<string>& tokens, int off, vector<string>& names, vector<string>& dependencies );
|
int parse_ifwhile ( const vector<string>& tokens, int off, vector<string>& names, vector<string>& dependencies );
|
||||||
int parse_do ( const vector<string>& tokens, int off, vector<string>& names, vector<string>& dependencies );
|
int parse_do ( const vector<string>& tokens, int off, vector<string>& names, vector<string>& dependencies );
|
||||||
|
|
||||||
|
const char* libc_includes[] =
|
||||||
|
{
|
||||||
|
"basestd.h",
|
||||||
|
"except.h",
|
||||||
|
"limits.h",
|
||||||
|
"stdarg.h",
|
||||||
|
"stdlib.h"
|
||||||
|
};
|
||||||
|
|
||||||
bool is_libc_include ( const string& inc )
|
bool is_libc_include ( const string& inc )
|
||||||
{
|
{
|
||||||
string s ( inc );
|
string s ( inc );
|
||||||
strlwr ( &s[0] );
|
strlwr ( &s[0] );
|
||||||
if ( s == "basetsd.h" )
|
for ( int i = 0; i < sizeof(libc_includes)/sizeof(libc_includes[0]); i++ )
|
||||||
return true;
|
{
|
||||||
if ( s == "except.h" )
|
if ( s == libc_includes[i] )
|
||||||
return true;
|
|
||||||
if ( s == "limits.h" )
|
|
||||||
return true;
|
|
||||||
if ( s == "stdarg.h" )
|
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,8 +84,11 @@ BOOL FileEnumProc ( PWIN32_FIND_DATA pwfd, const char* filename, long lParam )
|
||||||
|
|
||||||
void main()
|
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 );
|
EnumFilesInDirectory ( "c:/cvs/reactos/apps/utils/sdkparse/include", "*.h", FileEnumProc, 0, TRUE, FALSE );
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool import_file ( const char* filename )
|
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.ifs.pop_back();
|
||||||
h.ifspreproc.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" )
|
else if ( preproc == "else" )
|
||||||
{
|
{
|
||||||
string& oldpre = h.ifspreproc.back();
|
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 );
|
h.pragmas.push_back ( element );
|
||||||
}
|
}
|
||||||
|
else if ( preproc == "error" )
|
||||||
|
{
|
||||||
|
// FIXME - how to handle these
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf ( "process_preprocessor() choked on '%s'\n", preproc.c_str() );
|
printf ( "process_preprocessor() choked on '%s'\n", preproc.c_str() );
|
||||||
|
@ -373,8 +407,8 @@ char* skipsemi ( char* p )
|
||||||
|
|
||||||
char* findend ( char* p, bool& externc )
|
char* findend ( char* p, bool& externc )
|
||||||
{
|
{
|
||||||
if ( !strncmp ( p, "static inline struct _TEB * NtCurrentTeb", 40 ) )
|
//if ( !strncmp ( p, "static inline struct _TEB * NtCurrentTeb", 40 ) )
|
||||||
_CrtDbgBreak();
|
// _CrtDbgBreak();
|
||||||
// special-case for 'extern "C"'
|
// special-case for 'extern "C"'
|
||||||
if ( !strncmp ( p, "extern", 6 ) )
|
if ( !strncmp ( p, "extern", 6 ) )
|
||||||
{
|
{
|
||||||
|
@ -420,6 +454,17 @@ char* findend ( char* p, bool& externc )
|
||||||
&& !__iscsym(pStruct[-1])
|
&& !__iscsym(pStruct[-1])
|
||||||
&& !__iscsym(pStruct[strlen(structs[i])]) )
|
&& !__iscsym(pStruct[strlen(structs[i])]) )
|
||||||
{
|
{
|
||||||
|
// 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;
|
isStruct = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -449,7 +494,9 @@ Type identify ( const vector<string>& tokens, int off )
|
||||||
if ( tokens[off+2] == "_OBJECTS_AND_SID" )
|
if ( tokens[off+2] == "_OBJECTS_AND_SID" )
|
||||||
_CrtDbgBreak();
|
_CrtDbgBreak();
|
||||||
}*/
|
}*/
|
||||||
if ( tokens[off] == "typedef_tident" )
|
if ( tokens[off] == "__asm__" )
|
||||||
|
return T_ASM;
|
||||||
|
else if ( tokens[off] == "typedef_tident" )
|
||||||
return T_TIDENT;
|
return T_TIDENT;
|
||||||
else if ( tokens[off] == "if" )
|
else if ( tokens[off] == "if" )
|
||||||
return T_IF;
|
return T_IF;
|
||||||
|
@ -514,6 +561,8 @@ int parse_type ( Type t, const vector<string>& tokens, int off, vector<string>&
|
||||||
{
|
{
|
||||||
switch ( t )
|
switch ( t )
|
||||||
{
|
{
|
||||||
|
case T_ASM:
|
||||||
|
return parse_asm ( tokens, off, names, dependencies );
|
||||||
case T_TIDENT:
|
case T_TIDENT:
|
||||||
return parse_tident ( tokens, off, names, dependencies );
|
return parse_tident ( tokens, off, names, dependencies );
|
||||||
case T_VARIABLE:
|
case T_VARIABLE:
|
||||||
|
@ -563,6 +612,16 @@ void depend ( const string& ident, vector<string>& dependencies )
|
||||||
dependencies.push_back ( ident );
|
dependencies.push_back ( ident );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int parse_asm ( const vector<string>& tokens, int off, vector<string>& names, vector<string>& dependencies )
|
||||||
|
{
|
||||||
|
TOKASSERT ( tokens[off] == "__asm__" );
|
||||||
|
off++;
|
||||||
|
while ( tokens[off] != ";" )
|
||||||
|
off++;
|
||||||
|
ASSERT ( tokens[off] == ";" );
|
||||||
|
return off + 1;
|
||||||
|
}
|
||||||
|
|
||||||
int parse_tident ( const vector<string>& tokens, int off, vector<string>& names, vector<string>& dependencies )
|
int parse_tident ( const vector<string>& tokens, int off, vector<string>& names, vector<string>& dependencies )
|
||||||
{
|
{
|
||||||
TOKASSERT ( tokens[off] == "typedef_tident" );
|
TOKASSERT ( tokens[off] == "typedef_tident" );
|
||||||
|
@ -580,8 +639,7 @@ int parse_variable ( const vector<string>& tokens, int off, vector<string>& name
|
||||||
while ( tokens[off] != ";" )
|
while ( tokens[off] != ";" )
|
||||||
name ( tokens[off++], names );
|
name ( tokens[off++], names );
|
||||||
TOKASSERT ( tokens[off] == ";" );
|
TOKASSERT ( tokens[off] == ";" );
|
||||||
off++;
|
return off + 1;
|
||||||
return off;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int parse_struct ( const vector<string>& tokens, int off, vector<string>& names, vector<string>& dependencies )
|
int parse_struct ( const vector<string>& tokens, int off, vector<string>& names, vector<string>& dependencies )
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue