Changeset 10646 in webkit for trunk/JavaScriptCore/kjs
- Timestamp:
- Sep 28, 2005, 11:51:15 AM (20 years ago)
- Location:
- trunk/JavaScriptCore/kjs
- Files:
-
- 3 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/grammar.y
r10621 r10646 42 42 #define YYERROR_VERBOSE 43 43 #endif 44 #define DBG(l, s, e) { l->setLoc(s.first_line, e.last_line, Parser::sid); } // location45 44 46 45 extern int kjsyylex(); 47 46 int kjsyyerror(const char *); 48 static bool automatic(); 47 static bool allowAutomaticSemicolon(); 48 49 #define AUTO_SEMICOLON do { if (!allowAutomaticSemicolon()) YYABORT; } while (0) 50 #define DBG(l, s, e) (l)->setLoc((s).first_line, (e).last_line, Parser::sid) 49 51 50 52 using namespace KJS; … … 85 87 PropertyValueNode *plist; 86 88 PropertyNode *pnode; 87 CatchNode *cnode;88 FinallyNode *fnode;89 89 } 90 90 91 91 %start Program 92 93 /* expect a shift/reduce conflict from the "dangling else" problem94 when using bison the warning can be supressed */95 // %expect 196 92 97 93 /* literals */ … … 102 98 %token BREAK CASE DEFAULT FOR NEW VAR CONST CONTINUE 103 99 %token FUNCTION RETURN VOID DELETE 104 %token IF THIS DO WHILE ELSEIN INSTANCEOF TYPEOF100 %token IF THIS DO WHILE IN INSTANCEOF TYPEOF 105 101 %token SWITCH WITH RESERVED 106 102 %token THROW TRY CATCH FINALLY 103 104 /* give an if without an else higher precedence than an else to resolve the ambiguity */ 105 %nonassoc IF_WITHOUT_ELSE 106 %nonassoc ELSE 107 107 108 108 /* punctuators */ … … 130 130 131 131 /* non-terminal types */ 132 %type <node> Literal PrimaryExpr Expr MemberExpr NewExpr CallExpr 133 %type <node> ArrayLiteral 134 %type <node> LeftHandSideExpr PostfixExpr UnaryExpr 135 %type <node> MultiplicativeExpr AdditiveExpr 136 %type <node> ShiftExpr RelationalExpr EqualityExpr 137 %type <node> BitwiseANDExpr BitwiseXORExpr BitwiseORExpr 138 %type <node> LogicalANDExpr LogicalORExpr 139 %type <node> ConditionalExpr AssignmentExpr 140 %type <node> ExprOpt 141 142 %type <cnode> Catch 143 %type <fnode> Finally 132 %type <node> Literal ArrayLiteral 133 134 %type <node> PrimaryExpr PrimaryExprNoBrace 135 %type <node> MemberExpr MemberExprNoBF /* BF => brace or function */ 136 %type <node> NewExpr NewExprNoBF 137 %type <node> CallExpr CallExprNoBF 138 %type <node> LeftHandSideExpr LeftHandSideExprNoBF 139 %type <node> PostfixExpr PostfixExprNoBF 140 %type <node> UnaryExpr UnaryExprNoBF UnaryExprCommon 141 %type <node> MultiplicativeExpr MultiplicativeExprNoBF 142 %type <node> AdditiveExpr AdditiveExprNoBF 143 %type <node> ShiftExpr ShiftExprNoBF 144 %type <node> RelationalExpr RelationalExprNoIn RelationalExprNoBF 145 %type <node> EqualityExpr EqualityExprNoIn EqualityExprNoBF 146 %type <node> BitwiseANDExpr BitwiseANDExprNoIn BitwiseANDExprNoBF 147 %type <node> BitwiseXORExpr BitwiseXORExprNoIn BitwiseXORExprNoBF 148 %type <node> BitwiseORExpr BitwiseORExprNoIn BitwiseORExprNoBF 149 %type <node> LogicalANDExpr LogicalANDExprNoIn LogicalANDExprNoBF 150 %type <node> LogicalORExpr LogicalORExprNoIn LogicalORExprNoBF 151 %type <node> ConditionalExpr ConditionalExprNoIn ConditionalExprNoBF 152 %type <node> AssignmentExpr AssignmentExprNoIn AssignmentExprNoBF 153 %type <node> Expr ExprNoIn ExprNoBF 154 155 %type <node> ExprOpt ExprNoInOpt 144 156 145 157 %type <stat> Statement Block … … 152 164 153 165 %type <slist> StatementList 154 %type <init> Initializer 166 %type <init> Initializer InitializerNoIn 155 167 %type <func> FunctionDeclaration 156 168 %type <funcExpr> FunctionExpr … … 159 171 %type <param> FormalParameterList 160 172 %type <op> AssignmentOperator 161 %type <prog> Program162 173 %type <args> Arguments 163 174 %type <alist> ArgumentList 164 %type <vlist> VariableDeclarationList ConstDeclarationList165 %type <decl> VariableDeclaration ConstDeclaration175 %type <vlist> VariableDeclarationList VariableDeclarationListNoIn ConstDeclarationList 176 %type <decl> VariableDeclaration VariableDeclarationNoIn ConstDeclaration 166 177 %type <cblk> CaseBlock 167 178 %type <ccl> CaseClause DefaultClause … … 175 186 176 187 Literal: 177 NULLTOKEN { $$ = new NullNode(); } 178 | TRUETOKEN { $$ = new BooleanNode(true); } 179 | FALSETOKEN { $$ = new BooleanNode(false); } 180 | NUMBER { $$ = new NumberNode($1); } 181 | STRING { $$ = new StringNode($1); } 182 | '/' /* a RegExp ? */ { Lexer *l = Lexer::curr(); 183 if (!l->scanRegExp()) YYABORT; 184 $$ = new RegExpNode(l->pattern,l->flags);} 185 | DIVEQUAL /* a RegExp starting with /= ! */ 186 { Lexer *l = Lexer::curr(); 187 if (!l->scanRegExp()) YYABORT; 188 $$ = new RegExpNode(UString('=')+l->pattern,l->flags);} 188 NULLTOKEN { $$ = new NullNode(); } 189 | TRUETOKEN { $$ = new BooleanNode(true); } 190 | FALSETOKEN { $$ = new BooleanNode(false); } 191 | NUMBER { $$ = new NumberNode($1); } 192 | STRING { $$ = new StringNode($1); } 193 | '/' /* regexp */ { 194 Lexer *l = Lexer::curr(); 195 if (!l->scanRegExp()) YYABORT; 196 $$ = new RegExpNode(l->pattern, l->flags); 197 } 198 | DIVEQUAL /* regexp with /= */ { 199 Lexer *l = Lexer::curr(); 200 if (!l->scanRegExp()) YYABORT; 201 $$ = new RegExpNode(UString('=') + l->pattern, l->flags); 202 } 189 203 ; 190 204 191 205 PrimaryExpr: 192 THIS { $$ = new ThisNode(); } 206 PrimaryExprNoBrace 207 | '{' '}' { $$ = new ObjectLiteralNode(); } 208 | '{' PropertyNameAndValueList '}' { $$ = new ObjectLiteralNode($2); } 209 ; 210 211 PrimaryExprNoBrace: 212 THIS { $$ = new ThisNode(); } 193 213 | Literal 194 214 | ArrayLiteral 195 | IDENT { $$ = new ResolveNode(*$1); } 196 | '(' Expr ')' { if ($2->isResolveNode()) $$ = $2; else $$ = new GroupNode($2); } 197 | '{' '}' { $$ = new ObjectLiteralNode(); } 198 | '{' PropertyNameAndValueList '}' { $$ = new ObjectLiteralNode($2); } 215 | IDENT { $$ = new ResolveNode(*$1); } 216 | '(' Expr ')' { $$ = $2->isResolveNode() ? $2 : new GroupNode($2); } 199 217 ; 200 218 201 219 ArrayLiteral: 202 '[' ElisionOpt ']' { $$ = new ArrayNode($2); }203 | '[' ElementList ']' { $$ = new ArrayNode($2); }204 | '[' ElementList ',' ElisionOpt ']' { $$ = new ArrayNode($4, $2); }220 '[' ElisionOpt ']' { $$ = new ArrayNode($2); } 221 | '[' ElementList ']' { $$ = new ArrayNode($2); } 222 | '[' ElementList ',' ElisionOpt ']' { $$ = new ArrayNode($4, $2); } 205 223 ; 206 224 207 225 ElementList: 208 ElisionOpt AssignmentExpr { $$ = new ElementNode($1, $2); }226 ElisionOpt AssignmentExpr { $$ = new ElementNode($1, $2); } 209 227 | ElementList ',' ElisionOpt AssignmentExpr 210 { $$ = new ElementNode($1, $3, $4); }228 { $$ = new ElementNode($1, $3, $4); } 211 229 ; 212 230 213 231 ElisionOpt: 214 /* nothing */ { $$ = 0; }232 /* nothing */ { $$ = 0; } 215 233 | Elision 216 234 ; 217 235 218 236 Elision: 219 ',' { $$ = 1; }220 | Elision ',' { $$ = $1 + 1; }237 ',' { $$ = 1; } 238 | Elision ',' { $$ = $1 + 1; } 221 239 ; 222 240 … … 224 242 PropertyName ':' AssignmentExpr { $$ = new PropertyValueNode($1, $3); } 225 243 | PropertyNameAndValueList ',' PropertyName ':' AssignmentExpr 226 { $$ = new PropertyValueNode($3, $5, $1); }244 { $$ = new PropertyValueNode($3, $5, $1); } 227 245 ; 228 246 229 247 PropertyName: 230 IDENT { $$ = new PropertyNode(*$1); }231 | STRING { $$ = new PropertyNode(Identifier(*$1)); }232 | NUMBER { $$ = new PropertyNode($1); }248 IDENT { $$ = new PropertyNode(*$1); } 249 | STRING { $$ = new PropertyNode(Identifier(*$1)); } 250 | NUMBER { $$ = new PropertyNode($1); } 233 251 ; 234 252 235 253 MemberExpr: 236 254 PrimaryExpr 237 | FunctionExpr { $$ = $1; } 238 | MemberExpr '[' Expr ']' { $$ = new BracketAccessorNode($1, $3); } 239 | MemberExpr '.' IDENT { $$ = new DotAccessorNode($1, *$3); } 240 | NEW MemberExpr Arguments { $$ = new NewExprNode($2, $3); } 255 | FunctionExpr { $$ = $1; } 256 | MemberExpr '[' Expr ']' { $$ = new BracketAccessorNode($1, $3); } 257 | MemberExpr '.' IDENT { $$ = new DotAccessorNode($1, *$3); } 258 | NEW MemberExpr Arguments { $$ = new NewExprNode($2, $3); } 259 ; 260 261 MemberExprNoBF: 262 PrimaryExprNoBrace 263 | MemberExprNoBF '[' Expr ']' { $$ = new BracketAccessorNode($1, $3); } 264 | MemberExprNoBF '.' IDENT { $$ = new DotAccessorNode($1, *$3); } 265 | NEW MemberExpr Arguments { $$ = new NewExprNode($2, $3); } 241 266 ; 242 267 243 268 NewExpr: 244 269 MemberExpr 245 | NEW NewExpr { $$ = new NewExprNode($2); } 270 | NEW NewExpr { $$ = new NewExprNode($2); } 271 ; 272 273 NewExprNoBF: 274 MemberExprNoBF 275 | NEW NewExpr { $$ = new NewExprNode($2); } 246 276 ; 247 277 248 278 CallExpr: 249 MemberExpr Arguments { $$ = makeFunctionCallNode($1, $2); } 250 | CallExpr Arguments { $$ = makeFunctionCallNode($1, $2); } 251 | CallExpr '[' Expr ']' { $$ = new BracketAccessorNode($1, $3); } 252 | CallExpr '.' IDENT { $$ = new DotAccessorNode($1, *$3); } 279 MemberExpr Arguments { $$ = makeFunctionCallNode($1, $2); } 280 | CallExpr Arguments { $$ = makeFunctionCallNode($1, $2); } 281 | CallExpr '[' Expr ']' { $$ = new BracketAccessorNode($1, $3); } 282 | CallExpr '.' IDENT { $$ = new DotAccessorNode($1, *$3); } 283 ; 284 285 CallExprNoBF: 286 MemberExprNoBF Arguments { $$ = makeFunctionCallNode($1, $2); } 287 | CallExprNoBF Arguments { $$ = makeFunctionCallNode($1, $2); } 288 | CallExprNoBF '[' Expr ']' { $$ = new BracketAccessorNode($1, $3); } 289 | CallExprNoBF '.' IDENT { $$ = new DotAccessorNode($1, *$3); } 253 290 ; 254 291 255 292 Arguments: 256 '(' ')' { $$ = new ArgumentsNode(); }257 | '(' ArgumentList ')' { $$ = new ArgumentsNode($2); }293 '(' ')' { $$ = new ArgumentsNode(); } 294 | '(' ArgumentList ')' { $$ = new ArgumentsNode($2); } 258 295 ; 259 296 260 297 ArgumentList: 261 AssignmentExpr { $$ = new ArgumentListNode($1); }262 | ArgumentList ',' AssignmentExpr { $$ = new ArgumentListNode($1, $3); }298 AssignmentExpr { $$ = new ArgumentListNode($1); } 299 | ArgumentList ',' AssignmentExpr { $$ = new ArgumentListNode($1, $3); } 263 300 ; 264 301 … … 268 305 ; 269 306 270 PostfixExpr: /* TODO: no line terminator here */ 307 LeftHandSideExprNoBF: 308 NewExprNoBF 309 | CallExprNoBF 310 ; 311 312 PostfixExpr: 271 313 LeftHandSideExpr 272 | LeftHandSideExpr PLUSPLUS { if (!makePostfixNode($$, $1, OpPlusPlus)) YYABORT; } 273 | LeftHandSideExpr MINUSMINUS { if (!makePostfixNode($$, $1, OpMinusMinus)) YYABORT; } 274 ; 314 | LeftHandSideExpr PLUSPLUS { if (!makePostfixNode($$, $1, OpPlusPlus)) YYABORT; } 315 | LeftHandSideExpr MINUSMINUS { if (!makePostfixNode($$, $1, OpMinusMinus)) YYABORT; } 316 ; 317 318 PostfixExprNoBF: 319 LeftHandSideExprNoBF 320 | LeftHandSideExprNoBF PLUSPLUS { if (!makePostfixNode($$, $1, OpPlusPlus)) YYABORT; } 321 | LeftHandSideExprNoBF MINUSMINUS { if (!makePostfixNode($$, $1, OpMinusMinus)) YYABORT; } 322 ; 323 324 UnaryExprCommon: 325 DELETE UnaryExpr { $$ = makeDeleteNode($2); } 326 | VOID UnaryExpr { $$ = new VoidNode($2); } 327 | TYPEOF UnaryExpr { $$ = makeTypeOfNode($2); } 328 | PLUSPLUS UnaryExpr { if (!makePrefixNode($$, $2, OpPlusPlus)) YYABORT; } 329 | AUTOPLUSPLUS UnaryExpr { if (!makePrefixNode($$, $2, OpPlusPlus)) YYABORT; } 330 | MINUSMINUS UnaryExpr { if (!makePrefixNode($$, $2, OpMinusMinus)) YYABORT; } 331 | AUTOMINUSMINUS UnaryExpr { if (!makePrefixNode($$, $2, OpMinusMinus)) YYABORT; } 332 | '+' UnaryExpr { $$ = new UnaryPlusNode($2); } 333 | '-' UnaryExpr { $$ = new NegateNode($2); } 334 | '~' UnaryExpr { $$ = new BitwiseNotNode($2); } 335 | '!' UnaryExpr { $$ = new LogicalNotNode($2); } 275 336 276 337 UnaryExpr: 277 338 PostfixExpr 278 | DELETE UnaryExpr { $$ = makeDeleteNode($2); } 279 | VOID UnaryExpr { $$ = new VoidNode($2); } 280 | TYPEOF UnaryExpr { $$ = makeTypeOfNode($2); } 281 | PLUSPLUS UnaryExpr { if (!makePrefixNode($$, $2, OpPlusPlus)) YYABORT; } 282 | AUTOPLUSPLUS UnaryExpr { if (!makePrefixNode($$, $2, OpPlusPlus)) YYABORT; } 283 | MINUSMINUS UnaryExpr { if (!makePrefixNode($$, $2, OpMinusMinus)) YYABORT; } 284 | AUTOMINUSMINUS UnaryExpr { if (!makePrefixNode($$, $2, OpMinusMinus)) YYABORT; } 285 | '+' UnaryExpr { $$ = new UnaryPlusNode($2); } 286 | '-' UnaryExpr { $$ = new NegateNode($2); } 287 | '~' UnaryExpr { $$ = new BitwiseNotNode($2); } 288 | '!' UnaryExpr { $$ = new LogicalNotNode($2); } 339 | UnaryExprCommon 340 ; 341 342 UnaryExprNoBF: 343 PostfixExprNoBF 344 | UnaryExprCommon 289 345 ; 290 346 291 347 MultiplicativeExpr: 292 348 UnaryExpr 293 | MultiplicativeExpr '*' UnaryExpr { $$ = new MultNode($1, $3, '*'); } 294 | MultiplicativeExpr '/' UnaryExpr { $$ = new MultNode($1, $3, '/'); } 295 | MultiplicativeExpr '%' UnaryExpr { $$ = new MultNode($1,$3,'%'); } 349 | MultiplicativeExpr '*' UnaryExpr { $$ = new MultNode($1, $3, '*'); } 350 | MultiplicativeExpr '/' UnaryExpr { $$ = new MultNode($1, $3, '/'); } 351 | MultiplicativeExpr '%' UnaryExpr { $$ = new MultNode($1, $3,'%'); } 352 ; 353 354 MultiplicativeExprNoBF: 355 UnaryExprNoBF 356 | MultiplicativeExprNoBF '*' UnaryExpr 357 { $$ = new MultNode($1, $3, '*'); } 358 | MultiplicativeExprNoBF '/' UnaryExpr 359 { $$ = new MultNode($1, $3, '/'); } 360 | MultiplicativeExprNoBF '%' UnaryExpr 361 { $$ = new MultNode($1, $3,'%'); } 296 362 ; 297 363 … … 302 368 ; 303 369 370 AdditiveExprNoBF: 371 MultiplicativeExprNoBF 372 | AdditiveExprNoBF '+' MultiplicativeExpr 373 { $$ = new AddNode($1, $3, '+'); } 374 | AdditiveExprNoBF '-' MultiplicativeExpr 375 { $$ = new AddNode($1, $3, '-'); } 376 ; 377 304 378 ShiftExpr: 305 379 AdditiveExpr 306 | ShiftExpr LSHIFT AdditiveExpr { $$ = new ShiftNode($1, OpLShift, $3); } 307 | ShiftExpr RSHIFT AdditiveExpr { $$ = new ShiftNode($1, OpRShift, $3); } 308 | ShiftExpr URSHIFT AdditiveExpr { $$ = new ShiftNode($1, OpURShift, $3); } 380 | ShiftExpr LSHIFT AdditiveExpr { $$ = new ShiftNode($1, OpLShift, $3); } 381 | ShiftExpr RSHIFT AdditiveExpr { $$ = new ShiftNode($1, OpRShift, $3); } 382 | ShiftExpr URSHIFT AdditiveExpr { $$ = new ShiftNode($1, OpURShift, $3); } 383 ; 384 385 ShiftExprNoBF: 386 AdditiveExprNoBF 387 | ShiftExprNoBF LSHIFT AdditiveExpr { $$ = new ShiftNode($1, OpLShift, $3); } 388 | ShiftExprNoBF RSHIFT AdditiveExpr { $$ = new ShiftNode($1, OpRShift, $3); } 389 | ShiftExprNoBF URSHIFT AdditiveExpr { $$ = new ShiftNode($1, OpURShift, $3); } 309 390 ; 310 391 311 392 RelationalExpr: 312 393 ShiftExpr 313 | RelationalExpr '<' ShiftExpr 314 { $$ = new RelationalNode($1, OpLess, $3); } 315 | RelationalExpr '>' ShiftExpr 316 { $$ = new RelationalNode($1, OpGreater, $3); } 317 | RelationalExpr LE ShiftExpr 318 { $$ = new RelationalNode($1, OpLessEq, $3); } 319 | RelationalExpr GE ShiftExpr 320 { $$ = new RelationalNode($1, OpGreaterEq, $3); } 321 | RelationalExpr INSTANCEOF ShiftExpr 322 { $$ = new RelationalNode($1, OpInstanceOf, $3); } 323 | RelationalExpr IN ShiftExpr 324 { $$ = new RelationalNode($1, OpIn, $3); } 394 | RelationalExpr '<' ShiftExpr { $$ = new RelationalNode($1, OpLess, $3); } 395 | RelationalExpr '>' ShiftExpr { $$ = new RelationalNode($1, OpGreater, $3); } 396 | RelationalExpr LE ShiftExpr { $$ = new RelationalNode($1, OpLessEq, $3); } 397 | RelationalExpr GE ShiftExpr { $$ = new RelationalNode($1, OpGreaterEq, $3); } 398 | RelationalExpr INSTANCEOF ShiftExpr { $$ = new RelationalNode($1, OpInstanceOf, $3); } 399 | RelationalExpr IN ShiftExpr { $$ = new RelationalNode($1, OpIn, $3); } 400 ; 401 402 RelationalExprNoIn: 403 ShiftExpr 404 | RelationalExprNoIn '<' ShiftExpr { $$ = new RelationalNode($1, OpLess, $3); } 405 | RelationalExprNoIn '>' ShiftExpr { $$ = new RelationalNode($1, OpGreater, $3); } 406 | RelationalExprNoIn LE ShiftExpr { $$ = new RelationalNode($1, OpLessEq, $3); } 407 | RelationalExprNoIn GE ShiftExpr { $$ = new RelationalNode($1, OpGreaterEq, $3); } 408 | RelationalExprNoIn INSTANCEOF ShiftExpr 409 { $$ = new RelationalNode($1, OpInstanceOf, $3); } 410 ; 411 412 RelationalExprNoBF: 413 ShiftExprNoBF 414 | RelationalExprNoBF '<' ShiftExpr { $$ = new RelationalNode($1, OpLess, $3); } 415 | RelationalExprNoBF '>' ShiftExpr { $$ = new RelationalNode($1, OpGreater, $3); } 416 | RelationalExprNoBF LE ShiftExpr { $$ = new RelationalNode($1, OpLessEq, $3); } 417 | RelationalExprNoBF GE ShiftExpr { $$ = new RelationalNode($1, OpGreaterEq, $3); } 418 | RelationalExprNoBF INSTANCEOF ShiftExpr 419 { $$ = new RelationalNode($1, OpInstanceOf, $3); } 420 | RelationalExprNoBF IN ShiftExpr { $$ = new RelationalNode($1, OpIn, $3); } 325 421 ; 326 422 327 423 EqualityExpr: 328 424 RelationalExpr 329 | EqualityExpr EQEQ RelationalExpr { $$ = new EqualNode($1, OpEqEq, $3); } 330 | EqualityExpr NE RelationalExpr { $$ = new EqualNode($1, OpNotEq, $3); } 331 | EqualityExpr STREQ RelationalExpr { $$ = new EqualNode($1, OpStrEq, $3); } 332 | EqualityExpr STRNEQ RelationalExpr { $$ = new EqualNode($1, OpStrNEq, $3);} 425 | EqualityExpr EQEQ RelationalExpr { $$ = new EqualNode($1, OpEqEq, $3); } 426 | EqualityExpr NE RelationalExpr { $$ = new EqualNode($1, OpNotEq, $3); } 427 | EqualityExpr STREQ RelationalExpr { $$ = new EqualNode($1, OpStrEq, $3); } 428 | EqualityExpr STRNEQ RelationalExpr { $$ = new EqualNode($1, OpStrNEq, $3);} 429 ; 430 431 EqualityExprNoIn: 432 RelationalExprNoIn 433 | EqualityExprNoIn EQEQ RelationalExprNoIn 434 { $$ = new EqualNode($1, OpEqEq, $3); } 435 | EqualityExprNoIn NE RelationalExprNoIn 436 { $$ = new EqualNode($1, OpNotEq, $3); } 437 | EqualityExprNoIn STREQ RelationalExprNoIn 438 { $$ = new EqualNode($1, OpStrEq, $3); } 439 | EqualityExprNoIn STRNEQ RelationalExprNoIn 440 { $$ = new EqualNode($1, OpStrNEq, $3);} 441 ; 442 443 EqualityExprNoBF: 444 RelationalExprNoBF 445 | EqualityExprNoBF EQEQ RelationalExpr 446 { $$ = new EqualNode($1, OpEqEq, $3); } 447 | EqualityExprNoBF NE RelationalExpr { $$ = new EqualNode($1, OpNotEq, $3); } 448 | EqualityExprNoBF STREQ RelationalExpr 449 { $$ = new EqualNode($1, OpStrEq, $3); } 450 | EqualityExprNoBF STRNEQ RelationalExpr 451 { $$ = new EqualNode($1, OpStrNEq, $3);} 333 452 ; 334 453 335 454 BitwiseANDExpr: 336 455 EqualityExpr 337 | BitwiseANDExpr '&' EqualityExpr { $$ = new BitOperNode($1, OpBitAnd, $3); } 456 | BitwiseANDExpr '&' EqualityExpr { $$ = new BitOperNode($1, OpBitAnd, $3); } 457 ; 458 459 BitwiseANDExprNoIn: 460 EqualityExprNoIn 461 | BitwiseANDExprNoIn '&' EqualityExprNoIn 462 { $$ = new BitOperNode($1, OpBitAnd, $3); } 463 ; 464 465 BitwiseANDExprNoBF: 466 EqualityExprNoBF 467 | BitwiseANDExprNoBF '&' EqualityExpr { $$ = new BitOperNode($1, OpBitAnd, $3); } 338 468 ; 339 469 340 470 BitwiseXORExpr: 341 471 BitwiseANDExpr 342 | BitwiseXORExpr '^' BitwiseANDExpr { $$ = new BitOperNode($1, OpBitXOr, $3); } 472 | BitwiseXORExpr '^' BitwiseANDExpr { $$ = new BitOperNode($1, OpBitXOr, $3); } 473 ; 474 475 BitwiseXORExprNoIn: 476 BitwiseANDExprNoIn 477 | BitwiseXORExprNoIn '^' BitwiseANDExprNoIn 478 { $$ = new BitOperNode($1, OpBitXOr, $3); } 479 ; 480 481 BitwiseXORExprNoBF: 482 BitwiseANDExprNoBF 483 | BitwiseXORExprNoBF '^' BitwiseANDExpr 484 { $$ = new BitOperNode($1, OpBitXOr, $3); } 343 485 ; 344 486 345 487 BitwiseORExpr: 346 488 BitwiseXORExpr 347 | BitwiseORExpr '|' BitwiseXORExpr { $$ = new BitOperNode($1, OpBitOr, $3); } 489 | BitwiseORExpr '|' BitwiseXORExpr { $$ = new BitOperNode($1, OpBitOr, $3); } 490 ; 491 492 BitwiseORExprNoIn: 493 BitwiseXORExprNoIn 494 | BitwiseORExprNoIn '|' BitwiseXORExprNoIn 495 { $$ = new BitOperNode($1, OpBitOr, $3); } 496 ; 497 498 BitwiseORExprNoBF: 499 BitwiseXORExprNoBF 500 | BitwiseORExprNoBF '|' BitwiseXORExpr 501 { $$ = new BitOperNode($1, OpBitOr, $3); } 348 502 ; 349 503 350 504 LogicalANDExpr: 351 505 BitwiseORExpr 352 | LogicalANDExpr AND BitwiseORExpr 353 { $$ = new BinaryLogicalNode($1, OpAnd, $3); } 506 | LogicalANDExpr AND BitwiseORExpr { $$ = new BinaryLogicalNode($1, OpAnd, $3); } 507 ; 508 509 LogicalANDExprNoIn: 510 BitwiseORExprNoIn 511 | LogicalANDExprNoIn AND BitwiseORExprNoIn 512 { $$ = new BinaryLogicalNode($1, OpAnd, $3); } 513 ; 514 515 LogicalANDExprNoBF: 516 BitwiseORExprNoBF 517 | LogicalANDExprNoBF AND BitwiseORExpr 518 { $$ = new BinaryLogicalNode($1, OpAnd, $3); } 354 519 ; 355 520 356 521 LogicalORExpr: 357 522 LogicalANDExpr 358 | LogicalORExpr OR LogicalANDExpr 359 { $$ = new BinaryLogicalNode($1, OpOr, $3); } 523 | LogicalORExpr OR LogicalANDExpr { $$ = new BinaryLogicalNode($1, OpOr, $3); } 524 ; 525 526 LogicalORExprNoIn: 527 LogicalANDExprNoIn 528 | LogicalORExprNoIn OR LogicalANDExprNoIn 529 { $$ = new BinaryLogicalNode($1, OpOr, $3); } 530 ; 531 532 LogicalORExprNoBF: 533 LogicalANDExprNoBF 534 | LogicalORExprNoBF OR LogicalANDExpr { $$ = new BinaryLogicalNode($1, OpOr, $3); } 360 535 ; 361 536 … … 363 538 LogicalORExpr 364 539 | LogicalORExpr '?' AssignmentExpr ':' AssignmentExpr 365 { $$ = new ConditionalNode($1, $3, $5); } 540 { $$ = new ConditionalNode($1, $3, $5); } 541 ; 542 543 ConditionalExprNoIn: 544 LogicalORExprNoIn 545 | LogicalORExprNoIn '?' AssignmentExprNoIn ':' AssignmentExprNoIn 546 { $$ = new ConditionalNode($1, $3, $5); } 547 ; 548 549 ConditionalExprNoBF: 550 LogicalORExprNoBF 551 | LogicalORExprNoBF '?' AssignmentExpr ':' AssignmentExpr 552 { $$ = new ConditionalNode($1, $3, $5); } 366 553 ; 367 554 … … 369 556 ConditionalExpr 370 557 | LeftHandSideExpr AssignmentOperator AssignmentExpr 371 { if (!makeAssignNode($$, $1, $2, $3)) YYABORT; } 558 { if (!makeAssignNode($$, $1, $2, $3)) YYABORT; } 559 ; 560 561 AssignmentExprNoIn: 562 ConditionalExprNoIn 563 | LeftHandSideExpr AssignmentOperator AssignmentExprNoIn 564 { if (!makeAssignNode($$, $1, $2, $3)) YYABORT; } 565 ; 566 567 AssignmentExprNoBF: 568 ConditionalExprNoBF 569 | LeftHandSideExprNoBF AssignmentOperator AssignmentExpr 570 { if (!makeAssignNode($$, $1, $2, $3)) YYABORT; } 372 571 ; 373 572 374 573 AssignmentOperator: 375 '=' { $$ = OpEqual; }376 | PLUSEQUAL { $$ = OpPlusEq; }377 | MINUSEQUAL { $$ = OpMinusEq; }378 | MULTEQUAL { $$ = OpMultEq; }379 | DIVEQUAL { $$ = OpDivEq; }380 | LSHIFTEQUAL { $$ = OpLShift; }381 | RSHIFTEQUAL { $$ = OpRShift; }382 | URSHIFTEQUAL { $$ = OpURShift; }383 | ANDEQUAL { $$ = OpAndEq; }384 | XOREQUAL { $$ = OpXOrEq; }385 | OREQUAL { $$ = OpOrEq; }386 | MODEQUAL { $$ = OpModEq; }574 '=' { $$ = OpEqual; } 575 | PLUSEQUAL { $$ = OpPlusEq; } 576 | MINUSEQUAL { $$ = OpMinusEq; } 577 | MULTEQUAL { $$ = OpMultEq; } 578 | DIVEQUAL { $$ = OpDivEq; } 579 | LSHIFTEQUAL { $$ = OpLShift; } 580 | RSHIFTEQUAL { $$ = OpRShift; } 581 | URSHIFTEQUAL { $$ = OpURShift; } 582 | ANDEQUAL { $$ = OpAndEq; } 583 | XOREQUAL { $$ = OpXOrEq; } 584 | OREQUAL { $$ = OpOrEq; } 585 | MODEQUAL { $$ = OpModEq; } 387 586 ; 388 587 389 588 Expr: 390 589 AssignmentExpr 391 | Expr ',' AssignmentExpr { $$ = new CommaNode($1, $3); } 590 | Expr ',' AssignmentExpr { $$ = new CommaNode($1, $3); } 591 ; 592 593 ExprNoIn: 594 AssignmentExprNoIn 595 | ExprNoIn ',' AssignmentExprNoIn { $$ = new CommaNode($1, $3); } 596 ; 597 598 ExprNoBF: 599 AssignmentExprNoBF 600 | ExprNoBF ',' AssignmentExpr { $$ = new CommaNode($1, $3); } 392 601 ; 393 602 … … 411 620 412 621 Block: 413 '{' '}' { $$ = new BlockNode(0); DBG($$, @2, @2); }414 | '{' SourceElements '}' { $$ = new BlockNode($2); DBG($$, @3, @3); }622 '{' '}' { $$ = new BlockNode(0); DBG($$, @2, @2); } 623 | '{' SourceElements '}' { $$ = new BlockNode($2); DBG($$, @3, @3); } 415 624 ; 416 625 417 626 StatementList: 418 Statement { $$ = new StatListNode($1); }419 | StatementList Statement { $$ = new StatListNode($1, $2); }627 Statement { $$ = new StatListNode($1); } 628 | StatementList Statement { $$ = new StatListNode($1, $2); } 420 629 ; 421 630 422 631 VariableStatement: 423 VAR VariableDeclarationList ';' { $$ = new VarStatementNode($2); 424 DBG($$, @1, @3); } 425 | VAR VariableDeclarationList error { if (automatic()) { 426 $$ = new VarStatementNode($2); 427 DBG($$, @1, @2); 428 } else { 429 YYABORT; 430 } 431 } 632 VAR VariableDeclarationList ';' { $$ = new VarStatementNode($2); DBG($$, @1, @3); } 633 | VAR VariableDeclarationList error { $$ = new VarStatementNode($2); DBG($$, @1, @2); AUTO_SEMICOLON; } 432 634 ; 433 635 434 636 VariableDeclarationList: 435 VariableDeclaration { $$ = new VarDeclListNode($1); }637 VariableDeclaration { $$ = new VarDeclListNode($1); } 436 638 | VariableDeclarationList ',' VariableDeclaration 437 { $$ = new VarDeclListNode($1, $3); } 639 { $$ = new VarDeclListNode($1, $3); } 640 ; 641 642 VariableDeclarationListNoIn: 643 VariableDeclarationNoIn { $$ = new VarDeclListNode($1); } 644 | VariableDeclarationListNoIn ',' VariableDeclarationNoIn 645 { $$ = new VarDeclListNode($1, $3); } 438 646 ; 439 647 440 648 VariableDeclaration: 441 IDENT { $$ = new VarDeclNode(*$1, 0, VarDeclNode::Variable); } 442 | IDENT Initializer { $$ = new VarDeclNode(*$1, $2, VarDeclNode::Variable); } 649 IDENT { $$ = new VarDeclNode(*$1, 0, VarDeclNode::Variable); } 650 | IDENT Initializer { $$ = new VarDeclNode(*$1, $2, VarDeclNode::Variable); } 651 ; 652 653 VariableDeclarationNoIn: 654 IDENT { $$ = new VarDeclNode(*$1, 0, VarDeclNode::Variable); } 655 | IDENT InitializerNoIn { $$ = new VarDeclNode(*$1, $2, VarDeclNode::Variable); } 443 656 ; 444 657 445 658 ConstStatement: 446 CONST ConstDeclarationList ';' { $$ = new VarStatementNode($2); 447 DBG($$, @1, @3); } 448 | CONST ConstDeclarationList error { if (automatic()) { 449 $$ = new VarStatementNode($2); 450 DBG($$, @1, @2); 451 } else { 452 YYABORT; 453 } 454 } 659 CONST ConstDeclarationList ';' { $$ = new VarStatementNode($2); DBG($$, @1, @3); } 660 | CONST ConstDeclarationList error { $$ = new VarStatementNode($2); DBG($$, @1, @2); AUTO_SEMICOLON; } 455 661 ; 456 662 457 663 ConstDeclarationList: 458 ConstDeclaration { $$ = new VarDeclListNode($1); }459 | ConstDeclarationList ',' VariableDeclaration460 { $$ = new VarDeclListNode($1, $3); }664 ConstDeclaration { $$ = new VarDeclListNode($1); } 665 | ConstDeclarationList ',' ConstDeclaration 666 { $$ = new VarDeclListNode($1, $3); } 461 667 ; 462 668 463 669 ConstDeclaration: 464 IDENT { $$ = new VarDeclNode(*$1, 0, VarDeclNode::Constant); }465 | IDENT Initializer { $$ = new VarDeclNode(*$1, $2, VarDeclNode::Constant); }670 IDENT { $$ = new VarDeclNode(*$1, 0, VarDeclNode::Constant); } 671 | IDENT Initializer { $$ = new VarDeclNode(*$1, $2, VarDeclNode::Constant); } 466 672 ; 467 673 468 674 Initializer: 469 '=' AssignmentExpr { $$ = new AssignExprNode($2); } 675 '=' AssignmentExpr { $$ = new AssignExprNode($2); } 676 ; 677 678 InitializerNoIn: 679 '=' AssignmentExprNoIn { $$ = new AssignExprNode($2); } 470 680 ; 471 681 472 682 EmptyStatement: 473 ';' { $$ = new EmptyStatementNode(); }683 ';' { $$ = new EmptyStatementNode(); } 474 684 ; 475 685 476 686 ExprStatement: 477 Expr ';' { $$ = new ExprStatementNode($1); 478 DBG($$, @1, @2); } 479 | Expr error { if (automatic()) { 480 $$ = new ExprStatementNode($1); 481 DBG($$, @1, @1); 482 } else 483 YYABORT; } 484 ; 485 486 IfStatement: /* shift/reduce conflict due to dangling else */ 487 IF '(' Expr ')' Statement { $$ = new IfNode($3,$5,0);DBG($$,@1,@4); } 687 ExprNoBF ';' { $$ = new ExprStatementNode($1); DBG($$, @1, @2); } 688 | ExprNoBF error { $$ = new ExprStatementNode($1); DBG($$, @1, @1); AUTO_SEMICOLON; } 689 ; 690 691 IfStatement: 692 IF '(' Expr ')' Statement %prec IF_WITHOUT_ELSE 693 { $$ = new IfNode($3, $5, 0); DBG($$, @1, @4); } 488 694 | IF '(' Expr ')' Statement ELSE Statement 489 { $$ = new IfNode($3,$5,$7);DBG($$,@1,@4); }695 { $$ = new IfNode($3, $5, $7); DBG($$, @1, @4); } 490 696 ; 491 697 492 698 IterationStatement: 493 DO Statement WHILE '(' Expr ')' { $$=new DoWhileNode($2,$5);DBG($$,@1,@3);} 494 | WHILE '(' Expr ')' Statement { $$ = new WhileNode($3,$5);DBG($$,@1,@4); } 495 | FOR '(' ExprOpt ';' ExprOpt ';' ExprOpt ')' 496 Statement { $$ = new ForNode($3,$5,$7,$9); 497 DBG($$,@1,@8); } 498 | FOR '(' VAR VariableDeclarationList ';' ExprOpt ';' ExprOpt ')' 499 Statement { $$ = new ForNode($4,$6,$8,$10); 500 DBG($$,@1,@9); } 501 | FOR '(' LeftHandSideExpr IN Expr ')' 502 Statement { 503 Node *n = $3; 504 bool paren = n->isGroupNode(); 505 if (paren) 506 n = static_cast<GroupNode *>(n)->nodeInsideAllParens(); 507 508 if (!n->isLocation()) 509 YYABORT; 510 511 $$ = new ForInNode(n, $5, $7); 512 DBG($$,@1,@6); 513 } 514 | FOR '(' VAR IDENT IN Expr ')' 515 Statement { $$ = new ForInNode(*$4,0,$6,$8); 516 DBG($$,@1,@7); } 517 | FOR '(' VAR IDENT Initializer IN Expr ')' 518 Statement { $$ = new ForInNode(*$4,$5,$7,$9); 519 DBG($$,@1,@8); } 699 DO Statement WHILE '(' Expr ')' { $$ = new DoWhileNode($2, $5); DBG($$, @1, @3);} 700 | WHILE '(' Expr ')' Statement { $$ = new WhileNode($3, $5); DBG($$, @1, @4); } 701 | FOR '(' ExprNoInOpt ';' ExprOpt ';' ExprOpt ')' Statement 702 { $$ = new ForNode($3, $5, $7, $9); DBG($$, @1, @8); } 703 | FOR '(' VAR VariableDeclarationListNoIn ';' ExprOpt ';' ExprOpt ')' Statement 704 { $$ = new ForNode($4, $6, $8, $10); DBG($$, @1, @9); } 705 | FOR '(' LeftHandSideExpr IN Expr ')' Statement 706 { 707 Node *n = $3->nodeInsideAllParens(); 708 if (!n->isLocation()) 709 YYABORT; 710 $$ = new ForInNode(n, $5, $7); 711 DBG($$, @1, @6); 712 } 713 | FOR '(' VAR IDENT IN Expr ')' Statement 714 { $$ = new ForInNode(*$4, 0, $6, $8); DBG($$, @1, @7); } 715 | FOR '(' VAR IDENT InitializerNoIn IN Expr ')' Statement 716 { $$ = new ForInNode(*$4, $5, $7, $9); DBG($$, @1, @8); } 520 717 ; 521 718 522 719 ExprOpt: 523 /* nothing */ { $$ = 0; }720 /* nothing */ { $$ = 0; } 524 721 | Expr 525 722 ; 526 723 724 ExprNoInOpt: 725 /* nothing */ { $$ = 0; } 726 | ExprNoIn 727 ; 728 527 729 ContinueStatement: 528 CONTINUE ';' { $$ = new ContinueNode(); DBG($$,@1,@2); } 529 | CONTINUE error { if (automatic()) { 530 $$ = new ContinueNode(); DBG($$,@1,@1); 531 } else 532 YYABORT; } 533 | CONTINUE IDENT ';' { $$ = new ContinueNode(*$2); DBG($$,@1,@3); } 534 | CONTINUE IDENT error { if (automatic()) { 535 $$ = new ContinueNode(*$2);DBG($$,@1,@2); 536 } else 537 YYABORT; } 730 CONTINUE ';' { $$ = new ContinueNode(); DBG($$, @1, @2); } 731 | CONTINUE error { $$ = new ContinueNode(); DBG($$, @1, @1); AUTO_SEMICOLON; } 732 | CONTINUE IDENT ';' { $$ = new ContinueNode(*$2); DBG($$, @1, @3); } 733 | CONTINUE IDENT error { $$ = new ContinueNode(*$2); DBG($$, @1, @2); AUTO_SEMICOLON; } 538 734 ; 539 735 540 736 BreakStatement: 541 BREAK ';' { $$ = new BreakNode();DBG($$,@1,@2); } 542 | BREAK error { if (automatic()) { 543 $$ = new BreakNode(); DBG($$,@1,@1); 544 } else 545 YYABORT; } 546 | BREAK IDENT ';' { $$ = new BreakNode(*$2); DBG($$,@1,@3); } 547 | BREAK IDENT error { if (automatic()) { 548 $$ = new BreakNode(*$2); DBG($$,@1,@2); 549 } else 550 YYABORT; 551 } 737 BREAK ';' { $$ = new BreakNode(); DBG($$, @1, @2); } 738 | BREAK error { $$ = new BreakNode(); DBG($$, @1, @1); AUTO_SEMICOLON; } 739 | BREAK IDENT ';' { $$ = new BreakNode(*$2); DBG($$, @1, @3); } 740 | BREAK IDENT error { $$ = new BreakNode(*$2); DBG($$, @1, @2); AUTO_SEMICOLON; } 552 741 ; 553 742 554 743 ReturnStatement: 555 RETURN ';' { $$ = new ReturnNode(0); DBG($$,@1,@2); } 556 | RETURN error { if (automatic()) { 557 $$ = new ReturnNode(0); DBG($$,@1,@1); 558 } else 559 YYABORT; } 560 | RETURN Expr ';' { $$ = new ReturnNode($2); DBG($$,@1,@3); } 561 | RETURN Expr error { if (automatic()) { 562 $$ = new ReturnNode($2); DBG($$,@1,@2); 563 } else 564 YYABORT; } 744 RETURN ';' { $$ = new ReturnNode(0); DBG($$, @1, @2); } 745 | RETURN error { $$ = new ReturnNode(0); DBG($$, @1, @1); AUTO_SEMICOLON; } 746 | RETURN Expr ';' { $$ = new ReturnNode($2); DBG($$, @1, @3); } 747 | RETURN Expr error { $$ = new ReturnNode($2); DBG($$, @1, @2); AUTO_SEMICOLON; } 565 748 ; 566 749 567 750 WithStatement: 568 WITH '(' Expr ')' Statement { $$ = new WithNode($3,$5); 569 DBG($$, @1, @4); } 751 WITH '(' Expr ')' Statement { $$ = new WithNode($3, $5); DBG($$, @1, @4); } 570 752 ; 571 753 572 754 SwitchStatement: 573 SWITCH '(' Expr ')' CaseBlock { $$ = new SwitchNode($3, $5); 574 DBG($$, @1, @4); } 755 SWITCH '(' Expr ')' CaseBlock { $$ = new SwitchNode($3, $5); DBG($$, @1, @4); } 575 756 ; 576 757 577 758 CaseBlock: 578 '{' CaseClausesOpt '}' { $$ = new CaseBlockNode($2, 0, 0); }759 '{' CaseClausesOpt '}' { $$ = new CaseBlockNode($2, 0, 0); } 579 760 | '{' CaseClausesOpt DefaultClause CaseClausesOpt '}' 580 { $$ = new CaseBlockNode($2, $3, $4); }761 { $$ = new CaseBlockNode($2, $3, $4); } 581 762 ; 582 763 583 764 CaseClausesOpt: 584 /* nothing */ { $$ = 0; }765 /* nothing */ { $$ = 0; } 585 766 | CaseClauses 586 767 ; 587 768 588 769 CaseClauses: 589 CaseClause { $$ = new ClauseListNode($1); }590 | CaseClauses CaseClause { $$ = new ClauseListNode($1, $2); }770 CaseClause { $$ = new ClauseListNode($1); } 771 | CaseClauses CaseClause { $$ = new ClauseListNode($1, $2); } 591 772 ; 592 773 593 774 CaseClause: 594 CASE Expr ':' { $$ = new CaseClauseNode($2); }595 | CASE Expr ':' StatementList { $$ = new CaseClauseNode($2, $4); }775 CASE Expr ':' { $$ = new CaseClauseNode($2); } 776 | CASE Expr ':' StatementList { $$ = new CaseClauseNode($2, $4); } 596 777 ; 597 778 598 779 DefaultClause: 599 DEFAULT ':' { $$ = new CaseClauseNode(0); }600 | DEFAULT ':' StatementList { $$ = new CaseClauseNode(0, $3); }780 DEFAULT ':' { $$ = new CaseClauseNode(0); } 781 | DEFAULT ':' StatementList { $$ = new CaseClauseNode(0, $3); } 601 782 ; 602 783 603 784 LabelledStatement: 604 IDENT ':' Statement { $3->pushLabel(*$1); 605 $$ = new LabelNode(*$1, $3); } 785 IDENT ':' Statement { $3->pushLabel(*$1); $$ = new LabelNode(*$1, $3); } 606 786 ; 607 787 608 788 ThrowStatement: 609 THROW Expr ';' { $$ = new ThrowNode($2); DBG($$,@1,@3); }610 | THROW Expr error { if (automatic()) { $$ = new ThrowNode($2); DBG($$,@1,@2); } else YYABORT; }789 THROW Expr ';' { $$ = new ThrowNode($2); DBG($$, @1, @3); } 790 | THROW Expr error { $$ = new ThrowNode($2); DBG($$, @1, @2); AUTO_SEMICOLON; } 611 791 ; 612 792 613 793 TryStatement: 614 TRY Block Catch { $$ = new TryNode($2, $3); DBG($$,@1,@2); } 615 | TRY Block Finally { $$ = new TryNode($2, $3); DBG($$,@1,@2); } 616 | TRY Block Catch Finally { $$ = new TryNode($2, $3, $4); DBG($$,@1,@2); } 617 ; 618 619 Catch: 620 CATCH '(' IDENT ')' Block { $$ = new CatchNode(*$3, $5); } 621 ; 622 623 Finally: 624 FINALLY Block { $$ = new FinallyNode($2); } 794 TRY Block FINALLY Block { $$ = new TryNode($2, Identifier::null(), 0, $4); DBG($$, @1, @2); } 795 | TRY Block CATCH '(' IDENT ')' Block { $$ = new TryNode($2, *$5, $7, 0); DBG($$, @1, @2); } 796 | TRY Block CATCH '(' IDENT ')' Block FINALLY Block 797 { $$ = new TryNode($2, *$5, $7, $9); DBG($$, @1, @2); } 625 798 ; 626 799 627 800 FunctionDeclaration: 628 FUNCTION '(' ')' FunctionBody { YYABORT; } 801 FUNCTION IDENT '(' ')' FunctionBody { $$ = new FuncDeclNode(*$2, $5); } 802 | FUNCTION IDENT '(' FormalParameterList ')' FunctionBody 803 { $$ = new FuncDeclNode(*$2, $4, $6); } 804 ; 805 806 FunctionExpr: 807 FUNCTION '(' ')' FunctionBody { $$ = new FuncExprNode(Identifier::null(), $4); } 629 808 | FUNCTION '(' FormalParameterList ')' FunctionBody 630 { YYABORT; } 631 | FUNCTION IDENT '(' ')' FunctionBody 632 { $$ = new FuncDeclNode(*$2, $5); } 809 { $$ = new FuncExprNode(Identifier::null(), $3, $5); } 810 | FUNCTION IDENT '(' ')' FunctionBody { $$ = new FuncExprNode(*$2, $5); } 633 811 | FUNCTION IDENT '(' FormalParameterList ')' FunctionBody 634 { $$ = new FuncDeclNode(*$2, $4, $6); } 635 ; 636 637 FunctionExpr: 638 FUNCTION '(' ')' FunctionBody { $$ = new FuncExprNode(Identifier::null(), $4); } 639 | FUNCTION '(' FormalParameterList ')' FunctionBody 640 { $$ = new FuncExprNode(Identifier::null(), $3, $5); } 641 | FUNCTION IDENT '(' ')' FunctionBody 642 { $$ = new FuncExprNode(*$2, $5); } 643 | FUNCTION IDENT '(' FormalParameterList ')' FunctionBody 644 { $$ = new FuncExprNode(*$2, $4, $6); } 812 { $$ = new FuncExprNode(*$2, $4, $6); } 645 813 ; 646 814 647 815 FormalParameterList: 648 IDENT { $$ = new ParameterNode(*$1); }649 | FormalParameterList ',' IDENT { $$ = new ParameterNode($1, *$3); }816 IDENT { $$ = new ParameterNode(*$1); } 817 | FormalParameterList ',' IDENT { $$ = new ParameterNode($1, *$3); } 650 818 ; 651 819 652 820 FunctionBody: 653 '{' '}' /* TODO: spec ??? */ { $$ = new FunctionBodyNode(0); 654 DBG($$, @1, @2);} 655 | '{' SourceElements '}' { $$ = new FunctionBodyNode($2); 656 DBG($$, @1, @3);} 821 '{' '}' /* not in spec */ { $$ = new FunctionBodyNode(0); DBG($$, @1, @2); } 822 | '{' SourceElements '}' { $$ = new FunctionBodyNode($2); DBG($$, @1, @3); } 657 823 ; 658 824 659 825 Program: 660 /* nothing, empty script */ { $$ = new ProgramNode(0); 661 Parser::accept($$); } 662 | SourceElements { $$ = new ProgramNode($1); 663 Parser::accept($$); } 826 /* not in spec */ { Parser::accept(new ProgramNode(0)); } 827 | SourceElements { Parser::accept(new ProgramNode($1)); } 664 828 ; 665 829 666 830 SourceElements: 667 SourceElement { $$ = new SourceElementsNode($1); }668 | SourceElements SourceElement { $$ = new SourceElementsNode($1, $2); }831 SourceElement { $$ = new SourceElementsNode($1); } 832 | SourceElements SourceElement { $$ = new SourceElementsNode($1, $2); } 669 833 ; 670 834 671 835 SourceElement: 672 FunctionDeclaration { $$ = $1; }673 | Statement { $$ = $1; }674 ; 675 836 FunctionDeclaration { $$ = $1; } 837 | Statement { $$ = $1; } 838 ; 839 676 840 %% 677 841 678 842 static bool makeAssignNode(Node*& result, Node *loc, Operator op, Node *expr) 679 843 { 680 Node *n = loc; 681 bool paren = n->isGroupNode(); 682 if (paren) 683 n = static_cast<GroupNode *>(n)->nodeInsideAllParens(); 844 Node *n = loc->nodeInsideAllParens(); 684 845 685 846 if (!n->isLocation()) … … 703 864 static bool makePrefixNode(Node*& result, Node *expr, Operator op) 704 865 { 705 Node *n = expr; 706 bool paren = n->isGroupNode(); 707 if (paren) 708 n = static_cast<GroupNode *>(n)->nodeInsideAllParens(); 866 Node *n = expr->nodeInsideAllParens(); 709 867 710 868 if (!n->isLocation()) … … 728 886 static bool makePostfixNode(Node*& result, Node *expr, Operator op) 729 887 { 730 Node *n = expr; 731 bool paren = n->isGroupNode(); 732 if (paren) 733 n = static_cast<GroupNode *>(n)->nodeInsideAllParens(); 888 Node *n = expr->nodeInsideAllParens(); 734 889 735 890 if (!n->isLocation()) … … 753 908 static Node *makeFunctionCallNode(Node *func, ArgumentsNode *args) 754 909 { 755 Node *n = func; 756 bool paren = n->isGroupNode(); 757 if (paren) 758 n = static_cast<GroupNode *>(n)->nodeInsideAllParens(); 910 Node *n = func->nodeInsideAllParens(); 759 911 760 912 if (!n->isLocation()) … … 765 917 } else if (n->isBracketAccessorNode()) { 766 918 BracketAccessorNode *bracket = static_cast<BracketAccessorNode *>(n); 767 if ( paren)919 if (n != func) 768 920 return new FunctionCallParenBracketNode(bracket->base(), bracket->subscript(), args); 769 921 else … … 772 924 assert(n->isDotAccessorNode()); 773 925 DotAccessorNode *dot = static_cast<DotAccessorNode *>(n); 774 if ( paren)926 if (n != func) 775 927 return new FunctionCallParenDotNode(dot->base(), dot->identifier(), args); 776 928 else … … 781 933 static Node *makeTypeOfNode(Node *expr) 782 934 { 783 Node *n = expr; 784 bool paren = n->isGroupNode(); 785 if (paren) 786 n = static_cast<GroupNode *>(n)->nodeInsideAllParens(); 935 Node *n = expr->nodeInsideAllParens(); 787 936 788 937 if (n->isResolveNode()) { … … 795 944 static Node *makeDeleteNode(Node *expr) 796 945 { 797 Node *n = expr; 798 bool paren = n->isGroupNode(); 799 if (paren) 800 n = static_cast<GroupNode *>(n)->nodeInsideAllParens(); 946 Node *n = expr->nodeInsideAllParens(); 801 947 802 948 if (!n->isLocation()) … … 815 961 } 816 962 817 int yyerror 963 int yyerror(const char * /* s */) /* Called by yyparse on error */ 818 964 { 819 // fprintf(stderr, "ERROR: %s at line %d\n", 820 // s, KJS::Lexer::curr()->lineNo()); 965 // fprintf(stderr, "ERROR: %s at line %d\n", s, KJS::Lexer::curr()->lineNo()); 821 966 return 1; 822 967 } 823 968 824 969 /* may we automatically insert a semicolon ? */ 825 bool automatic()970 static bool allowAutomaticSemicolon() 826 971 { 827 if (yychar == '}' || yychar == 0) 828 return true; 829 else if (Lexer::curr()->prevTerminator()) 830 return true; 831 832 return false; 972 return yychar == '}' || yychar == 0 || Lexer::curr()->prevTerminator(); 833 973 } -
trunk/JavaScriptCore/kjs/nodes.cpp
r10636 r10646 60 60 if (exec->hadException()) { \ 61 61 setExceptionDetailsIfNeeded(exec); \ 62 return Completion(Throw, exec->exception()); \ 62 ValueImp *ex = exec->exception(); \ 63 exec->clearException(); \ 64 return Completion(Throw, ex); \ 63 65 } \ 64 66 if (Collector::outOfMemory()) \ … … 68 70 if (exec->hadException()) { \ 69 71 setExceptionDetailsIfNeeded(exec); \ 70 return exec->exception(); \72 return Undefined(); \ 71 73 } \ 72 74 if (Collector::outOfMemory()) \ … … 81 83 return List(); // will be picked up by KJS_CHECKEXCEPTION 82 84 83 #ifdef KJS_DEBUG_MEM84 std::list<Node *> * Node::s_nodes = 0L;85 #endif86 87 85 // ------------------------------ Node ----------------------------------------- 88 86 … … 99 97 } 100 98 101 #ifdef KJS_DEBUG_MEM102 void Node::finalCheck()103 {104 fprintf( stderr, "Node::finalCheck(): list count : %d\n", (int)s_nodes.size() );105 std::list<Node *>::iterator it = s_nodes->begin();106 for ( unsigned i = 0; it != s_nodes->end() ; ++it, ++i )107 fprintf( stderr, "[%d] Still having node %p (%s) (refcount %d)\n", i, (void*)*it, typeid( **it ).name(), (*it)->refcount );108 delete s_nodes;109 s_nodes = 0L;110 }111 #endif112 113 ValueImp *Node::throwError(ExecState *exec, ErrorType e, const char *msg)114 {115 return KJS::throwError(exec, e, msg, lineNo(), sourceId(), &sourceURL);116 }117 118 99 static void substitute(UString &string, const UString &substring) 119 100 { … … 121 102 assert(position != -1); 122 103 string = string.substr(0, position) + substring + string.substr(position + 2); 104 } 105 106 Completion Node::createErrorCompletion(ExecState *exec, ErrorType e, const char *msg) 107 { 108 return Completion(Throw, Error::create(exec, e, msg, lineNo(), sourceId(), &sourceURL)); 109 } 110 111 Completion Node::createErrorCompletion(ExecState *exec, ErrorType e, const char *msg, const Identifier &ident) 112 { 113 UString message = msg; 114 substitute(message, ident.ustring()); 115 return Completion(Throw, Error::create(exec, e, message, lineNo(), sourceId(), &sourceURL)); 116 } 117 118 ValueImp *Node::throwError(ExecState *exec, ErrorType e, const char *msg) 119 { 120 return KJS::throwError(exec, e, msg, lineNo(), sourceId(), &sourceURL); 123 121 } 124 122 … … 163 161 substitute(message, label.ustring()); 164 162 return KJS::throwError(exec, e, message, lineNo(), sourceId(), &sourceURL); 163 } 164 165 ValueImp *Node::throwUndefinedVariableError(ExecState *exec, const Identifier &ident) 166 { 167 return throwError(exec, ReferenceError, "Can't find variable: %s", ident); 165 168 } 166 169 … … 177 180 } 178 181 182 Node *Node::nodeInsideAllParens() 183 { 184 return this; 185 } 186 179 187 // ------------------------------ StatementNode -------------------------------- 180 188 … … 200 208 } 201 209 202 // return true if the debugger wants us to stop at this point203 bool StatementNode::abortStatement(ExecState *exec)204 {205 Debugger *dbg = exec->dynamicInterpreter()->imp()->debugger();206 if (dbg)207 return dbg->imp()->aborted();208 else209 return false;210 }211 212 210 void StatementNode::processFuncDecl(ExecState *exec) 213 211 { … … 216 214 // ------------------------------ NullNode ------------------------------------- 217 215 218 ValueImp *NullNode::evaluate(ExecState * /*exec*/)216 ValueImp *NullNode::evaluate(ExecState *) 219 217 { 220 218 return Null(); … … 223 221 // ------------------------------ BooleanNode ---------------------------------- 224 222 225 ValueImp *BooleanNode::evaluate(ExecState * /*exec*/)223 ValueImp *BooleanNode::evaluate(ExecState *) 226 224 { 227 225 return jsBoolean(value); … … 230 228 // ------------------------------ NumberNode ----------------------------------- 231 229 232 ValueImp *NumberNode::evaluate(ExecState * /*exec*/)230 ValueImp *NumberNode::evaluate(ExecState *) 233 231 { 234 232 return jsNumber(value); … … 237 235 // ------------------------------ StringNode ----------------------------------- 238 236 239 ValueImp *StringNode::evaluate(ExecState * /*exec*/)237 ValueImp *StringNode::evaluate(ExecState *) 240 238 { 241 239 return jsString(value); … … 263 261 264 262 // ------------------------------ ResolveNode ---------------------------------- 265 266 static ValueImp *undefinedVariableError(ExecState *exec, const Identifier &ident)267 {268 return throwError(exec, ReferenceError, "Can't find variable: " + ident.ustring());269 }270 263 271 264 // ECMA 11.1.2 & 10.1.4 … … 289 282 } while (iter != end); 290 283 291 return undefinedVariableError(exec, ident);284 return throwUndefinedVariableError(exec, ident); 292 285 } 293 286 … … 298 291 { 299 292 return group->evaluate(exec); 293 } 294 295 Node *GroupNode::nodeInsideAllParens() 296 { 297 Node *n = this; 298 do 299 n = static_cast<GroupNode *>(n)->group.get(); 300 while (n->isGroupNode()); 301 return n; 300 302 } 301 303 … … 373 375 374 376 // ECMA 11.1.5 375 ValueImp *PropertyNode::evaluate(ExecState * /*exec*/)377 ValueImp *PropertyNode::evaluate(ExecState *) 376 378 { 377 379 ValueImp *s; … … 415 417 // ------------------------------ ArgumentListNode ----------------------------- 416 418 417 ValueImp *ArgumentListNode::evaluate(ExecState * /*exec*/)419 ValueImp *ArgumentListNode::evaluate(ExecState *) 418 420 { 419 421 assert(0); 420 return NULL; // dummy, see evaluateList()422 return 0; // dummy, see evaluateList() 421 423 } 422 424 … … 437 439 // ------------------------------ ArgumentsNode -------------------------------- 438 440 439 ValueImp *ArgumentsNode::evaluate(ExecState * /*exec*/)441 ValueImp *ArgumentsNode::evaluate(ExecState *) 440 442 { 441 443 assert(0); 442 return NULL; // dummy, see evaluateList()444 return 0; // dummy, see evaluateList() 443 445 } 444 446 … … 549 551 } while (iter != end); 550 552 551 return undefinedVariableError(exec, ident);553 return throwUndefinedVariableError(exec, ident); 552 554 } 553 555 … … 672 674 } while (iter != end); 673 675 674 return undefinedVariableError(exec, m_ident);676 return throwUndefinedVariableError(exec, m_ident); 675 677 } 676 678 … … 903 905 } while (iter != end); 904 906 905 return undefinedVariableError(exec, m_ident);907 return throwUndefinedVariableError(exec, m_ident); 906 908 } 907 909 … … 978 980 KJS_CHECKEXCEPTIONVALUE 979 981 980 return jsNumber(v->toNumber(exec)); /* TODO: optimize */982 return jsNumber(v->toNumber(exec)); 981 983 } 982 984 … … 1292 1294 1293 1295 if (m_oper != OpEqual) 1294 return undefinedVariableError(exec, m_ident);1296 return throwUndefinedVariableError(exec, m_ident); 1295 1297 1296 1298 found: … … 1420 1422 Completion c = statement->execute(exec); 1421 1423 KJS_ABORTPOINT 1422 if (exec->hadException()) {1423 ValueImp *ex = exec->exception();1424 exec->clearException();1425 return Completion(Throw, ex);1426 }1427 1428 1424 if (c.complType() != Normal) 1429 1425 return c; … … 1437 1433 return c2; 1438 1434 1439 if (exec->hadException()) {1440 ValueImp *ex = exec->exception();1441 exec->clearException();1442 return Completion(Throw, ex);1443 }1444 1445 1435 if (c2.isValueCompletion()) 1446 1436 v = c2.value(); … … 1486 1476 // built-in properties of the global object with var declarations. 1487 1477 if (variable->getDirect(ident)) 1488 return NULL;1478 return 0; 1489 1479 val = Undefined(); 1490 1480 } … … 1590 1580 1591 1581 // ECMA 12.3 1592 Completion EmptyStatementNode::execute(ExecState * /*exec*/)1582 Completion EmptyStatementNode::execute(ExecState *) 1593 1583 { 1594 1584 return Completion(Normal); … … 1658 1648 if (!((c.complType() == Continue) && ls.contains(c.target()))) { 1659 1649 if ((c.complType() == Break) && ls.contains(c.target())) 1660 return Completion(Normal, NULL);1650 return Completion(Normal, 0); 1661 1651 if (c.complType() != Normal) 1662 1652 return c; … … 1666 1656 } while (bv->toBoolean(exec)); 1667 1657 1668 return Completion(Normal, NULL);1658 return Completion(Normal, 0); 1669 1659 } 1670 1660 … … 1684 1674 Completion c; 1685 1675 bool b(false); 1686 ValueImp *value = NULL;1676 ValueImp *value = 0; 1687 1677 1688 1678 while (1) { … … 1724 1714 Completion ForNode::execute(ExecState *exec) 1725 1715 { 1726 ValueImp *v, *cval = NULL;1716 ValueImp *v, *cval = 0; 1727 1717 1728 1718 if (expr1) { … … 1787 1777 { 1788 1778 ValueImp *e; 1789 ValueImp *retval = NULL;1779 ValueImp *retval = 0; 1790 1780 ObjectImp *v; 1791 1781 Completion c; … … 1804 1794 // access any property. 1805 1795 if (e->isUndefinedOrNull()) { 1806 return Completion(Normal, NULL);1796 return Completion(Normal, 0); 1807 1797 } 1808 1798 … … 1903 1893 1904 1894 if (ident.isEmpty() && !exec->context().imp()->seenLabels()->inIteration()) 1905 return Completion(Throw, 1906 throwError(exec, SyntaxError, "Invalid continue statement.")); 1895 return createErrorCompletion(exec, SyntaxError, "Invalid continue statement."); 1907 1896 else if (!ident.isEmpty() && !exec->context().imp()->seenLabels()->contains(ident)) 1908 return Completion(Throw, 1909 throwError(exec, SyntaxError, "Label %s not found.", ident)); 1897 return createErrorCompletion(exec, SyntaxError, "Label %s not found.", ident); 1910 1898 else 1911 return Completion(Continue, NULL, ident);1899 return Completion(Continue, 0, ident); 1912 1900 } 1913 1901 … … 1921 1909 if (ident.isEmpty() && !exec->context().imp()->seenLabels()->inIteration() && 1922 1910 !exec->context().imp()->seenLabels()->inSwitch()) 1923 return Completion(Throw, 1924 throwError(exec, SyntaxError, "Invalid break statement.")); 1911 return createErrorCompletion(exec, SyntaxError, "Invalid break statement."); 1925 1912 else if (!ident.isEmpty() && !exec->context().imp()->seenLabels()->contains(ident)) 1926 return Completion(Throw, 1927 throwError(exec, SyntaxError, "Label %s not found.", ident)); 1913 return createErrorCompletion(exec, SyntaxError, "Label %s not found."); 1928 1914 else 1929 return Completion(Break, NULL, ident);1915 return Completion(Break, 0, ident); 1930 1916 } 1931 1917 … … 1939 1925 CodeType codeType = exec->context().imp()->codeType(); 1940 1926 if (codeType != FunctionCode && codeType != AnonymousCode ) { 1941 return Completion(Throw, throwError(exec, SyntaxError, "Invalid return statement."));1927 return createErrorCompletion(exec, SyntaxError, "Invalid return statement."); 1942 1928 } 1943 1929 … … 2002 1988 // ------------------------------ ClauseListNode ------------------------------- 2003 1989 2004 ValueImp *ClauseListNode::evaluate(ExecState * /*exec*/)2005 { 2006 / * should never be called */1990 ValueImp *ClauseListNode::evaluate(ExecState *) 1991 { 1992 // should never be called 2007 1993 assert(false); 2008 return NULL;1994 return 0; 2009 1995 } 2010 1996 … … 2039 2025 } 2040 2026 2041 ValueImp *CaseBlockNode::evaluate(ExecState * /*exec*/)2042 { 2043 / * should never be called */2027 ValueImp *CaseBlockNode::evaluate(ExecState *) 2028 { 2029 // should never be called 2044 2030 assert(false); 2045 return NULL;2031 return 0; 2046 2032 } 2047 2033 … … 2148 2134 Completion LabelNode::execute(ExecState *exec) 2149 2135 { 2150 Completion e; 2151 2152 if (!exec->context().imp()->seenLabels()->push(label)) { 2153 return Completion( Throw, 2154 throwError(exec, SyntaxError, "Duplicated label %s found.", label)); 2155 }; 2156 e = statement->execute(exec); 2136 if (!exec->context().imp()->seenLabels()->push(label)) 2137 return createErrorCompletion(exec, SyntaxError, "Duplicated label %s found.", label); 2138 Completion e = statement->execute(exec); 2157 2139 exec->context().imp()->seenLabels()->pop(); 2158 2140 … … 2180 2162 } 2181 2163 2182 // ------------------------------ CatchNode ------------------------------------2183 2184 Completion CatchNode::execute(ExecState */*exec*/)2185 {2186 // should never be reached. execute(exec, arg) is used instead2187 assert(0L);2188 return Completion();2189 }2190 2191 // ECMA 12.142192 Completion CatchNode::execute(ExecState *exec, ValueImp *arg)2193 {2194 /* TODO: correct ? Not part of the spec */2195 2196 exec->clearException();2197 2198 ObjectImp *obj(new ObjectImp());2199 obj->put(exec, ident, arg, DontDelete);2200 exec->context().imp()->pushScope(obj);2201 Completion c = block->execute(exec);2202 exec->context().imp()->popScope();2203 2204 return c;2205 }2206 2207 void CatchNode::processVarDecls(ExecState *exec)2208 {2209 block->processVarDecls(exec);2210 }2211 2212 // ------------------------------ FinallyNode ----------------------------------2213 2214 // ECMA 12.142215 Completion FinallyNode::execute(ExecState *exec)2216 {2217 return block->execute(exec);2218 }2219 2220 void FinallyNode::processVarDecls(ExecState *exec)2221 {2222 block->processVarDecls(exec);2223 }2224 2225 2164 // ------------------------------ TryNode -------------------------------------- 2226 2165 … … 2230 2169 KJS_BREAKPOINT; 2231 2170 2232 Completion c, c2; 2233 2234 c = block->execute(exec); 2235 2236 if (!_final) { 2237 if (c.complType() != Throw) 2238 return c; 2239 return _catch->execute(exec,c.value()); 2240 } 2241 2242 if (!_catch) { 2243 ValueImp *lastException = exec->exception(); 2244 exec->clearException(); 2245 2246 c2 = _final->execute(exec); 2247 2248 if (!exec->hadException()) 2249 exec->setException(lastException); 2250 2251 return (c2.complType() == Normal) ? c : c2; 2252 } 2253 2254 if (c.complType() == Throw) 2255 c = _catch->execute(exec,c.value()); 2256 2257 c2 = _final->execute(exec); 2258 return (c2.complType() == Normal) ? c : c2; 2171 Completion c = tryBlock->execute(exec); 2172 2173 if (catchBlock && c.complType() == Throw) { 2174 ObjectImp *obj = new ObjectImp; 2175 obj->put(exec, exceptionIdent, c.value(), DontDelete); 2176 exec->context().imp()->pushScope(obj); 2177 c = catchBlock->execute(exec); 2178 exec->context().imp()->popScope(); 2179 } 2180 2181 if (finallyBlock) { 2182 Completion c2 = finallyBlock->execute(exec); 2183 if (c2.complType() != Normal) 2184 c = c2; 2185 } 2186 2187 return c; 2259 2188 } 2260 2189 2261 2190 void TryNode::processVarDecls(ExecState *exec) 2262 2191 { 2263 block->processVarDecls(exec);2264 if ( _final)2265 _final->processVarDecls(exec);2266 if ( _catch)2267 _catch->processVarDecls(exec);2192 tryBlock->processVarDecls(exec); 2193 if (catchBlock) 2194 catchBlock->processVarDecls(exec); 2195 if (finallyBlock) 2196 finallyBlock->processVarDecls(exec); 2268 2197 } 2269 2198 … … 2271 2200 2272 2201 // ECMA 13 2273 ValueImp *ParameterNode::evaluate(ExecState * /*exec*/)2202 ValueImp *ParameterNode::evaluate(ExecState *) 2274 2203 { 2275 2204 return Undefined(); … … 2282 2211 { 2283 2212 setLoc(-1, -1, -1); 2284 //fprintf(stderr,"FunctionBodyNode::FunctionBodyNode %p\n",this);2285 2213 } 2286 2214 … … 2299 2227 2300 2228 // TODO: let this be an object with [[Class]] property "Function" 2301 FunctionImp *fimp = new DeclaredFunctionImp(exec, ident, body.get(), context->scopeChain()); 2302 ObjectImp *func(fimp); // protect from GC 2229 FunctionImp *func = new DeclaredFunctionImp(exec, ident, body.get(), context->scopeChain()); 2303 2230 2304 2231 ObjectImp *proto = exec->lexicalInterpreter()->builtinObject()->construct(exec, List::empty()); … … 2308 2235 int plen = 0; 2309 2236 for(ParameterNode *p = param.get(); p != 0L; p = p->nextParam(), plen++) 2310 f imp->addParameter(p->ident());2237 func->addParameter(p->ident()); 2311 2238 2312 2239 func->put(exec, lengthPropertyName, Number(plen), ReadOnly|DontDelete|DontEnum); … … 2327 2254 } 2328 2255 2256 Completion FuncDeclNode::execute(ExecState *) 2257 { 2258 return Completion(Normal); 2259 } 2260 2329 2261 // ------------------------------ FuncExprNode --------------------------------- 2330 2262 … … 2334 2266 ContextImp *context = exec->context().imp(); 2335 2267 bool named = !ident.isNull(); 2336 ObjectImp *functionScopeObject = NULL;2268 ObjectImp *functionScopeObject = 0; 2337 2269 2338 2270 if (named) { … … 2344 2276 } 2345 2277 2346 FunctionImp *fimp = new DeclaredFunctionImp(exec, ident, body.get(), context->scopeChain()); 2347 ValueImp *ret(fimp); 2278 FunctionImp *func = new DeclaredFunctionImp(exec, ident, body.get(), context->scopeChain()); 2348 2279 ObjectImp *proto = exec->lexicalInterpreter()->builtinObject()->construct(exec, List::empty()); 2349 proto->put(exec, constructorPropertyName, ret, ReadOnly|DontDelete|DontEnum);2350 f imp->put(exec, prototypePropertyName, proto, Internal|DontDelete);2280 proto->put(exec, constructorPropertyName, func, ReadOnly|DontDelete|DontEnum); 2281 func->put(exec, prototypePropertyName, proto, Internal|DontDelete); 2351 2282 2352 2283 int plen = 0; 2353 2284 for(ParameterNode *p = param.get(); p != 0L; p = p->nextParam(), plen++) 2354 f imp->addParameter(p->ident());2285 func->addParameter(p->ident()); 2355 2286 2356 2287 if (named) { 2357 functionScopeObject->put(exec, ident, ret, Internal | ReadOnly | (context->codeType() == EvalCode ? 0 : DontDelete));2288 functionScopeObject->put(exec, ident, func, Internal | ReadOnly | (context->codeType() == EvalCode ? 0 : DontDelete)); 2358 2289 context->popScope(); 2359 2290 } 2360 2291 2361 return ret;2292 return func; 2362 2293 } 2363 2294 -
trunk/JavaScriptCore/kjs/nodes.h
r10634 r10646 30 30 31 31 #include "internal.h" 32 //#include "debugger.h"33 #ifndef NDEBUG34 #ifndef __osf__35 #include <list>36 #endif37 #endif38 32 39 33 namespace KJS { … … 86 80 UString toString() const; 87 81 virtual void streamTo(SourceStream &s) const = 0; 88 virtual void processVarDecls(ExecState * /*exec*/) {}82 virtual void processVarDecls(ExecState *) {} 89 83 int lineNo() const { return line; } 90 84 91 public:92 85 // reference counting mechanism 93 86 void ref() { ++m_refcount; } … … 95 88 unsigned int refcount() { return m_refcount; } 96 89 97 virtual bool isGroupNode() const { return false; }90 virtual Node *nodeInsideAllParens(); 98 91 99 92 virtual bool isLocation() const { return false; } … … 101 94 virtual bool isBracketAccessorNode() const { return false; } 102 95 virtual bool isDotAccessorNode() const { return false; } 96 virtual bool isGroupNode() const { return false; } 103 97 104 98 protected: 105 ValueImp *throwError(ExecState *exec, ErrorType e, const char *msg); 106 ValueImp *throwError(ExecState *exec, ErrorType e, const char *msg, ValueImp *, Node *); 107 ValueImp *throwError(ExecState *exec, ErrorType e, const char *msg, const Identifier &); 108 ValueImp *throwError(ExecState *exec, ErrorType e, const char *msg, ValueImp *, const Identifier &); 109 ValueImp *throwError(ExecState *exec, ErrorType e, const char *msg, ValueImp *, Node *, Node *); 110 ValueImp *throwError(ExecState *exec, ErrorType e, const char *msg, ValueImp *, Node *, const Identifier &); 111 112 void setExceptionDetailsIfNeeded(ExecState *exec); 99 Completion createErrorCompletion(ExecState *, ErrorType, const char *msg); 100 Completion createErrorCompletion(ExecState *, ErrorType, const char *msg, const Identifier &); 101 102 ValueImp *throwError(ExecState *, ErrorType, const char *msg); 103 ValueImp *throwError(ExecState *, ErrorType, const char *msg, ValueImp *, Node *); 104 ValueImp *throwError(ExecState *, ErrorType, const char *msg, const Identifier &); 105 ValueImp *throwError(ExecState *, ErrorType, const char *msg, ValueImp *, const Identifier &); 106 ValueImp *throwError(ExecState *, ErrorType, const char *msg, ValueImp *, Node *, Node *); 107 ValueImp *throwError(ExecState *, ErrorType, const char *msg, ValueImp *, Node *, const Identifier &); 108 109 ValueImp *throwUndefinedVariableError(ExecState *, const Identifier &); 110 111 void setExceptionDetailsIfNeeded(ExecState *); 112 113 113 int line; 114 114 UString sourceURL; 115 115 unsigned int m_refcount; 116 116 virtual int sourceId() const { return -1; } 117 117 118 private: 118 119 // disallow assignment … … 129 130 int sourceId() const { return sid; } 130 131 bool hitStatement(ExecState *exec); 131 bool abortStatement(ExecState *exec);132 132 virtual Completion execute(ExecState *exec) = 0; 133 133 void pushLabel(const Identifier &id) { ls.push(id); } … … 211 211 GroupNode(Node *g) : group(g) { } 212 212 virtual ValueImp *evaluate(ExecState *exec); 213 virtual void streamTo(SourceStream &s) const;214 213 virtual Node *nodeInsideAllParens(); 214 virtual void streamTo(SourceStream &s) const; 215 215 virtual bool isGroupNode() const { return true; } 216 Node *nodeInsideAllParens()217 {218 Node *n = group.get();219 while (n->isGroupNode()) {220 n = static_cast<GroupNode *>(n)->group.get();221 }222 return n;223 }224 225 216 private: 226 217 SharedPtr<Node> group; … … 1001 992 }; 1002 993 1003 class CatchNode : public StatementNode {1004 public:1005 CatchNode(const Identifier &i, StatementNode *b) : ident(i), block(b) {}1006 virtual Completion execute(ExecState *exec);1007 Completion execute(ExecState *exec, ValueImp *arg);1008 virtual void processVarDecls(ExecState *exec);1009 virtual void streamTo(SourceStream &s) const;1010 private:1011 Identifier ident;1012 SharedPtr<StatementNode> block;1013 };1014 1015 class FinallyNode : public StatementNode {1016 public:1017 FinallyNode(StatementNode *b) : block(b) {}1018 virtual Completion execute(ExecState *exec);1019 virtual void processVarDecls(ExecState *exec);1020 virtual void streamTo(SourceStream &s) const;1021 private:1022 SharedPtr<StatementNode> block;1023 };1024 1025 994 class TryNode : public StatementNode { 1026 995 public: 1027 TryNode(StatementNode *b, CatchNode *c) 1028 : block(b), _catch(c), _final(0) {} 1029 TryNode(StatementNode *b, FinallyNode *f) 1030 : block(b), _catch(0), _final(f) {} 1031 TryNode(StatementNode *b, CatchNode *c, FinallyNode *f) 1032 : block(b), _catch(c), _final(f) {} 1033 virtual Completion execute(ExecState *exec); 1034 virtual void processVarDecls(ExecState *exec); 1035 virtual void streamTo(SourceStream &s) const; 1036 private: 1037 SharedPtr<StatementNode> block; 1038 SharedPtr<CatchNode> _catch; 1039 SharedPtr<FinallyNode> _final; 996 TryNode(StatementNode *b, const Identifier &e, StatementNode *c, StatementNode *f) 997 : tryBlock(b), exceptionIdent(e), catchBlock(c), finallyBlock(f) { } 998 virtual Completion execute(ExecState *exec); 999 virtual void processVarDecls(ExecState *exec); 1000 virtual void streamTo(SourceStream &s) const; 1001 private: 1002 SharedPtr<StatementNode> tryBlock; 1003 Identifier exceptionIdent; 1004 SharedPtr<StatementNode> catchBlock; 1005 SharedPtr<StatementNode> finallyBlock; 1040 1006 }; 1041 1007 … … 1070 1036 FuncExprNode(const Identifier &i, ParameterNode *p, FunctionBodyNode *b) 1071 1037 : ident(i), param(p->next), body(b) { p->next = 0; } 1072 ValueImp *evaluate(ExecState *exec); 1073 virtual void streamTo(SourceStream &s) const; 1074 1075 private: 1076 friend class FuncDeclNode; 1077 1038 virtual ValueImp *evaluate(ExecState *); 1039 virtual void streamTo(SourceStream &) const; 1040 private: 1078 1041 Identifier ident; 1079 1042 SharedPtr<ParameterNode> param; … … 1087 1050 FuncDeclNode(const Identifier &i, ParameterNode *p, FunctionBodyNode *b) 1088 1051 : ident(i), param(p->next), body(b) { p->next = 0; } 1089 Completion execute(ExecState */*exec*/) 1090 { /* empty */ return Completion(); } 1091 void processFuncDecl(ExecState *exec); 1092 virtual void streamTo(SourceStream &s) const; 1052 virtual Completion execute(ExecState *); 1053 virtual void processFuncDecl(ExecState *); 1054 virtual void streamTo(SourceStream &) const; 1093 1055 private: 1094 1056 Identifier ident; -
trunk/JavaScriptCore/kjs/nodes2string.cpp
r10634 r10646 1 // -*- c-basic-offset: 2 -*-2 1 /* 3 2 * This file is part of the KDE libraries … … 665 664 } 666 665 667 void CatchNode::streamTo(SourceStream &s) const668 {669 s << SourceStream::Endl << "catch (" << ident << ")" << block;670 }671 672 void FinallyNode::streamTo(SourceStream &s) const673 {674 s << SourceStream::Endl << "finally " << block;675 }676 677 666 void TryNode::streamTo(SourceStream &s) const 678 667 { 679 s << "try " << block 680 << _catch 681 << _final; 668 s << "try " << tryBlock; 669 if (catchBlock) 670 s << SourceStream::Endl << "catch (" << exceptionIdent << ")" << catchBlock; 671 if (finallyBlock) 672 s << SourceStream::Endl << "finally " << finallyBlock; 682 673 } 683 674 … … 689 680 } 690 681 691 void FuncDeclNode::streamTo(SourceStream &s) const { 692 s << "function " << ident << "("; 693 if (param) 694 s << param; 695 s << ")" << body; 682 void FuncDeclNode::streamTo(SourceStream &s) const 683 { 684 s << "function " << ident << "(" << param << ")" << body; 696 685 } 697 686 698 687 void FuncExprNode::streamTo(SourceStream &s) const 699 688 { 700 s << "function " << "(" 701 << param 702 << ")" << body; 689 s << "function " << ident << "(" << param << ")" << body; 703 690 } 704 691 … … 708 695 s << n->element; 709 696 } 710
Note:
See TracChangeset
for help on using the changeset viewer.