JavaScript: fix handling of various missing semicolons in loops

This commit is contained in:
Colomban Wendling 2014-08-03 23:24:33 +02:00
parent 3ff01aeeb3
commit 35e8fbbe28
3 changed files with 75 additions and 6 deletions

View File

@ -709,7 +709,7 @@ static void parseSwitch (tokenInfo *const token)
}
static void parseLoop (tokenInfo *const token)
static boolean parseLoop (tokenInfo *const token)
{
/*
* Handles these statements
@ -732,6 +732,7 @@ static void parseLoop (tokenInfo *const token)
* }
* while (number<5);
*/
boolean is_terminated = TRUE;
if (isKeyword (token, KEYWORD_for) || isKeyword (token, KEYWORD_while))
{
@ -758,7 +759,7 @@ static void parseLoop (tokenInfo *const token)
}
else
{
parseLine(token, FALSE);
is_terminated = parseLine(token, FALSE);
}
}
else if (isKeyword (token, KEYWORD_do))
@ -777,9 +778,10 @@ static void parseLoop (tokenInfo *const token)
}
else
{
parseLine(token, FALSE);
is_terminated = parseLine(token, FALSE);
}
if (is_terminated)
readToken(token);
if (isKeyword (token, KEYWORD_while))
@ -794,8 +796,12 @@ static void parseLoop (tokenInfo *const token)
*/
skipArgumentList(token);
}
if (! isType (token, TOKEN_SEMICOLON))
is_terminated = FALSE;
}
}
return is_terminated;
}
static boolean parseIf (tokenInfo *const token)
@ -1654,7 +1660,7 @@ static boolean parseLine (tokenInfo *const token, boolean is_inside_class)
case KEYWORD_for:
case KEYWORD_while:
case KEYWORD_do:
parseLoop (token);
is_terminated = parseLoop (token);
break;
case KEYWORD_if:
case KEYWORD_else:

View File

@ -1,5 +1,5 @@
// All these examples contain various forms of IF statements
// All these examples contain various forms of statements
// with missing semicolons. Each of these are valid and must
// be accommodated.
//
@ -7,6 +7,9 @@
// The following tags should be generated:
// functions
// a
// aa
// aa_sub1 [aa]
// aa_sub2 [aa]
// b
// baz [f]
// c
@ -32,6 +35,15 @@
// w
// w_sub1 [w]
// w_sub2 [w]
// x
// x_sub1 [x]
// x_sub2 [x]
// y
// y_sub1 [y]
// y_sub2 [y]
// z
// z_sub1 [z]
// z_sub2 [z]
// classes
// MyClass
// methods
@ -189,3 +201,42 @@ MyClass = {
var dummy5 = 42;
}
};
function x(){
function x_sub1(){
while (1)
x_sub2()
}
function x_sub2(){
}
}
function y(){
function y_sub1(){
while (1) {
y_sub2()
}
}
function y_sub2(){
}
}
function z(){
function z_sub1(){
do {
z_sub2()
} while (0)
}
function z_sub2(){
}
}
function aa(){
function aa_sub1(){
do
aa_sub2()
while (0)
}
function aa_sub2(){
}
}

View File

@ -3,6 +3,9 @@ MyClass
MyClass_sub1フ128ホMyClassヨ0
MyClass_sub2フ128ホMyClassヨ0
aフ16ヨ0
aa<EFBFBD>16<EFBFBD>0
aa_sub1<EFBFBD>16<EFBFBD>aa<EFBFBD>0
aa_sub2<EFBFBD>16<EFBFBD>aa<EFBFBD>0
bフ16ヨ0
bazフ16ホfヨ0
cフ16ヨ0
@ -28,3 +31,12 @@ v
wフ16ヨ0
w_sub1フ16ホwヨ0
w_sub2フ16ホwヨ0
x<EFBFBD>16<EFBFBD>0
x_sub1<EFBFBD>16<EFBFBD>x<EFBFBD>0
x_sub2<EFBFBD>16<EFBFBD>x<EFBFBD>0
y<EFBFBD>16<EFBFBD>0
y_sub1<EFBFBD>16<EFBFBD>y<EFBFBD>0
y_sub2<EFBFBD>16<EFBFBD>y<EFBFBD>0
z<EFBFBD>16<EFBFBD>0
z_sub1<EFBFBD>16<EFBFBD>z<EFBFBD>0
z_sub2<EFBFBD>16<EFBFBD>z<EFBFBD>0