Skip to content

Commit d207bf8

Browse files
committed
Remove unused ScanFlagSuppressIdPid mode, and refactor Ident::Tk to replace HashTbl::TkFromNameLen
1 parent 08d7955 commit d207bf8

File tree

4 files changed

+50
-70
lines changed

4 files changed

+50
-70
lines changed

lib/Parser/Hash.cpp

Lines changed: 41 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,46 @@ uint HashTbl::CountAndVerifyItems(IdentPtr *buckets, uint bucketCount, uint mask
157157
}
158158
#endif
159159

160+
160161
#pragma warning(push)
161-
#pragma warning(disable:4740) // flow in or out of inline asm code suppresses global optimization
162+
#pragma warning(disable:4740) // flow in or out of inline asm code suppresses global optimization
163+
164+
// Decide if token is keyword by string matching -
165+
// This method is used during colorizing when scanner isn't interested in storing the actual id and does not care about conversion of escape sequences
166+
tokens Ident::TkFromNameLen(uint32 luHash, _In_reads_(cch) LPCOLESTR prgch, uint32 cch, bool isStrictMode, ushort * pgrfid, ushort * ptk)
167+
{
168+
// look for a keyword
169+
#include "kwds_sw.h"
170+
171+
#define KEYWORD(tk,f,prec2,nop2,prec1,nop1,name) \
172+
LEqual_##name: \
173+
if (cch == g_ssym_##name.cch && \
174+
0 == memcmp(g_ssym_##name.sz, prgch, cch * sizeof(OLECHAR))) \
175+
{ \
176+
if (f) \
177+
*pgrfid |= f; \
178+
*ptk = tk; \
179+
return ((f & fidKwdRsvd) || (isStrictMode && (f & fidKwdFutRsvd))) ? tk : tkID; \
180+
} \
181+
goto LDefault;
182+
#include "keywords.h"
183+
184+
LDefault:
185+
return tkID;
186+
}
187+
188+
#pragma warning(pop)
189+
190+
#if DBG
191+
tokens Ident::TkFromNameLen(_In_reads_(cch) LPCOLESTR prgch, uint32 cch, bool isStrictMode)
192+
{
193+
uint32 luHash = CaseSensitiveComputeHash(prgch, prgch + cch);
194+
ushort grfid;
195+
ushort tk;
196+
return TkFromNameLen(luHash, prgch, cch, isStrictMode, &grfid, &tk);
197+
}
198+
#endif
199+
162200
tokens Ident::Tk(bool isStrictMode)
163201
{
164202
const tokens token = (tokens)m_tk;
@@ -168,22 +206,8 @@ tokens Ident::Tk(bool isStrictMode)
168206
const uint32 luHash = this->m_luHash;
169207
const LPCOLESTR prgch = Psz();
170208
const uint32 cch = Cch();
171-
#include "kwds_sw.h"
172-
173-
#define KEYWORD(tk,f,prec2,nop2,prec1,nop1,name) \
174-
LEqual_##name: \
175-
if (cch == g_ssym_##name.cch && \
176-
0 == memcmp(g_ssym_##name.sz, prgch, cch * sizeof(OLECHAR))) \
177-
{ \
178-
if (f) \
179-
this->m_grfid |= f; \
180-
this->m_tk = tk; \
181-
return ((f & fidKwdRsvd) || (isStrictMode && (f & fidKwdFutRsvd))) ? tk : tkID; \
182-
} \
183-
goto LDefault;
184-
#include "keywords.h"
185-
LDefault:
186-
return tkID;
209+
210+
return TkFromNameLen(luHash, prgch, cch, isStrictMode, &this->m_grfid, &this->m_tk);
187211
}
188212
else if (token == tkNone || !(m_grfid & fidKwdRsvd))
189213
{
@@ -194,7 +218,6 @@ tokens Ident::Tk(bool isStrictMode)
194218
}
195219
return token;
196220
}
197-
#pragma warning(pop)
198221

199222
void Ident::SetTk(tokens token, ushort grfid)
200223
{
@@ -423,33 +446,6 @@ bool HashTbl::Contains(_In_reads_(cch) LPCOLESTR prgch, int32 cch)
423446

424447
#include "HashFunc.cpp"
425448

426-
#pragma warning(push)
427-
#pragma warning(disable:4740) // flow in or out of inline asm code suppresses global optimization
428-
429-
// Decide if token is keyword by string matching -
430-
// This method is used during colorizing when scanner isn't interested in storing the actual id and does not care about conversion of escape sequences
431-
tokens HashTbl::TkFromNameLen(_In_reads_(cch) LPCOLESTR prgch, uint32 cch, bool isStrictMode)
432-
{
433-
uint32 luHash = CaseSensitiveComputeHash(prgch, prgch + cch);
434-
435-
// look for a keyword
436-
#include "kwds_sw.h"
437-
438-
#define KEYWORD(tk,f,prec2,nop2,prec1,nop1,name) \
439-
LEqual_##name: \
440-
if (cch == g_ssym_##name.cch && \
441-
0 == memcmp(g_ssym_##name.sz, prgch, cch * sizeof(OLECHAR))) \
442-
{ \
443-
return ((f & fidKwdRsvd) || (isStrictMode && (f & fidKwdFutRsvd))) ? tk : tkID; \
444-
} \
445-
goto LDefault;
446-
#include "keywords.h"
447-
448-
LDefault:
449-
return tkID;
450-
}
451-
452-
#pragma warning(pop)
453449

454450
__declspec(noreturn) void HashTbl::OutOfMemory()
455451
{

lib/Parser/Hash.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,12 @@ struct Ident
322322

323323
void SetIsModuleExport() { m_grfid |= fidModuleExport; }
324324
BOOL GetIsModuleExport() const { return m_grfid & fidModuleExport; }
325+
326+
static tokens TkFromNameLen(uint32 luHash, _In_reads_(cch) LPCOLESTR prgch, uint32 cch, bool isStrictMode, ushort * pgrfid, ushort * ptk);
327+
328+
#if DBG
329+
static tokens TkFromNameLen(_In_reads_(cch) LPCOLESTR prgch, uint32 cch, bool isStrictMode);
330+
#endif
325331
};
326332

327333

@@ -389,7 +395,6 @@ class HashTbl
389395
#endif
390396
);
391397

392-
tokens TkFromNameLen(_In_reads_(cch) LPCOLESTR prgch, uint32 cch, bool isStrictMode);
393398
NoReleaseAllocator* GetAllocator() {return &m_noReleaseAllocator;}
394399

395400
bool Contains(_In_reads_(cch) LPCOLESTR prgch, int32 cch);

lib/Parser/Scan.cpp

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -465,26 +465,6 @@ tokens Scanner<EncodingPolicy>::ScanIdentifierContinue(bool identifyKwds, bool f
465465
return tkID;
466466
}
467467

468-
// During syntax coloring, scanner doesn't need to convert the escape sequence to get actual characters, it just needs the classification information
469-
// So call up hashtables custom method to check if the string scanned is identifier or keyword.
470-
// Do the same for deferred parsing, but use a custom method that only tokenizes JS keywords.
471-
if ((m_DeferredParseFlags & ScanFlagSuppressIdPid) != 0)
472-
{
473-
m_ptoken->SetIdentifier(NULL);
474-
if (!fHasEscape)
475-
{
476-
// If there are no escape, that the main scan loop would have found the keyword already
477-
// So we can just assume it is an ID
478-
DebugOnly(int32 cch = UnescapeToTempBuf(pchMin, p));
479-
DebugOnly(tokens tk = m_phtbl->TkFromNameLen(m_tempChBuf.m_prgch, cch, IsStrictMode()));
480-
Assert(tk == tkID || (tk == tkYIELD && !this->YieldIsKeyword()) || (tk == tkAWAIT && !this->AwaitIsKeyword()));
481-
return tkID;
482-
}
483-
int32 cch = UnescapeToTempBuf(pchMin, p);
484-
tokens tk = m_phtbl->TkFromNameLen(m_tempChBuf.m_prgch, cch, IsStrictMode());
485-
return (!this->YieldIsKeyword() && tk == tkYIELD) || (!this->AwaitIsKeyword() && tk == tkAWAIT) ? tkID : tk;
486-
}
487-
488468
// UTF16 Scanner are only for syntax coloring, so it shouldn't come here.
489469
if (EncodingPolicy::MultiUnitEncoding && !fHasMultiChar && !fHasEscape)
490470
{
@@ -493,7 +473,7 @@ tokens Scanner<EncodingPolicy>::ScanIdentifierContinue(bool identifyKwds, bool f
493473
// If there are no escape, that the main scan loop would have found the keyword already
494474
// So we can just assume it is an ID
495475
DebugOnly(int32 cch = UnescapeToTempBuf(pchMin, p));
496-
DebugOnly(tokens tk = m_phtbl->TkFromNameLen(m_tempChBuf.m_prgch, cch, IsStrictMode()));
476+
DebugOnly(tokens tk = Ident::TkFromNameLen(m_tempChBuf.m_prgch, cch, IsStrictMode()));
497477
Assert(tk == tkID || (tk == tkYIELD && !this->YieldIsKeyword()) || (tk == tkAWAIT && !this->AwaitIsKeyword()));
498478

499479
m_ptoken->SetIdentifier(reinterpret_cast<const char *>(pchMin), (int32)(p - pchMin));
@@ -506,8 +486,8 @@ tokens Scanner<EncodingPolicy>::ScanIdentifierContinue(bool identifyKwds, bool f
506486
if (!fHasEscape)
507487
{
508488
// If it doesn't have escape, then Scan() should have taken care of keywords (except
509-
// yield if this->YieldIsKeyword() is false, in which case yield is treated as an identifier, and except
510-
// await if this->AwaitIsKeyword() is false, in which case await is treated as an identifier).
489+
// yield if m_fYieldIsKeyword is false, in which case yield is treated as an identifier, and except
490+
// await if m_fAwaitIsKeyword is false, in which case await is treated as an identifier).
511491
// We don't have to check if the name is reserved word and return it as an Identifier
512492
Assert(pid->Tk(IsStrictMode()) == tkID
513493
|| (pid->Tk(IsStrictMode()) == tkYIELD && !this->YieldIsKeyword())

lib/Parser/Scan.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,6 @@ enum ScanFlag
318318
{
319319
ScanFlagNone = 0,
320320
ScanFlagSuppressStrPid = 1, // Force strings to always have pid
321-
ScanFlagSuppressIdPid = 2 // Force identifiers to always have pid (currently unused)
322321
};
323322

324323
typedef HRESULT (*CommentCallback)(void *data, OLECHAR firstChar, OLECHAR secondChar, bool containTypeDef, charcount_t min, charcount_t lim, bool adjacent, bool multiline, charcount_t startLine, charcount_t endLine);

0 commit comments

Comments
 (0)