diff --git a/autotest/CppParser/CppParser.cpp b/autotest/CppParser/CppParser.cpp new file mode 100644 index 000000000..771079c0f --- /dev/null +++ b/autotest/CppParser/CppParser.cpp @@ -0,0 +1,67 @@ +#include + +using namespace Upp; + +Vector errs; + +void AddError(int ln, const String& s) +{ + errs.Add(AsString(ln) + ": " + s); +} + +void Test(const char *path) +{ + CppBase base; + + LOG("**** " << GetFileName(path)); + + FileIn in(path); + errs.Clear(); + + Parser p; + p.Do(in, Vector(), base, path, callback(AddError)); + + if(errs.GetCount()) + DUMPC(errs); + Qualify(base); + String out; + for(int i = 0; i < base.GetCount(); i++) { + out << Nvl(base.GetKey(i), "") << " {\n"; + const Array& ma = base[i]; + for(int j = 0; j < ma.GetCount(); j++) { + const CppItem& m = ma[j]; + out << '\t' << CppItemKindAsString(m.kind) << ' ' << m.qitem << ", line " << m.line << "\n"; + } + out << "}\n"; + } + + p.dobody = true; + in.Seek(0); + p.Do(in, Vector(), base, path, callback(AddError)); + + out << " {\n"; + for(int i = 0; i < p.local.GetCount(); i++) { + out << p.local.GetKey(i) << " " << p.local[i].type; + if(p.local[i].isptr) + out << " pointer"; + out << ", line: " << p.local[i].line << "\n"; + } + out << "}"; + LOG("===="); + LOG(out); + LOG("-------------------------------------------------------------------------------"); + String h = LoadFile(ForceExt(path, ".out")); + h.Replace("\r", ""); + ASSERT(out == h); +} + +CONSOLE_APP_MAIN { + StdLogSetup(LOG_COUT|LOG_FILE); + + FindFile ff(GetDataFile("*.in")); + while(ff) { + Test(ff.GetPath()); + ff.Next(); + } + LOG("=========== OK"); +} diff --git a/autotest/CppParser/CppParser.upp b/autotest/CppParser/CppParser.upp new file mode 100644 index 000000000..3b609ad85 --- /dev/null +++ b/autotest/CppParser/CppParser.upp @@ -0,0 +1,14 @@ +uses + Core, + CppBase; + +file + CppParser.cpp, + test1.in, + test1.out, + test2.in, + test2.out; + +mainconfig + "" = "SSE2"; + diff --git a/autotest/CppParser/init b/autotest/CppParser/init new file mode 100644 index 000000000..caa0521ce --- /dev/null +++ b/autotest/CppParser/init @@ -0,0 +1,5 @@ +#ifndef _CppParser_icpp_init_stub +#define _CppParser_icpp_init_stub +#include "Core/init" +#include "CppBase/init" +#endif diff --git a/autotest/CppParser/test1.in b/autotest/CppParser/test1.in new file mode 100644 index 000000000..6ef6e057b --- /dev/null +++ b/autotest/CppParser/test1.in @@ -0,0 +1,18 @@ +void Test() {} + +class Foo { + Foo(); +}; + +struct Point { + int x, y; + Point *next; + Foo bar; +}; + +Point global; + +void foo() +{ + int x = 10; + Point a, b, *c; diff --git a/autotest/CppParser/test1.out b/autotest/CppParser/test1.out new file mode 100644 index 000000000..3fddef058 --- /dev/null +++ b/autotest/CppParser/test1.out @@ -0,0 +1,22 @@ + { + FUNCTION Test(), line 1 + FUNCTION foo(), line 15 + VARIABLE global, line 13 +} +Foo { + CONSTRUCTOR Foo(), line 4 + STRUCT class, line 3 +} +Point { + INSTANCEVARIABLE bar, line 10 + INSTANCEVARIABLE next, line 9 + STRUCT struct, line 7 + INSTANCEVARIABLE x, line 8 + INSTANCEVARIABLE y, line 8 +} + { +x , line: 17 +a Point, line: 18 +b Point, line: 18 +c Point pointer, line: 18 +} \ No newline at end of file diff --git a/autotest/CppParser/test2.in b/autotest/CppParser/test2.in new file mode 100644 index 000000000..f1215bde4 --- /dev/null +++ b/autotest/CppParser/test2.in @@ -0,0 +1,5 @@ +template +struct _CrtEnableIf +{ + typedef _Ty _Type; +}; diff --git a/autotest/CppParser/test2.out b/autotest/CppParser/test2.out new file mode 100644 index 000000000..6108603aa --- /dev/null +++ b/autotest/CppParser/test2.out @@ -0,0 +1,8 @@ +_CrtEnableIf { + STRUCTTEMPLATE struct, line 1 +} +_CrtEnableIf ::_Type { + TYPEDEF typedef, line 4 +} + { +} \ No newline at end of file diff --git a/autotest/SpinLock/SpinLock.upp b/autotest/SpinLock/SpinLock.upp index edcf19ab8..b0f93fa5b 100644 --- a/autotest/SpinLock/SpinLock.upp +++ b/autotest/SpinLock/SpinLock.upp @@ -2,7 +2,7 @@ uses Core; file - SpinLock.cpp; + SpinLock.cpp optimize_speed; mainconfig "" = "SSE2 MT";