Commit 55d0e4f8 authored by Roberto Raggi's avatar Roberto Raggi
Browse files

Improved the way we expand function-like macros when we can't collect all the arguments.

parent 656d70fa
...@@ -810,9 +810,8 @@ void Preprocessor::preprocess(const QByteArray &fileName, const QByteArray &sour ...@@ -810,9 +810,8 @@ void Preprocessor::preprocess(const QByteArray &fileName, const QByteArray &sour
++_dot; ++_dot;
} }
if (_dot->isNot(T_RPAREN)) { if (_dot->isNot(T_RPAREN))
// ### warning expected T_RPAREN _result->append(spell);
}
else else
expandFunctionLikeMacro(identifierToken, m); expandFunctionLikeMacro(identifierToken, m);
......
#include <QtTest> #include <QtTest>
#include <pp.h> #include <pp.h>
CPLUSPLUS_USE_NAMESPACE using namespace CPlusPlus;
class tst_Preprocessor: public QObject class tst_Preprocessor: public QObject
{ {
...@@ -9,21 +9,35 @@ Q_OBJECT ...@@ -9,21 +9,35 @@ Q_OBJECT
private Q_SLOTS: private Q_SLOTS:
void pp_with_no_client(); void pp_with_no_client();
void unfinished_function_like_macro_call();
}; };
void tst_Preprocessor::pp_with_no_client() void tst_Preprocessor::pp_with_no_client()
{ {
using namespace CPlusPlus;
Client *client = 0; // no client. Client *client = 0; // no client.
Environment env; Environment env;
Preprocessor preprocess(client, &env); Preprocessor preprocess(client, &env);
QByteArray preprocessed = preprocess("<stdin>", QByteArray preprocessed = preprocess("<stdin>",
"#define foo(a,b) a + b\nfoo(1, 2)\n"); "\n#define foo(a,b) a + b"
"\nfoo(1, 2)\n");
QByteArray expected = "1 + 2"; QByteArray expected = "1 + 2";
QCOMPARE(preprocessed.trimmed(), expected); QCOMPARE(preprocessed.trimmed(), expected);
} }
void tst_Preprocessor::unfinished_function_like_macro_call()
{
Client *client = 0; // no client.
Environment env;
Preprocessor preprocess(client, &env);
QByteArray preprocessed = preprocess("<stdin>",
"\n#define foo(a,b) a + b"
"\nfoo(1, 2\n");
QByteArray expected = "foo";
QCOMPARE(preprocessed.trimmed(), expected);
}
QTEST_APPLESS_MAIN(tst_Preprocessor) QTEST_APPLESS_MAIN(tst_Preprocessor)
#include "tst_preprocessor.moc" #include "tst_preprocessor.moc"
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