forked from qt-creator/qt-creator
C++: Fix preprocessing of comments within function-like macro
Task-number: QTCREATORBUG-9535 Change-Id: Ifd94f674214314b3694be74cca297ddab873cd8c Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
This commit is contained in:
committed by
Orgad Shaneh
parent
2a2d0a0c44
commit
a341094a68
@@ -1631,6 +1631,123 @@ void tst_Preprocessor::comments_within_data()
|
||||
"# 12 \"<stdin>\"\n"
|
||||
"int foo = 4;"
|
||||
);
|
||||
|
||||
QTest::newRow("inside_function_like_macro") << _(
|
||||
"#define /* comment */ ASSIGN1(VAR, VALUE) VAR = VALUE\n"
|
||||
"#define ASSIGN2(/* comment */ VAR, VALUE) VAR = VALUE\n"
|
||||
"#define ASSIGN3(VAR /* comment */, VALUE) VAR = VALUE\n"
|
||||
"#define ASSIGN4(VAR, /* comment */ VALUE) VAR = VALUE\n"
|
||||
"#define ASSIGN5(VAR, VALUE /* comment */) VAR = VALUE\n"
|
||||
"#define ASSIGN6(VAR, VALUE) /* comment */ VAR = VALUE\n"
|
||||
"#define ASSIGN7(VAR, ... /* comment */) VAR\n"
|
||||
"void func()\n"
|
||||
"{\n"
|
||||
" int i;\n"
|
||||
" ASSIGN1(i, 3);\n"
|
||||
" ASSIGN2(i, 3);\n"
|
||||
" ASSIGN3(i, 3);\n"
|
||||
" ASSIGN4(i, 3);\n"
|
||||
" ASSIGN5(i, 3);\n"
|
||||
" ASSIGN6(i, 3);\n"
|
||||
" ASSIGN7(i, 3);\n"
|
||||
"}\n"
|
||||
) << _(
|
||||
"# 1 \"<stdin>\"\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"void func()\n"
|
||||
"{\n"
|
||||
" int i;\n"
|
||||
"# expansion begin 397,7 11:12 ~1 11:15\n"
|
||||
"i = 3\n"
|
||||
"# expansion end\n"
|
||||
"# 11 \"<stdin>\"\n"
|
||||
" ;\n"
|
||||
"# expansion begin 416,7 12:12 ~1 12:15\n"
|
||||
"i = 3\n"
|
||||
"# expansion end\n"
|
||||
"# 12 \"<stdin>\"\n"
|
||||
" ;\n"
|
||||
"# expansion begin 435,7 13:12 ~1 13:15\n"
|
||||
"i = 3\n"
|
||||
"# expansion end\n"
|
||||
"# 13 \"<stdin>\"\n"
|
||||
" ;\n"
|
||||
"# expansion begin 454,7 14:12 ~1 14:15\n"
|
||||
"i = 3\n"
|
||||
"# expansion end\n"
|
||||
"# 14 \"<stdin>\"\n"
|
||||
" ;\n"
|
||||
"# expansion begin 473,7 15:12 ~1 15:15\n"
|
||||
"i = 3\n"
|
||||
"# expansion end\n"
|
||||
"# 15 \"<stdin>\"\n"
|
||||
" ;\n"
|
||||
"# expansion begin 492,7 16:12 ~1 16:15\n"
|
||||
"i = 3\n"
|
||||
"# expansion end\n"
|
||||
"# 16 \"<stdin>\"\n"
|
||||
" ;\n"
|
||||
"# expansion begin 511,7 17:12\n"
|
||||
"i\n"
|
||||
"# expansion end\n"
|
||||
"# 17 \"<stdin>\"\n"
|
||||
" ;\n"
|
||||
"}\n"
|
||||
) << _(
|
||||
"# 1 \"<stdin>\"\n"
|
||||
" /* comment */\n"
|
||||
" /* comment */\n"
|
||||
" /* comment */\n"
|
||||
" /* comment */\n"
|
||||
" /* comment */\n"
|
||||
" /* comment */\n"
|
||||
" /* comment */\n"
|
||||
"void func()\n"
|
||||
"{\n"
|
||||
" int i;\n"
|
||||
"# expansion begin 397,7 11:12 ~1 11:15\n"
|
||||
"i = 3\n"
|
||||
"# expansion end\n"
|
||||
"# 11 \"<stdin>\"\n"
|
||||
" ;\n"
|
||||
"# expansion begin 416,7 12:12 ~1 12:15\n"
|
||||
"i = 3\n"
|
||||
"# expansion end\n"
|
||||
"# 12 \"<stdin>\"\n"
|
||||
" ;\n"
|
||||
"# expansion begin 435,7 13:12 ~1 13:15\n"
|
||||
"i = 3\n"
|
||||
"# expansion end\n"
|
||||
"# 13 \"<stdin>\"\n"
|
||||
" ;\n"
|
||||
"# expansion begin 454,7 14:12 ~1 14:15\n"
|
||||
"i = 3\n"
|
||||
"# expansion end\n"
|
||||
"# 14 \"<stdin>\"\n"
|
||||
" ;\n"
|
||||
"# expansion begin 473,7 15:12 ~1 15:15\n"
|
||||
"i = 3\n"
|
||||
"# expansion end\n"
|
||||
"# 15 \"<stdin>\"\n"
|
||||
" ;\n"
|
||||
"# expansion begin 492,7 16:12 ~1 16:15\n"
|
||||
"i = 3\n"
|
||||
"# expansion end\n"
|
||||
"# 16 \"<stdin>\"\n"
|
||||
" ;\n"
|
||||
"# expansion begin 511,7 17:12\n"
|
||||
"i\n"
|
||||
"# expansion end\n"
|
||||
"# 17 \"<stdin>\"\n"
|
||||
" ;\n"
|
||||
"}\n"
|
||||
);
|
||||
}
|
||||
|
||||
void tst_Preprocessor::comments_before_args()
|
||||
@@ -1641,17 +1758,32 @@ void tst_Preprocessor::comments_before_args()
|
||||
Preprocessor preprocess(client, &env);
|
||||
preprocess.setKeepComments(true);
|
||||
QByteArray preprocessed = preprocess.run(QLatin1String("<stdin>"),
|
||||
"\n#define foo(a,b) int a = b;"
|
||||
"\nfoo/*C comment*/(a,1)\n"
|
||||
"\nfoo/**Doxygen comment*/(b,2)\n"
|
||||
"\nfoo//C++ comment\n(c,3)\n"
|
||||
"\nfoo///Doxygen C++ comment\n(d,4)\n"
|
||||
"\nfoo/*multiple*///comments\n/**as well*/(e,5)\n",
|
||||
"#define foo(a,b) int a = b;\n"
|
||||
"foo/*C comment*/(a,1)\n"
|
||||
"foo/**Doxygen comment*/(b,2)\n"
|
||||
"foo//C++ comment\n"
|
||||
"(c,3)\n"
|
||||
"foo///Doxygen C++ comment\n"
|
||||
"(d,4)\n"
|
||||
"foo/*multiple*///comments\n"
|
||||
"/**as well*/(e,5)\n",
|
||||
true, false);
|
||||
|
||||
preprocessed = preprocessed.simplified();
|
||||
// DUMP_OUTPUT(preprocessed);
|
||||
QVERIFY(compare(simplified(preprocessed), "int a=1;int b=2;int c=3;int d=4;int e=5;"));
|
||||
QByteArray expected =
|
||||
"\n"
|
||||
" /*C comment*/int a = 1;\n"
|
||||
" /**Doxygen comment*/int b = 2;\n"
|
||||
" //C++ comment\n"
|
||||
"int\n"
|
||||
"c = 3;\n"
|
||||
" ///Doxygen C++ comment\n"
|
||||
"int\n"
|
||||
"d = 4;\n"
|
||||
" /*multiple*/ //comments\n"
|
||||
"/**as well*/ int\n"
|
||||
"e = 5;\n";
|
||||
QVERIFY(compare(preprocessed, expected));
|
||||
}
|
||||
|
||||
void tst_Preprocessor::multiline_strings()
|
||||
|
Reference in New Issue
Block a user