Skip to content

Commit

Permalink
[MERGE #936] Fix numerous issues with Use Before Declaration
Browse files Browse the repository at this point in the history
Merge pull request #936 from ianwjhalliday:fix505
Fixes #505 and VSO 5425942

Emit() needs to visit all AST nodes so that various algorithms can
collect data and set info on symbols and such, assign locations etc.

In our implementation of the let/const lexical variable Use Before
Declaration error, we had a call to EmitUseBeforeDeclaration() at the
beginning of Emit() and would exit early if it decided to emit the error
into the bytecode.  This would prevent visitation of subtrees in certain
cases, like e.g. issue #505.  It would do this for assignments, i.e.
stores.  Detection for Use Before Declaration for loads (and typeof)
are done in EmitPropLoad and EmitPropTypeof.

This fix pushes Use Before Declaration detection for stores down into
EmitPropStore and fixes up where we clear the `needsDeclaration` flag on
symbols that we weren't doing exactly right for EmitPropStore to work
this way.

Summary of changes

 - Tweak parse tree tracing to note deferred funcs
 - Change EmitPropStore to emit static UseBeforeDecl
 - Consolidate Emit() of knop[Var|Let|Const]Decl
 - Reduce code duplication in TrackMemberNodesInObjectForIntConstants
 - Add missing EmitUseBeforeDeclaration in EmitReference for knopCall
 - Remove EmitUseBeforeDeclaration for knopVarDecl case in Emit()
 - Remove redundant parameter fLoadUndef from
   EmitUseBeforeDeclarationRuntimeError().  Use the presence of the
   location parameter to indicate that a LdUndef is needed instead.
 - Remove fAcquire param from EmitUseBeforeDeclaration
 - Remove pnodeNeedUndef parameter from EmitUseBeforeDeclaration
 - Remove always true fAssignRegs parameter from EmitApplyCall.
 - Removed call to EmitUseBeforeDeclaration in
   EmitCallTargetNoEvalComponents.  This was the only remaining call
   that used pnodeNeedUndef, hence ability to remove that parameter
   from EmitUseBeforeDeclaration.
 - Added three test cases to unittests
  • Loading branch information
Ian Halliday committed May 12, 2016
2 parents e477b13 + 008cc68 commit ea29437
Show file tree
Hide file tree
Showing 3 changed files with 161 additions and 162 deletions.
6 changes: 6 additions & 0 deletions lib/Parser/Parse.cpp
Expand Up @@ -12915,6 +12915,12 @@ void PrintPnodeWIndent(ParseNode *pnode,int indentAmt) {
PrintFormalsWIndent(pnode->sxFnc.pnodeParams, indentAmt + INDENT_SIZE);
PrintPnodeWIndent(pnode->sxFnc.pnodeRest, indentAmt + INDENT_SIZE);
PrintPnodeWIndent(pnode->sxFnc.pnodeBody, indentAmt + INDENT_SIZE);
if (pnode->sxFnc.pnodeBody == nullptr)
{
Output::Print(_u("[%4d, %4d): "), pnode->ichMin, pnode->ichLim);
Indent(indentAmt + INDENT_SIZE);
Output::Print(_u("<parse deferred body>\n"));
}
break;
//PTNODE(knopProg , "program" ,None ,Fnc ,fnopNone)
case knopProg:
Expand Down

0 comments on commit ea29437

Please sign in to comment.