Preprocessor: cleanup

This commit is contained in:
Daniel Marjamäki 2012-01-05 18:37:15 +01:00
parent c5f62c19d6
commit 07776e90ad
3 changed files with 31 additions and 31 deletions

View File

@ -104,7 +104,7 @@ static std::string unify(const std::string &s, char separator)
} }
/** Just read the code into a string. Perform simple cleanup of the code */ /** Just read the code into a string. Perform simple cleanup of the code */
std::string Preprocessor::read(std::istream &istr, const std::string &filename, Settings *settings) std::string Preprocessor::read(std::istream &istr, const std::string &filename)
{ {
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
// //
@ -164,7 +164,7 @@ std::string Preprocessor::read(std::istream &istr, const std::string &filename,
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
// //
// Remove all comments.. // Remove all comments..
result = removeComments(result, filename, settings); result = removeComments(result, filename, _settings);
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
// //
@ -756,7 +756,7 @@ void Preprocessor::preprocess(std::istream &srcCodeStream, std::string &processe
if (file0.empty()) if (file0.empty())
file0 = filename; file0 = filename;
processedFile = read(srcCodeStream, filename, _settings); processedFile = read(srcCodeStream, filename);
// Remove asm(...) // Remove asm(...)
removeAsm(processedFile); removeAsm(processedFile);
@ -1836,7 +1836,7 @@ std::string Preprocessor::handleIncludes(const std::string &code, const std::str
includes.push_back(filename); includes.push_back(filename);
ostr << "#file \"" << filename << "\"\n" ostr << "#file \"" << filename << "\"\n"
<< handleIncludes(read(fin, filename, NULL), filename, includePaths, defs, includes) << std::endl << handleIncludes(read(fin, filename), filename, includePaths, defs, includes) << std::endl
<< "#endfile\n"; << "#endfile\n";
continue; continue;
} }
@ -1909,7 +1909,7 @@ void Preprocessor::handleIncludes(std::string &code, const std::string &filePath
} }
handledFiles.insert(tempFile); handledFiles.insert(tempFile);
processedFile = Preprocessor::read(fin, filename, _settings); processedFile = Preprocessor::read(fin, filename);
fin.close(); fin.close();
} }

View File

