Skip to content

Commit a4058ce

Browse files
committed
Parser refactor: More use stronger type instead of casting from ParseNode
Also updated the ParseNodeFnc and ParseNodeProg constructor to initialize its field with default values Remove unused fields in ParseNodeBin and ParseNodeTri Reconfigure fields in ParseNode to save space. ParseNode is not 8 byte smaller, and ParseNodeBin is 16 bytes smaller on 64-bit.
1 parent d25db2e commit a4058ce

17 files changed

+971
-934
lines changed

lib/Parser/Hash.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,14 @@ void Ident::SetTk(tokens token, ushort grfid)
206206
}
207207
}
208208

209+
void Ident::TrySetIsUsedInLdElem(ParseNode * pnode)
210+
{
211+
if (pnode && pnode->nop == knopStr)
212+
{
213+
pnode->AsParseNodePid()->pid->SetIsUsedInLdElem(true);
214+
}
215+
}
216+
209217
IdentPtr HashTbl::PidFromTk(tokens token)
210218
{
211219
Assert(token > tkNone && token < tkID);

lib/Parser/Hash.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,7 @@ struct Ident
172172
this->isUsedInLdElem = is;
173173
}
174174

175-
static void TrySetIsUsedInLdElem(ParseNode * pnode)
176-
{
177-
if (pnode && pnode->nop == knopStr)
178-
{
179-
pnode->AsParseNodePid()->pid->SetIsUsedInLdElem(true);
180-
}
181-
}
175+
static void TrySetIsUsedInLdElem(ParseNode * pnode);
182176

183177
bool IsSingleAssignment()
184178
{

lib/Parser/Parse.cpp

Lines changed: 239 additions & 299 deletions
Large diffs are not rendered by default.

lib/Parser/Parse.h

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -272,19 +272,19 @@ class Parser
272272
ParseNodePid * CreateNameNode(IdentPtr pid);
273273
ParseNodePid * CreateNameNode(IdentPtr pid, PidRefStack * ref, charcount_t ichMin, charcount_t ichLim);
274274
ParseNodeSpecialName * CreateSpecialNameNode(IdentPtr pid, PidRefStack * ref, charcount_t ichMin, charcount_t ichLim);
275-
ParseNodeSuperReference * CreateSuperReferenceNode(OpCode nop, ParseNodePtr pnode1, ParseNodePtr pnode2);
276-
ParseNodeProg * CreateProgNode(bool isModuleSource);
275+
ParseNodeSuperReference * CreateSuperReferenceNode(OpCode nop, ParseNodeSpecialName * pnode1, ParseNodePtr pnode2);
276+
ParseNodeProg * CreateProgNode(bool isModuleSource, ULONG lineNumber);
277277

278278
ParseNodeCall * CreateCallNode(OpCode nop, ParseNodePtr pnode1, ParseNodePtr pnode2);
279279
ParseNodeCall * CreateCallNode(OpCode nop, ParseNodePtr pnode1, ParseNodePtr pnode2, charcount_t ichMin, charcount_t ichLim);
280-
ParseNodeSuperCall * CreateSuperCallNode(ParseNodePtr pnode1, ParseNodePtr pnode2);
280+
ParseNodeSuperCall * CreateSuperCallNode(ParseNodeSpecialName * pnode1, ParseNodePtr pnode2);
281281

282282
ParseNodeFnc * CreateDummyFuncNode(bool fDeclaration);
283283

284284
ParseNodeParamPattern * CreateParamPatternNode(ParseNodePtr pnode1);
285285
ParseNodeParamPattern * CreateDummyParamPatternNode(charcount_t ichMin);
286286

287-
Symbol* AddDeclForPid(ParseNodePtr pnode, IdentPtr pid, SymbolType symbolType, bool errorOnRedecl);
287+
Symbol* AddDeclForPid(ParseNodeVar * pnode, IdentPtr pid, SymbolType symbolType, bool errorOnRedecl);
288288
void CheckRedeclarationErrorForBlockId(IdentPtr pid, int blockId);
289289

290290
public:
@@ -431,12 +431,12 @@ class Parser
431431
bool NextTokenIsPropertyNameStart() const { return m_token.tk == tkID || m_token.tk == tkStrCon || m_token.tk == tkIntCon || m_token.tk == tkFltCon || m_token.tk == tkLBrack || m_token.IsReservedWord(); }
432432

433433
template<bool buildAST>
434-
void PushStmt(StmtNest *pStmt, ParseNodePtr pnode, OpCode op, LabelId* pLabelIdList)
434+
void PushStmt(StmtNest *pStmt, ParseNodeStmt * pnode, OpCode op, LabelId* pLabelIdList)
435435
{
436436
if (buildAST)
437437
{
438-
pnode->AsParseNodeStmt()->grfnop = 0;
439-
pnode->AsParseNodeStmt()->pnodeOuter = (NULL == m_pstmtCur) ? NULL : m_pstmtCur->pnodeStmt;
438+
pnode->grfnop = 0;
439+
pnode->pnodeOuter = (NULL == m_pstmtCur) ? NULL : m_pstmtCur->pnodeStmt;
440440

441441
pStmt->pnodeStmt = pnode;
442442
}
@@ -662,7 +662,9 @@ class Parser
662662
StrictModeEnvironment smEnvironment = SM_NotUsed,
663663
const bool isSourceElementList = false,
664664
bool* strictModeOn = NULL);
665+
#if ENABLE_BACKGROUND_PARSING
665666
bool FastScanFormalsAndBody();
667+
#endif
666668
bool ScanAheadToFunctionEnd(uint count);
667669

668670
bool DoParallelParse(ParseNodeFnc * pnodeFnc) const;
@@ -730,10 +732,10 @@ class Parser
730732
void ParseTopLevelDeferredFunc(ParseNodeFnc * pnodeFnc, ParseNodeFnc * pnodeFncParent, LPCOLESTR pNameHint, bool fLambda, bool *pNeedScanRCurly = nullptr);
731733
void ParseNestedDeferredFunc(ParseNodeFnc * pnodeFnc, bool fLambda, bool *pNeedScanRCurly, bool *pStrictModeTurnedOn);
732734
void CheckStrictFormalParameters();
733-
ParseNodePtr AddArgumentsNodeToVars(ParseNodeFnc * pnodeFnc);
735+
ParseNodeVar * AddArgumentsNodeToVars(ParseNodeFnc * pnodeFnc);
734736
ParseNodeVar * InsertVarAtBeginning(ParseNodeFnc * pnodeFnc, IdentPtr pid);
735737
ParseNodeVar * CreateSpecialVarDeclNode(ParseNodeFnc * pnodeFnc, IdentPtr pid);
736-
void UpdateArgumentsNode(ParseNodeFnc * pnodeFnc, ParseNodePtr argNode);
738+
void UpdateArgumentsNode(ParseNodeFnc * pnodeFnc, ParseNodeVar * argNode);
737739
void UpdateOrCheckForDuplicateInFormals(IdentPtr pid, SList<IdentPtr> *formals);
738740

739741
LPCOLESTR GetFunctionName(ParseNodeFnc * pnodeFnc, LPCOLESTR pNameHint);
@@ -753,7 +755,7 @@ class Parser
753755

754756
// Construct the name from the parse node.
755757
LPCOLESTR FormatPropertyString(LPCOLESTR propertyString, ParseNodePtr pNode, uint32 *fullNameHintLength, uint32 *pShortNameOffset);
756-
LPCOLESTR ConstructNameHint(ParseNodePtr pNode, uint32* fullNameHintLength, uint32 *pShortNameOffset);
758+
LPCOLESTR ConstructNameHint(ParseNodeBin * pNode, uint32* fullNameHintLength, uint32 *pShortNameOffset);
757759
LPCOLESTR AppendNameHints(IdentPtr left, IdentPtr right, uint32 *pNameLength, uint32 *pShortNameOffset, bool ignoreAddDotWithSpace = false, bool wrapInBrackets = false);
758760
LPCOLESTR AppendNameHints(IdentPtr left, LPCOLESTR right, uint32 *pNameLength, uint32 *pShortNameOffset, bool ignoreAddDotWithSpace = false, bool wrapInBrackets = false);
759761
LPCOLESTR AppendNameHints(LPCOLESTR left, IdentPtr right, uint32 *pNameLength, uint32 *pShortNameOffset, bool ignoreAddDotWithSpace = false, bool wrapInBrackets = false);
@@ -966,7 +968,7 @@ class Parser
966968

967969
template <class Fn>
968970
void FinishFunctionsInScope(ParseNodePtr pnodeScopeList, Fn fn);
969-
void FinishDeferredFunction(ParseNodePtr pnodeScopeList);
971+
void FinishDeferredFunction(ParseNodeBlock * pnodeScopeList);
970972

971973
/***********************************************************************
972974
Misc

0 commit comments

Comments
 (0)