Commit 6d393252 authored by hjk's avatar hjk Committed by hjk

preprocessor: rename operator() into run.

Easier to follow.

Change-Id: I6da1ca862ddb7048a6d16bf5e6ea18d6b2cfc7f8
Reviewed-by: default avatarhjk <qthjk@ovi.com>
parent 6d837b62
......@@ -55,7 +55,7 @@ QByteArray FastPreprocessor::run(QString fileName, const QString &source)
mergeEnvironment(i.fileName());
}
const QByteArray preprocessed = _preproc(fileName, source);
const QByteArray preprocessed = _preproc.run(fileName, source);
// qDebug("FastPreprocessor::run for %s produced [[%s]]", fileName.toUtf8().constData(), preprocessed.constData());
return preprocessed;
}
......
......@@ -210,5 +210,5 @@ QByteArray TypeOfExpression::preprocessedExpression(const QByteArray &utf8code)
}
Preprocessor preproc(0, m_environment.data());
return preproc("<expression>", utf8code);
return preproc.run("<expression>", utf8code);
}
......@@ -583,17 +583,15 @@ Preprocessor::Preprocessor(Client *client, Environment *env)
{
}
QByteArray Preprocessor::operator()(const QString &fileName, const QString &source)
QByteArray Preprocessor::run(const QString &fileName, const QString &source)
{
const QByteArray bytes = source.toLatin1();
const QByteArray preprocessedCode = operator()(fileName, bytes);
return preprocessedCode;
return run(fileName, source.toLatin1());
}
QByteArray Preprocessor::operator()(const QString &fileName,
const QByteArray &source,
bool noLines,
bool markGeneratedTokens)
QByteArray Preprocessor::run(const QString &fileName,
const QByteArray &source,
bool noLines,
bool markGeneratedTokens)
{
QByteArray preprocessed;
// qDebug()<<"running" << fileName<<"with"<<source.count('\n')<<"lines...";
......
......@@ -79,8 +79,8 @@ class CPLUSPLUS_EXPORT Preprocessor
public:
Preprocessor(Client *client, Environment *env);
QByteArray operator()(const QString &filename, const QString &source);
QByteArray operator()(const QString &filename, const QByteArray &source, bool noLines = false, bool markGeneratedTokens = true);
QByteArray run(const QString &filename, const QString &source);
QByteArray run(const QString &filename, const QByteArray &source, bool noLines = false, bool markGeneratedTokens = true);
bool expandMacros() const;
void setExpandMacros(bool expandMacros);
......
......@@ -623,7 +623,7 @@ void CppPreprocessor::sourceNeeded(QString &fileName, IncludeType type, unsigned
Document::Ptr previousDoc = switchDocument(doc);
const QByteArray preprocessedCode = preprocess(fileName, contents);
const QByteArray preprocessedCode = preprocess.run(fileName, contents);
// { QByteArray b(preprocessedCode); b.replace("\n", "<<<\n"); qDebug("Preprocessed code for \"%s\": [[%s]]", fileName.toUtf8().constData(), b.constData()); }
......
......@@ -204,7 +204,7 @@ public:
{
QByteArray src = loadSource(fileName);
QVERIFY(!src.isEmpty());
*m_output = m_pp(fileName, src, nolines, true);
*m_output = m_pp.run(fileName, src, nolines, true);
}
QList<Block> skippedBlocks() const
......@@ -341,13 +341,12 @@ void tst_Preprocessor::va_args()
Environment env;
Preprocessor preprocess(client, &env);
QByteArray preprocessed = preprocess(QLatin1String("<stdin>"),
QByteArray("#define foo(...) int f(__VA_ARGS__);\n"
"\nfoo( )\n"
"\nfoo(int a)\n"
"\nfoo(int a,int b)\n"),
true,
false);
QByteArray preprocessed = preprocess.run(QLatin1String("<stdin>"),
"#define foo(...) int f(__VA_ARGS__);\n"
"\nfoo( )\n"
"\nfoo(int a)\n"
"\nfoo(int a,int b)\n",
true, false);
preprocessed = preprocessed.simplified();
// DUMP_OUTPUT(preprocessed);
......@@ -360,12 +359,12 @@ void tst_Preprocessor::named_va_args()
Environment env;
Preprocessor preprocess(client, &env);
QByteArray preprocessed = preprocess(QLatin1String("<stdin>"),
QByteArray("\n#define foo(ARGS...) int f(ARGS);"
"\nfoo( )\n"
"\nfoo(int a)\n"
"\nfoo(int a,int b)\n"),
true, false);
QByteArray preprocessed = preprocess.run(QLatin1String("<stdin>"),
"\n#define foo(ARGS...) int f(ARGS);"
"\nfoo( )\n"
"\nfoo(int a)\n"
"\nfoo(int a,int b)\n",
true, false);
preprocessed = preprocessed.simplified();
QCOMPARE(simplified(preprocessed), QString("int f();int f(int a);int f(int a,int b);"));
......@@ -377,12 +376,12 @@ void tst_Preprocessor::first_empty_macro_arg()
Environment env;
Preprocessor preprocess(client, &env);
QByteArray preprocessed = preprocess(QLatin1String("<stdin>"),
QByteArray("\n#define foo(a,b) a int b;"
"\nfoo(const,cVal)\n"
"\nfoo(,Val)\n"
"\nfoo( ,Val2)\n"),
true, false);
QByteArray preprocessed = preprocess.run(QLatin1String("<stdin>"),
"\n#define foo(a,b) a int b;"
"\nfoo(const,cVal)\n"
"\nfoo(,Val)\n"
"\nfoo( ,Val2)\n",
true, false);
preprocessed = preprocessed.simplified();
// DUMP_OUTPUT(preprocessed);
......@@ -397,11 +396,11 @@ void tst_Preprocessor::invalid_param_count()
Preprocessor preprocess(client, &env);
// The following is illegal, but shouldn't crash the preprocessor.
// GCC says: 3:14: error: macro "foo" requires 2 arguments, but only 1 given
QByteArray preprocessed = preprocess(QLatin1String("<stdin>"),
QByteArray("\n#define foo(a,b) int f(a,b);"
"\n#define ARGS(t) t a,t b"
"\nfoo(ARGS(int))"),
true, false);
QByteArray preprocessed = preprocess.run(QLatin1String("<stdin>"),
"\n#define foo(a,b) int f(a,b);"
"\n#define ARGS(t) t a,t b"
"\nfoo(ARGS(int))",
true, false);
// do not verify the output: it's illegal, so anything might be outputted.
}
......@@ -411,10 +410,11 @@ void tst_Preprocessor::param_expanding_as_multiple_params()
Environment env;
Preprocessor preprocess(client, &env);
QByteArray preprocessed = preprocess(QLatin1String("<stdin>"),
QByteArray("\n#define foo(a,b) int f(a,b);"
"\n#define ARGS(t) t a,t b"
"\nfoo(ARGS(int))"));
QByteArray preprocessed = preprocess.run(QLatin1String("<stdin>"),
"\n#define foo(a,b) int f(a,b);"
"\n#define ARGS(t) t a,t b"
"\nfoo(ARGS(int))",
false, true);
QCOMPARE(simplified(preprocessed), QString("int f(int a,int b);"));
}
......@@ -424,12 +424,13 @@ void tst_Preprocessor::macro_argument_expansion() //QTCREATORBUG-7225
Environment env;
Preprocessor preprocess(client, &env);
QByteArray preprocessed = preprocess(QLatin1String("<stdin>"),
QByteArray("\n#define BAR1 2,3,4"
"\n#define FOO1(a,b,c) a+b+c"
"\nvoid test2(){"
"\nint x=FOO1(BAR1);"
"\n}"));
QByteArray preprocessed = preprocess.run(QLatin1String("<stdin>"),
"\n#define BAR1 2,3,4"
"\n#define FOO1(a,b,c) a+b+c"
"\nvoid test2(){"
"\nint x=FOO1(BAR1);"
"\n}",
false, true);
QCOMPARE(simplified(preprocessed), QString("void test2(){int x=2+3+4;}"));
}
......@@ -448,7 +449,7 @@ void tst_Preprocessor::macro_uses()
MockClient client(&env, &output);
Preprocessor preprocess(&client, &env);
QByteArray preprocessed = preprocess(QLatin1String("<stdin>"), buffer);
QByteArray preprocessed = preprocess.run(QLatin1String("<stdin>"), buffer);
QCOMPARE(simplified(preprocessed), QString("void test(){int x=8;int y=9;}"));
QCOMPARE(client.expandedMacros(), QList<QByteArray>() << QByteArray("FOO") << QByteArray("BAR"));
QCOMPARE(client.expandedMacrosOffset(), QList<unsigned>() << buffer.indexOf("FOO;") << buffer.indexOf("BAR;"));
......@@ -461,29 +462,29 @@ void tst_Preprocessor::macro_definition_lineno()
Client *client = 0; // no client.
Environment env;
Preprocessor preprocess(client, &env);
QByteArray preprocessed = preprocess(QLatin1String("<stdin>"),
QByteArray preprocessed = preprocess.run(QLatin1String("<stdin>"),
QByteArray("#define foo(ARGS) int f(ARGS)\n"
"foo(int a);\n"));
QVERIFY(preprocessed.contains("#gen true\n# 2 \"<stdin>\"\nint f"));
preprocessed = preprocess(QLatin1String("<stdin>"),
preprocessed = preprocess.run(QLatin1String("<stdin>"),
QByteArray("#define foo(ARGS) int f(ARGS)\n"
"foo(int a)\n"
";\n"));
QVERIFY(preprocessed.contains("#gen true\n# 2 \"<stdin>\"\nint f"));
preprocessed = preprocess(QLatin1String("<stdin>"),
preprocessed = preprocess.run(QLatin1String("<stdin>"),
QByteArray("#define foo(ARGS) int f(ARGS)\n"
"foo(int \n"
" a);\n"));
QVERIFY(preprocessed.contains("#gen true\n# 2 \"<stdin>\"\nint f"));
preprocessed = preprocess(QLatin1String("<stdin>"),
preprocessed = preprocess.run(QLatin1String("<stdin>"),
QByteArray("#define foo int f\n"
"foo;\n"));
QVERIFY(preprocessed.contains("#gen true\n# 2 \"<stdin>\"\nint f"));
preprocessed = preprocess(QLatin1String("<stdin>"),
preprocessed = preprocess.run(QLatin1String("<stdin>"),
QByteArray("#define foo int f\n"
"foo\n"
";\n"));
......@@ -497,7 +498,7 @@ void tst_Preprocessor::objmacro_expanding_as_fnmacro_notification()
MockClient client(&env, &output);
Preprocessor preprocess(&client, &env);
QByteArray preprocessed = preprocess(QLatin1String("<stdin>"),
QByteArray preprocessed = preprocess.run(QLatin1String("<stdin>"),
QByteArray("\n#define bar(a,b) a + b"
"\n#define foo bar"
"\nfoo(1, 2)\n"));
......@@ -512,7 +513,7 @@ void tst_Preprocessor::macro_arguments_notificatin()
MockClient client(&env, &output);
Preprocessor preprocess(&client, &env);
QByteArray preprocessed = preprocess(QLatin1String("<stdin>"),
QByteArray preprocessed = preprocess.run(QLatin1String("<stdin>"),
QByteArray("\n#define foo(a,b) a + b"
"\n#define arg(a) a"
"\n#define value 2"
......@@ -529,7 +530,7 @@ void tst_Preprocessor::unfinished_function_like_macro_call()
Environment env;
Preprocessor preprocess(client, &env);
QByteArray preprocessed = preprocess(QLatin1String("<stdin>"),
QByteArray preprocessed = preprocess.run(QLatin1String("<stdin>"),
QByteArray("\n#define foo(a,b) a + b"
"\nfoo(1, 2\n"));
QByteArray expected__("# 1 \"<stdin>\"\n\n\n 1\n#gen true\n# 2 \"<stdin>\"\n+\n#gen false\n# 3 \"<stdin>\"\n 2\n");
......@@ -585,7 +586,7 @@ void tst_Preprocessor::nasty_macro_expansion()
Environment env;
Preprocessor preprocess(client, &env);
QByteArray preprocessed = preprocess(QLatin1String("<stdin>"), input);
QByteArray preprocessed = preprocess.run(QLatin1String("<stdin>"), input);
QVERIFY(!preprocessed.contains("FIELD32"));
}
......@@ -596,7 +597,7 @@ void tst_Preprocessor::tstst()
Environment env;
Preprocessor preprocess(client, &env);
QByteArray preprocessed = preprocess(
QByteArray preprocessed = preprocess.run(
QLatin1String("<stdin>"),
QByteArray("\n"
"# define _GLIBCXX_VISIBILITY(V) __attribute__ ((__visibility__ (#V)))\n"
......@@ -626,7 +627,7 @@ void tst_Preprocessor::test_file_builtin()
Environment env;
Preprocessor preprocess(client, &env);
QByteArray preprocessed = preprocess(
QByteArray preprocessed = preprocess.run(
QLatin1String("some-file.c"),
QByteArray("const char *f = __FILE__\n"
));
......@@ -692,7 +693,7 @@ void tst_Preprocessor::blockSkipping()
Environment env;
MockClient client(&env, &output);
Preprocessor pp(&client, &env);
/*QByteArray preprocessed =*/ pp(
/*QByteArray preprocessed =*/ pp.run(
QLatin1String("<stdin>"),
QByteArray("#if 0\n"
"\n"
......@@ -722,7 +723,7 @@ void tst_Preprocessor::includes_1()
Environment env;
MockClient client(&env, &output);
Preprocessor pp(&client, &env);
/*QByteArray preprocessed =*/ pp(
/*QByteArray preprocessed =*/ pp.run(
QLatin1String("<stdin>"),
QByteArray("#define FOO <foo.h>\n"
"#define BAR \"bar.h\"\n"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment