Fix testrunner InternalError
This commit is contained in:
parent
902eb87a8a
commit
e827119856
|
@ -585,9 +585,12 @@ static void compileTerm(Token *&tok, AST_state& state)
|
||||||
return;
|
return;
|
||||||
if (Token::Match(tok, "L %str%|%char%"))
|
if (Token::Match(tok, "L %str%|%char%"))
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
if (state.inArrayAssignment && tok->str() == "." && Token::Match(tok->previous(), ",|{")) // Jump over . in C style struct initialization
|
if (state.inArrayAssignment && Token::Match(tok->previous(), "[{,] . %name%")) { // Jump over . in C style struct initialization
|
||||||
tok = tok->next();
|
state.op.push(tok);
|
||||||
if (state.inArrayAssignment && Token::Match(tok->previous(), "[,{] [ %num% ]")) {
|
tok->astOperand1(tok->next());
|
||||||
|
tok = tok->tokAt(2);
|
||||||
|
}
|
||||||
|
if (state.inArrayAssignment && Token::Match(tok->previous(), "[{,] [ %num% ]")) {
|
||||||
state.op.push(tok);
|
state.op.push(tok);
|
||||||
tok->astOperand1(tok->next());
|
tok->astOperand1(tok->next());
|
||||||
tok = tok->tokAt(3);
|
tok = tok->tokAt(3);
|
||||||
|
@ -624,20 +627,20 @@ static void compileTerm(Token *&tok, AST_state& state)
|
||||||
}
|
}
|
||||||
} else if (tok->str() == "{") {
|
} else if (tok->str() == "{") {
|
||||||
const Token *prev = tok->previous();
|
const Token *prev = tok->previous();
|
||||||
if (prev && prev->str() == ")")
|
if (Token::simpleMatch(prev, ") {") && iscast(prev->link()))
|
||||||
prev = prev->link()->previous();
|
prev = prev->link()->previous();
|
||||||
if (Token::simpleMatch(tok->link(),"} [")) {
|
if (Token::simpleMatch(tok->link(),"} [")) {
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
} else if (tok->previous() && tok->previous()->isName()) {
|
} else if (tok->previous() && tok->previous()->isName()) {
|
||||||
compileBinOp(tok, state, compileExpression);
|
compileBinOp(tok, state, compileExpression);
|
||||||
} else if (!state.inArrayAssignment && (!prev || prev->str() != "=")) {
|
} else if (!state.inArrayAssignment && !Token::simpleMatch(prev, "=")) {
|
||||||
state.op.push(tok);
|
state.op.push(tok);
|
||||||
tok = tok->link()->next();
|
tok = tok->link()->next();
|
||||||
} else {
|
} else {
|
||||||
if (tok->link() != tok->next()) {
|
if (tok->link() != tok->next()) {
|
||||||
state.inArrayAssignment++;
|
state.inArrayAssignment++;
|
||||||
compileUnaryOp(tok, state, compileExpression);
|
compileUnaryOp(tok, state, compileExpression);
|
||||||
while (Token::Match(tok, "} [,}]") && state.inArrayAssignment > 0U) {
|
while (Token::Match(tok, "} [,};]") && state.inArrayAssignment > 0U) {
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
state.inArrayAssignment--;
|
state.inArrayAssignment--;
|
||||||
}
|
}
|
||||||
|
@ -1032,6 +1035,8 @@ static void createAstAtTokenInner(Token * const tok1, const Token *endToken, boo
|
||||||
{
|
{
|
||||||
for (Token *tok = tok1; tok && tok != endToken; tok = tok ? tok->next() : nullptr) {
|
for (Token *tok = tok1; tok && tok != endToken; tok = tok ? tok->next() : nullptr) {
|
||||||
if (tok->str() == "{" && !iscpp11init(tok)) {
|
if (tok->str() == "{" && !iscpp11init(tok)) {
|
||||||
|
if (Token::simpleMatch(tok->astOperand1(), ","))
|
||||||
|
continue;
|
||||||
if (Token::simpleMatch(tok->previous(), "( {"))
|
if (Token::simpleMatch(tok->previous(), "( {"))
|
||||||
;
|
;
|
||||||
// struct assignment
|
// struct assignment
|
||||||
|
|
|
@ -8063,7 +8063,7 @@ private:
|
||||||
ASSERT_EQUALS("QT_WA{{,( x0= QT_WA{{,( x1= x2=",
|
ASSERT_EQUALS("QT_WA{{,( x0= QT_WA{{,( x1= x2=",
|
||||||
testAst("QT_WA({},{x=0;});" // don't hang
|
testAst("QT_WA({},{x=0;});" // don't hang
|
||||||
"QT_WA({x=1;},{x=2;});"));
|
"QT_WA({x=1;},{x=2;});"));
|
||||||
ASSERT_EQUALS("xMACROtypeT=value1=,{({=",
|
ASSERT_EQUALS("xMACROtype.T=value.1=,{({=",
|
||||||
testAst("x = { MACRO( { .type=T, .value=1 } ) }")); // don't hang: MACRO({..})
|
testAst("x = { MACRO( { .type=T, .value=1 } ) }")); // don't hang: MACRO({..})
|
||||||
ASSERT_EQUALS("fori10=i{;;( i--", testAst("for (i=10;i;({i--;}) ) {}"));
|
ASSERT_EQUALS("fori10=i{;;( i--", testAst("for (i=10;i;({i--;}) ) {}"));
|
||||||
|
|
||||||
|
@ -8072,14 +8072,14 @@ private:
|
||||||
|
|
||||||
// struct initialization
|
// struct initialization
|
||||||
ASSERT_EQUALS("name_bytes[bits~unusedBits>>unusedBits<<{=", testAst("const uint8_t name_bytes[] = { (~bits >> unusedBits) << unusedBits };"));
|
ASSERT_EQUALS("name_bytes[bits~unusedBits>>unusedBits<<{=", testAst("const uint8_t name_bytes[] = { (~bits >> unusedBits) << unusedBits };"));
|
||||||
ASSERT_EQUALS("abuf0{={=", testAst("a = { .buf = { 0 } };"));
|
ASSERT_EQUALS("abuf.0{={=", testAst("a = { .buf = { 0 } };"));
|
||||||
ASSERT_EQUALS("ab2[a0=b0=,{a0=b0=,{,{=", testAst("struct AB ab[2] = { { .a=0, .b=0 }, { .a=0, .b=0 } };"));
|
ASSERT_EQUALS("ab2[a.0=b.0=,{a.0=b.0=,{,{=", testAst("struct AB ab[2] = { { .a=0, .b=0 }, { .a=0, .b=0 } };"));
|
||||||
ASSERT_EQUALS("tset{=", testAst("struct cgroup_taskset tset = {};"));
|
ASSERT_EQUALS("tset{=", testAst("struct cgroup_taskset tset = {};"));
|
||||||
ASSERT_EQUALS("s1a&,{2b&,{,{=", testAst("s = { {1, &a}, {2, &b} };"));
|
ASSERT_EQUALS("s1a&,{2b&,{,{=", testAst("s = { {1, &a}, {2, &b} };"));
|
||||||
ASSERT_EQUALS("s0[L.2[x={=", testAst("s = { [0].L[2] = x};"));
|
ASSERT_EQUALS("s0[L.2[x={=", testAst("s = { [0].L[2] = x};"));
|
||||||
|
|
||||||
// struct initialization hang
|
// struct initialization hang
|
||||||
ASSERT_EQUALS("sbar1{,{(={= fcmd( forfieldfield++;;(",
|
ASSERT_EQUALS("sbar.1{,{(={= fcmd( forfieldfield++;;(",
|
||||||
testAst("struct S s = {.bar = (struct foo) { 1, { } } };\n"
|
testAst("struct S s = {.bar = (struct foo) { 1, { } } };\n"
|
||||||
"void f(struct cmd *) { for (; field; field++) {} }"));
|
"void f(struct cmd *) { for (; field; field++) {} }"));
|
||||||
|
|
||||||
|
@ -8163,6 +8163,7 @@ private:
|
||||||
ASSERT_EQUALS("ac(=", testAst("a = (::b)c;"));
|
ASSERT_EQUALS("ac(=", testAst("a = (::b)c;"));
|
||||||
ASSERT_EQUALS("abcd,({(=", testAst("a = (s){b(c, d)};"));
|
ASSERT_EQUALS("abcd,({(=", testAst("a = (s){b(c, d)};"));
|
||||||
ASSERT_EQUALS("xatoistr({(=", testAst("x = (struct X){atoi(str)};"));
|
ASSERT_EQUALS("xatoistr({(=", testAst("x = (struct X){atoi(str)};"));
|
||||||
|
ASSERT_EQUALS("xa.0=b.0=,c.0=,{(=", testAst("x = (struct abc) { .a=0, .b=0, .c=0 };"));
|
||||||
|
|
||||||
// not cast
|
// not cast
|
||||||
ASSERT_EQUALS("AB||", testAst("(A)||(B)"));
|
ASSERT_EQUALS("AB||", testAst("(A)||(B)"));
|
||||||
|
|
Loading…
Reference in New Issue