ultimatepp/uppdev/cpp2/expand.cpp
cxl ddd0429964 .uppdev
git-svn-id: svn://ultimatepp.org/upp/trunk@8288 f0d560ea-af0d-0410-9eb7-867de7ffcac7
2015-03-23 09:27:27 +00:00

94 lines
No EOL
1.8 KiB
C++

#include "cpp.h"
#if 0
String MacroExpand(const char *s, ArrayMap<String, CppMacro>& macro, Index<String>& notmacro,
bool& incomment)
{
StringBuffer r;
while(*s) {
if(incomment) {
if(s[0] == '*' && s[1] == '/') {
incomment = false;
s += 2;
r.Cat("*/");
}
else
r.Cat(*s++);
}
else
if(iscib2(*s)) {
const char *b = s;
s++;
while(iscid2(*s))
s++;
String id(b, s);
if(notmacro.Find(id) < 0) {
const CppMacro *m = macro.FindPtr(id);
if(m && !id.StartsWith("__$allowed_on_")) {
Vector<String> param;
const char *s0 = s;
while(*s && (byte)*s <= ' ')
s++;
if(*s == '(') {
s++;
const char *b = s;
int level = 0;
for(;;)
if(*s == ',' && level == 0) {
ParamAdd(param, b, s);
s++;
b = s;
}
else
if(*s == ')') {
s++;
if(level == 0) {
ParamAdd(param, b, s - 1);
break;
}
level--;
}
else
if(*s == '(') {
s++;
level++;
}
else
if(*s == '\0')
break;
else
if(*s == '\"' || *s == '\'')
s = SkipString(s);
else
s++;
}
else
s = s0; // otherwise we eat spaces after parameterless macro
usedmacro.FindAdd(id);
int ti = notmacro.GetCount();
notmacro.Add(id);
id = '\x1a' + Expand(m->Expand(param));
notmacro.Trim(ti);
}
else
notmacro.Add(id);
}
r.Cat(id);
}
else
if(s[0] == '/' && s[1] == '*') {
incomment = true;
s += 2;
r.Cat("/*");
}
else
if(s[0] == '/' && s[1] == '/') {
r.Cat(s);
break;
}
else
r.Cat(*s++);
}
return r;
}
#endif