mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-07-11 22:03:01 -06:00
.developing preprocessor
git-svn-id: svn://ultimatepp.org/upp/trunk@8157 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
5193e84ff2
commit
3224e8d4ca
4 changed files with 59 additions and 4 deletions
|
|
@ -256,6 +256,22 @@ String Cpp::Preprocess(Stream& in, bool needresult)
|
|||
if(p.IsId())
|
||||
macro.UnlinkKey(p.ReadId());
|
||||
}
|
||||
else
|
||||
if(strncmp(s + 1, "include", 7) == 0 && level < 100) {
|
||||
String path = GetIncludePath(s + 8);
|
||||
DDUMP(path);
|
||||
if(path.GetCount()) {
|
||||
Cpp inc;
|
||||
inc.level = level + 1;
|
||||
inc.filedir = filedir;
|
||||
inc.include_path = include_path;
|
||||
FileIn in(path);
|
||||
inc.Preprocess(in, false);
|
||||
inc.macro.Sweep();
|
||||
for(int i = 0; i < inc.macro.GetCount(); i++)
|
||||
macro.GetAdd(inc.macro.GetKey(i)) = inc.macro[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
if(needresult)
|
||||
|
|
@ -272,7 +288,11 @@ String Cpp::Preprocess(Stream& in, bool needresult)
|
|||
incomment = false;
|
||||
s += 2;
|
||||
}
|
||||
s++;
|
||||
else
|
||||
if(s[0] == '/' && s[1] == '/' && !incomment)
|
||||
break;
|
||||
else
|
||||
s++;
|
||||
}
|
||||
}
|
||||
if(needresult)
|
||||
|
|
@ -281,3 +301,27 @@ String Cpp::Preprocess(Stream& in, bool needresult)
|
|||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
String Cpp::GetIncludePath(const char *s)
|
||||
{
|
||||
while(IsSpace(*s))
|
||||
s++;
|
||||
int type = *s;
|
||||
if(type == '<' || type == '\"' || type == '?') {
|
||||
s++;
|
||||
String name;
|
||||
if(type == '<') type = '>';
|
||||
while(*s != '\r' && *s != '\n') {
|
||||
if(*s == type) {
|
||||
if(type == '\"') {
|
||||
String fn = NormalizePath(name, filedir);
|
||||
if(FileExists(fn))
|
||||
return fn;
|
||||
}
|
||||
return GetFileOnPath(name, include_path, false);
|
||||
}
|
||||
name.Cat(*s++);
|
||||
}
|
||||
}
|
||||
return Null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,10 @@ struct CppMacro : Moveable<CppMacro> {
|
|||
struct Cpp {
|
||||
bool incomment;
|
||||
VectorMap<String, CppMacro> macro;
|
||||
|
||||
String filedir;
|
||||
String include_path;
|
||||
int level;
|
||||
|
||||
void Define(const char *s);
|
||||
|
||||
|
|
@ -28,9 +32,10 @@ struct Cpp {
|
|||
void ParamAdd(Vector<String>& param, const char *b, const char *e);
|
||||
|
||||
String Expand(const char *s);
|
||||
void Include(const char *s);
|
||||
String GetIncludePath(const char *s);
|
||||
|
||||
String Preprocess(Stream& in, bool needresult = true);
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -55,8 +55,11 @@ CONSOLE_APP_MAIN
|
|||
DUMP(x.Expand("This is: TEST( \"1\" \"2\" \",\", ',')!"));
|
||||
*/
|
||||
Cpp x;
|
||||
FileIn in0("C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\Vc\\Include\\crtdefs.h");
|
||||
x.Preprocess(in0);
|
||||
x.filedir = GetFileFolder(GetDataFile("x"));
|
||||
x.include_path = "C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\Vc\\Include;C:\\Program Files\\Microsoft SDKs\\Windows\\v7.1\\Include;C:\\OpenSSL-Win32\\include;C:\\u\\pgsql\\include;C:\\u\\OpenSSL-Win32\\include";
|
||||
x.level = 0;
|
||||
// FileIn in0("C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\Vc\\Include\\crtdefs.h");
|
||||
// x.Preprocess(in0);
|
||||
// FileIn in("C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\Vc\\Include\\string.h");
|
||||
FileIn in(GetDataFile("test.h"));
|
||||
LOG(x.Preprocess(in));
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
#include <string.h>
|
||||
#include <winbase.h>
|
||||
#include <wingdi.h>
|
||||
#include <winuser.h>
|
||||
|
||||
#define eprintf(x, ...) if(x) printf(__VA_ARGS__)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue