more special-cases

svn path=/trunk/; revision=6685
This commit is contained in:
Royce Mitchell III 2003-11-18 05:20:00 +00:00
parent 6c1d0b1576
commit 1f5f11925a
2 changed files with 100 additions and 9 deletions

View file

@ -87,8 +87,8 @@ BOOL FileEnumProc ( PWIN32_FIND_DATA pwfd, const char* filename, long lParam )
void main()
{
printf ( "press any key to start\n" );
getch();
//printf ( "press any key to start\n" );
//getch();
#if 1
import_file ( "../test.h" );
#else
@ -208,8 +208,12 @@ void process_preprocessor ( const char* filename, Header& h, const string& eleme
p = end+1;
p = skip_ws ( p );
const string dbg_filename = "napi/lpc.h DISABLE DISABLE DISABLE";
if ( preproc == "include" )
{
//if ( h.filename == "napi/lpc.h" )
// _CrtDbgBreak();
ASSERT ( *p == '<' || *p == '\"' );
p++;
p = skip_ws ( p );
@ -224,7 +228,7 @@ void process_preprocessor ( const char* filename, Header& h, const string& eleme
else
{
bool loaded = false;
for ( int i = 0; i < headers.size(); i++ )
for ( int i = 0; i < headers.size() && !loaded; i++ )
{
if ( headers[i]->filename == include_filename )
{
@ -277,6 +281,8 @@ void process_preprocessor ( const char* filename, Header& h, const string& eleme
}
else if ( preproc == "if" || preproc == "ifdef" || preproc == "ifndef" )
{
if ( dbg_filename == h.filename )
printf ( "(%s) PRE-PUSH preproc stack = %lu\n", preproc.c_str(), h.ifs.size() );
size_t len = element.size();
// check for header include guard...
if ( strstr ( element.c_str(), hdrguardtext.c_str() )
@ -286,14 +292,23 @@ void process_preprocessor ( const char* filename, Header& h, const string& eleme
else
h.ifs.push_back ( element );
h.ifspreproc.push_back ( preproc );
if ( dbg_filename == h.filename )
printf ( "POST-PUSH preproc stack = %lu\n", h.ifs.size() );
}
else if ( preproc == "endif" )
{
if ( dbg_filename == h.filename )
printf ( "(%s) PRE-POP preproc stack = %lu\n", preproc.c_str(), h.ifs.size() );
ASSERT ( h.ifs.size() > 0 && h.ifs.size() == h.ifspreproc.size() );
h.ifs.pop_back();
h.ifspreproc.pop_back();
if ( dbg_filename == h.filename )
printf ( "POST-POP preproc stack = %lu\n", h.ifs.size() );
}
else if ( preproc == "elif" )
{
if ( dbg_filename == h.filename )
printf ( "(%s) PRE-PUSHPOP preproc stack = %lu\n", preproc.c_str(), h.ifs.size() );
string& oldpre = h.ifspreproc.back();
string old = h.ifs.back();
string condold;
@ -311,9 +326,13 @@ void process_preprocessor ( const char* filename, Header& h, const string& eleme
}
h.ifs.back() = string("(") + element + ") && " + condold;
h.ifspreproc.back() = "if";
if ( dbg_filename == h.filename )
printf ( "POST-PUSHPOP preproc stack = %lu\n", h.ifs.size() );
}
else if ( preproc == "else" )
{
if ( dbg_filename == h.filename )
printf ( "(%s) PRE-PUSHPOP preproc stack = %lu\n", preproc.c_str(), h.ifs.size() );
string& oldpre = h.ifspreproc.back();
ASSERT ( oldpre != "else" );
if ( oldpre == "ifdef" )
@ -329,6 +348,8 @@ void process_preprocessor ( const char* filename, Header& h, const string& eleme
return;
}
oldpre = "else";
if ( dbg_filename == h.filename )
printf ( "POST-PUSHPOP preproc stack = %lu\n", h.ifs.size() );
}
else if ( preproc == "include_next" )
{
@ -511,13 +532,34 @@ char* findend ( char* p, bool& externc )
return end;
}
int skip_declspec ( const vector<string>& tokens, int off )
{
if ( tokens[off] == "__declspec" )
{
off++;
TOKASSERT ( tokens[off] == "(" );
off++;
int parens = 1;
while ( parens )
{
if ( tokens[off] == "(" )
parens++;
else if ( tokens[off] == ")" )
parens--;
off++;
}
}
return off;
}
Type identify ( const vector<string>& tokens, int off )
{
if ( tokens.size() > off+2 )
off = skip_declspec ( tokens, off );
/*if ( tokens.size() > off+4 )
{
if ( tokens[off+2] == "_lfind" )
if ( tokens[off+4] == "PCONTROLDISPATCHER" )
_CrtDbgBreak();
}
}*/
/*if ( tokens.size() > off+1 )
{
if ( tokens[off+1] == "_OSVERSIONINFOEXA" )
@ -558,6 +600,8 @@ Type identify ( const vector<string>& tokens, int off )
}
else if ( tokens[i] == ";" )
break;
else if ( tokens[i] == "__attribute__" )
break;
}
if ( openparens > 1 && closeparens )
return T_FUNCTION_PTR;
@ -738,9 +782,33 @@ int parse_param ( const vector<string>& tokens, int off, vector<string>& names,
{
if ( tokens[off] == ")" )
return off;
while ( tokens[off+1] != "," && tokens[off+1] != ")" )
// special-case check for function pointer params
int done = off;
int parens = 1;
bool fptr = false;
for ( ;; )
{
if ( tokens[done] == "," && parens == 1 )
break;
if ( tokens[done] == ")" )
{
if ( parens == 1 )
break;
else
parens--;
}
if ( tokens[done] == "(" )
parens++;
if ( tokens[done] == "*" && tokens[done-1] == "(" )
fptr = true;
done++;
}
if ( !fptr )
done--;
while ( off < done )
depend ( tokens[off++], dependencies );
name ( tokens[off++], names );
if ( !fptr )
name ( tokens[off++], names );
return off;
}
@ -748,6 +816,8 @@ int parse_function ( const vector<string>& tokens, int off, vector<string>& name
{
vector<string> fauxnames;
off = skip_declspec ( tokens, off );
while ( tokens[off+1] != "(" )
depend ( tokens[off++], dependencies );
name ( tokens[off++], names );
@ -763,6 +833,23 @@ int parse_function ( const vector<string>& tokens, int off, vector<string>& name
off++;
// check for "attributes"
if ( tokens[off] == "__attribute__" )
{
off++;
TOKASSERT ( tokens[off] == "(" );
off++;
int parens = 1;
while ( parens )
{
if ( tokens[off] == "(" )
parens++;
else if ( tokens[off] == ")" )
parens--;
off++;
}
}
// is this just a function *declaration* ?
if ( tokens[off] == ";" )
return off;
@ -793,6 +880,8 @@ int parse_function ( const vector<string>& tokens, int off, vector<string>& name
int parse_function_ptr ( const vector<string>& tokens, int off, vector<string>& names, vector<string>& dependencies )
{
off = skip_declspec ( tokens, off );
while ( tokens[off] != "(" )
depend ( tokens[off++], dependencies );

View file

@ -1,4 +1,4 @@
/* $Id: test.h,v 1.3 2003/11/06 19:38:23 royce Exp $
/* $Id: test.h,v 1.4 2003/11/18 05:20:00 royce Exp $
*/
/*
* test.h
@ -22,6 +22,8 @@
#ifndef __INTERNAL_PSAPI_H_INCLUDED__
#define __INTERNAL_PSAPI_H_INCLUDED__
void *_lfind(const void* match, const void* start,unsigned int* array_size, unsigned int elem_size,int (*cf)(const void*,const void*));
static inline struct _TEB * NtCurrentTeb(void)
{
struct _TEB * pTeb;