cpp: Fixed issue with #define inside the scope #1099

git-svn-id: svn://ultimatepp.org/upp/trunk@8501 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2015-06-03 07:06:22 +00:00
parent c70f5901fc
commit a66fcdb838
3 changed files with 27 additions and 34 deletions

View file

@ -311,7 +311,9 @@ struct SrcFile {
int commentLinesRemoved;
};
SrcFile PreProcess(Stream& in);
struct Parser;
SrcFile PreProcess(Stream& in, Parser& parser);
enum Kind {
STRUCT,
@ -579,6 +581,8 @@ struct Parser {
typedef Parser CLASSNAME;
public:
void AddMacro(int lineno, const String& macro);
struct FunctionStat
{
FunctionStat(const String & scope,

View file

@ -743,8 +743,11 @@ void Parser::ParamList(Decl& d) {
Elipsis(d);
break;
}
else
d.param.Add() = pick(Declaration(false, false, Null, Null).Top());
else {
Array<Parser::Decl> decl = Declaration(false, false, Null, Null);
if(decl.GetCount())
d.param.Add() = pick(decl.Top());
}
if(Key(t_elipsis)) {
Elipsis(d);
break;
@ -1305,6 +1308,18 @@ CppItem& Parser::Item(const String& scope, const String& using_namespace, const
return im;
}
void Parser::AddMacro(int lineno, const String& macro)
{
String name;
const char *s = macro;
while(*s && iscid(*s))
name.Cat(*s++);
CppItem& im = Item("", "", macro, name);
im.kind = MACRO;
im.line = lineno;
im.access = PUBLIC;
}
CppItem& Parser::Item(const String& scope, const String& using_namespace, const String& item,
const String& name)
{
@ -1650,34 +1665,6 @@ void Parser::Do()
Enum();
}
else
if(Key('#')) {
if(lex.Code() == t_string) {
String n = lex.GetText();
String name;
const char *s = n;
while(*s && iscid(*s))
name.Cat(*s++);
CppItem& im = Item("", context.namespace_using, n, name);
im.kind = MACRO;
s = strchr(n, '(');
if(s) {
s++;
String p;
for(;;) {
if(iscid(*s))
p.Cat(*s++);
else {
ScAdd(im.pname, p);
p.Clear();
if(*s == ')' || *s == '\0') break;
s++;
}
}
}
im.access = context.access;
}
}
else
if(!Scope(String(), String())) {
if(Key(tk_public)) {
context.access = PUBLIC;
@ -1750,7 +1737,7 @@ void Parser::Do(Stream& in, CppBase& _base, int filei_, int filetype_,
{
LLOG("= C++ Parser ==================================== " << fn);
base = &_base;
file = PreProcess(in);
file = PreProcess(in, *this);
lex.Init(~file.text);
err = _err;
filei = filei_;

View file

@ -19,12 +19,14 @@ SrcFile::SrcFile() :
{
}
SrcFile PreProcess(Stream& in) // This is not really C preprocess, only removes (or processes) comment and directives
SrcFile PreProcess(Stream& in, Parser& parser) // This is not really C preprocess, only removes (or processes) comment and directives
{
SrcFile res;
bool include = true;
int lineno = 0;
while(!in.IsEof()) {
String ln = in.GetLine();
lineno++;
SLPos(res);
while(*ln.Last() == '\\') {
ln.Trim(ln.GetLength() - 1);
@ -61,7 +63,7 @@ SrcFile PreProcess(Stream& in) // This is not really C preprocess, only removes
macro << ')';
}
if(include)
res.text << '#' << AsCString(macro);
parser.AddMacro(lineno, macro);
}
res.preprocessorLinesRemoved++;
}