@ -86,7 +86,7 @@ public:
void preprocess(std::istream &srcCodeStream, std::string &processedFile, std::list<std::string> &resultConfigurations, const std::string &filename, const std::list<std::string> &includePaths); void preprocess(std::istream &srcCodeStream, std::string &processedFile, std::list<std::string> &resultConfigurations, const std::string &filename, const std::list<std::string> &includePaths);
/** Just read the code into a string. Perform simple cleanup of the code */ /** Just read the code into a string. Perform simple cleanup of the code */
std::string read(std::istream &istr, const std::string &filename, Settings *settings); std::string read(std::istream &istr, const std::string &filename);
/** /**
* Get preprocessed code for a given configuration * Get preprocessed code for a given configuration

View File

@ -256,7 +256,7 @@ private:
Settings settings; Settings settings;
Preprocessor preprocessor(&settings, this); Preprocessor preprocessor(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
std::string codestr(preprocessor.read(istr,"test.c",0)); std::string codestr(preprocessor.read(istr,"test.c"));
ASSERT_EQUALS("a\n#aa b\n", codestr); ASSERT_EQUALS("a\n#aa b\n", codestr);
} }
@ -265,7 +265,7 @@ private:
Settings settings; Settings settings;
Preprocessor preprocessor(&settings, this); Preprocessor preprocessor(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
std::string codestr(preprocessor.read(istr,"test.c",0)); std::string codestr(preprocessor.read(istr,"test.c"));
ASSERT_EQUALS("\" \\\" /* abc */ \\n\"\n", codestr); ASSERT_EQUALS("\" \\\" /* abc */ \\n\"\n", codestr);
} }
@ -450,7 +450,7 @@ private:
std::istringstream istr(filedata); std::istringstream istr(filedata);
Settings settings; Settings settings;
Preprocessor preprocessor(&settings, this); Preprocessor preprocessor(&settings, this);
const std::string actual(preprocessor.read(istr, "test.c", 0)); const std::string actual(preprocessor.read(istr, "test.c"));
// Compare results.. // Compare results..
ASSERT_EQUALS("#if A\n#if A\n#if A\n#if defined(A)\n#elif defined(A)\n", actual); ASSERT_EQUALS("#if A\n#if A\n#if A\n#if defined(A)\n#elif defined(A)\n", actual);
@ -648,7 +648,7 @@ private:
std::istringstream istr(filedata); std::istringstream istr(filedata);
Settings settings; Settings settings;
Preprocessor preprocessor(&settings, this); Preprocessor preprocessor(&settings, this);
ASSERT_EQUALS("#error\n\n123", preprocessor.read(istr,"test.c",0)); ASSERT_EQUALS("#error\n\n123", preprocessor.read(istr,"test.c"));
} }
@ -692,13 +692,13 @@ private:
"A\n" "A\n"
"#endif\n" "#endif\n"
"B\n"); "B\n");
ASSERT_EQUALS("#if 0\n\n#endif\nB\n", preprocessor.read(code,"",NULL)); ASSERT_EQUALS("#if 0\n\n#endif\nB\n", preprocessor.read(code,""));
std::istringstream code2("#if (0)\n" std::istringstream code2("#if (0)\n"
"A\n" "A\n"
"#endif\n" "#endif\n"
"B\n"); "B\n");
ASSERT_EQUALS("#if 0\n\n#endif\nB\n", preprocessor.read(code2,"",NULL)); ASSERT_EQUALS("#if 0\n\n#endif\nB\n", preprocessor.read(code2,""));
} }
void if0_whitespace() { void if0_whitespace() {
@ -709,7 +709,7 @@ private:
"A\n" "A\n"
" # endif \n" " # endif \n"
"B\n"); "B\n");
ASSERT_EQUALS("#if 0\n\n#endif\nB\n", preprocessor.read(code,"",NULL)); ASSERT_EQUALS("#if 0\n\n#endif\nB\n", preprocessor.read(code,""));
} }
void if0_else() { void if0_else() {
@ -722,7 +722,7 @@ private:
"B\n" "B\n"
"#endif\n" "#endif\n"
"C\n"); "C\n");
ASSERT_EQUALS("#if 0\n\n#else\nB\n#endif\nC\n", preprocessor.read(code,"",NULL)); ASSERT_EQUALS("#if 0\n\n#else\nB\n#endif\nC\n", preprocessor.read(code,""));
std::istringstream code2("#if 1\n" std::istringstream code2("#if 1\n"
"A\n" "A\n"
@ -731,7 +731,7 @@ private:
"#endif\n" "#endif\n"
"C\n"); "C\n");
TODO_ASSERT_EQUALS("#if 1\nA\n#else\n\n#endif\nC\n", TODO_ASSERT_EQUALS("#if 1\nA\n#else\n\n#endif\nC\n",
"#if 1\nA\n#else\nB\n#endif\nC\n", preprocessor.read(code2,"",NULL)); "#if 1\nA\n#else\nB\n#endif\nC\n", preprocessor.read(code2,""));
} }
void if0_elif() { void if0_elif() {
@ -744,7 +744,7 @@ private:
"B\n" "B\n"
"#endif\n" "#endif\n"
"C\n"); "C\n");
ASSERT_EQUALS("#if 0\n\n#elif 1\nB\n#endif\nC\n", preprocessor.read(code,"",NULL)); ASSERT_EQUALS("#if 0\n\n#elif 1\nB\n#endif\nC\n", preprocessor.read(code,""));
} }
void if0_include_1() { void if0_include_1() {
@ -755,7 +755,7 @@ private:
"#include \"a.h\"\n" "#include \"a.h\"\n"
"#endif\n" "#endif\n"
"AB\n"); "AB\n");
ASSERT_EQUALS("#if 0\n\n#endif\nAB\n", preprocessor.read(code,"",NULL)); ASSERT_EQUALS("#if 0\n\n#endif\nAB\n", preprocessor.read(code,""));
} }
void if0_include_2() { void if0_include_2() {
@ -769,7 +769,7 @@ private:
"#endif\n" "#endif\n"
"#endif\n" "#endif\n"
"AB\n"); "AB\n");
ASSERT_EQUALS("#if 0\n\n#ifdef WIN32\n#else\n#endif\n#endif\nAB\n", preprocessor.read(code,"",NULL)); ASSERT_EQUALS("#if 0\n\n#ifdef WIN32\n#else\n#endif\n#endif\nAB\n", preprocessor.read(code,""));
} }
void includeguard1() { void includeguard1() {
@ -851,7 +851,7 @@ private:
std::istringstream istr(filedata); std::istringstream istr(filedata);
Settings settings; Settings settings;
Preprocessor preprocessor(&settings, this); Preprocessor preprocessor(&settings, this);
ASSERT_EQUALS("\n\n\n", preprocessor.read(istr, "test.c", 0)); ASSERT_EQUALS("\n\n\n", preprocessor.read(istr, "test.c"));
} }
@ -1477,7 +1477,7 @@ private:
std::istringstream istr(filedata); std::istringstream istr(filedata);
Settings settings; Settings settings;
Preprocessor preprocessor(&settings, this); Preprocessor preprocessor(&settings, this);
ASSERT_EQUALS("#define str \"abc\" \"def\"\n\nabcdef = str;\n", preprocessor.read(istr, "test.c", 0)); ASSERT_EQUALS("#define str \"abc\" \"def\"\n\nabcdef = str;\n", preprocessor.read(istr, "test.c"));
} }
void multiline2() { void multiline2() {
@ -1489,7 +1489,7 @@ private:
std::istringstream istr(filedata); std::istringstream istr(filedata);
Settings settings; Settings settings;
Preprocessor preprocessor(&settings, this); Preprocessor preprocessor(&settings, this);
ASSERT_EQUALS("#define sqr(aa) aa * aa\n\nsqr(5);\n", preprocessor.read(istr, "test.c", 0)); ASSERT_EQUALS("#define sqr(aa) aa * aa\n\nsqr(5);\n", preprocessor.read(istr, "test.c"));
} }
void multiline3() { void multiline3() {
@ -1501,7 +1501,7 @@ private:
std::istringstream istr(filedata); std::istringstream istr(filedata);
Settings settings; Settings settings;
Preprocessor preprocessor(&settings, this); Preprocessor preprocessor(&settings, this);
ASSERT_EQUALS("const char *str = \"abcdefghi\"\n\n\n", preprocessor.read(istr, "test.c", 0)); ASSERT_EQUALS("const char *str = \"abcdefghi\"\n\n\n", preprocessor.read(istr, "test.c"));
} }
void multiline4() { void multiline4() {
@ -2279,7 +2279,7 @@ private:
errout.str(""); errout.str("");
Settings settings; Settings settings;
Preprocessor preprocessor(&settings, this); Preprocessor preprocessor(&settings, this);
preprocessor.read(istr, "test.cpp", 0); preprocessor.read(istr, "test.cpp");
ASSERT_EQUALS("[test.cpp:1]: (error) The code contains characters that are unhandled. Neither unicode nor extended ASCII are supported. (line=1, character code=c8)\n", errout.str()); ASSERT_EQUALS("[test.cpp:1]: (error) The code contains characters that are unhandled. Neither unicode nor extended ASCII are supported. (line=1, character code=c8)\n", errout.str());
} }
@ -2288,7 +2288,7 @@ private:
std::istringstream istr(filedata); std::istringstream istr(filedata);
Settings settings; Settings settings;
Preprocessor preprocessor(&settings, this); Preprocessor preprocessor(&settings, this);
ASSERT_EQUALS("", preprocessor.read(istr, "test.cpp", 0)); ASSERT_EQUALS("", preprocessor.read(istr, "test.cpp"));
} }
void unicodeInString() { void unicodeInString() {
@ -2296,7 +2296,7 @@ private:
std::istringstream istr(filedata); std::istringstream istr(filedata);
Settings settings; Settings settings;
Preprocessor preprocessor(&settings, this); Preprocessor preprocessor(&settings, this);
ASSERT_EQUALS(filedata, preprocessor.read(istr, "test.cpp", 0)); ASSERT_EQUALS(filedata, preprocessor.read(istr, "test.cpp"));
} }
@ -2710,7 +2710,7 @@ private:
std::istringstream istr(filedata); std::istringstream istr(filedata);
Settings settings; Settings settings;
Preprocessor preprocessor(&settings, this); Preprocessor preprocessor(&settings, this);
ASSERT_EQUALS("#define FOO 1020", preprocessor.read(istr, "test.cpp", 0)); ASSERT_EQUALS("#define FOO 1020", preprocessor.read(istr, "test.cpp"));
} }
void testPreprocessorRead2() { void testPreprocessorRead2() {
@ -2718,7 +2718,7 @@ private:
std::istringstream istr(filedata); std::istringstream istr(filedata);
Settings settings; Settings settings;
Preprocessor preprocessor(&settings, this); Preprocessor preprocessor(&settings, this);
ASSERT_EQUALS("\"foo\\bar\"", preprocessor.read(istr, "test.cpp", 0)); ASSERT_EQUALS("\"foo\\bar\"", preprocessor.read(istr, "test.cpp"));
} }
void testPreprocessorRead3() { void testPreprocessorRead3() {
@ -2726,7 +2726,7 @@ private:
std::istringstream istr(filedata); std::istringstream istr(filedata);
Settings settings; Settings settings;
Preprocessor preprocessor(&settings, this); Preprocessor preprocessor(&settings, this);
ASSERT_EQUALS(filedata, preprocessor.read(istr, "test.cpp", 0)); ASSERT_EQUALS(filedata, preprocessor.read(istr, "test.cpp"));
} }
void testPreprocessorRead4() { void testPreprocessorRead4() {
@ -2736,7 +2736,7 @@ private:
std::istringstream istr(filedata); std::istringstream istr(filedata);
Settings settings; Settings settings;
Preprocessor preprocessor(&settings, this); Preprocessor preprocessor(&settings, this);
ASSERT_EQUALS("#define A \" \\\\\" \" \"", preprocessor.read(istr, "test.cpp", 0)); ASSERT_EQUALS("#define A \" \\\\\" \" \"", preprocessor.read(istr, "test.cpp"));
} }
{ {
@ -2745,7 +2745,7 @@ private:
std::istringstream istr(filedata); std::istringstream istr(filedata);
Settings settings; Settings settings;
Preprocessor preprocessor(&settings, this); Preprocessor preprocessor(&settings, this);
ASSERT_EQUALS("#define A \" \\\\\\\" \"", preprocessor.read(istr, "test.cpp", 0)); ASSERT_EQUALS("#define A \" \\\\\\\" \"", preprocessor.read(istr, "test.cpp"));
} }
{ {
@ -2754,7 +2754,7 @@ private:
std::istringstream istr(filedata); std::istringstream istr(filedata);
Settings settings; Settings settings;
Preprocessor preprocessor(&settings, this); Preprocessor preprocessor(&settings, this);
ASSERT_EQUALS("#define A \" \\\\\\\\\" \" \"", preprocessor.read(istr, "test.cpp", 0)); ASSERT_EQUALS("#define A \" \\\\\\\\\" \" \"", preprocessor.read(istr, "test.cpp"));
} }
} }