Skip to content

Commit ff9b959

Browse files
committed
Remove unused and probably broken syntax coloring support in scanner
Also remove instantiation of the Scanner<NullTerminatedUtf8EncodingPolicy>
1 parent af4ac8e commit ff9b959

File tree

8 files changed

+8
-199
lines changed

8 files changed

+8
-199
lines changed

lib/Common/CommonDefines.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,8 @@
210210
#endif
211211
#endif
212212

213-
// Don't enable background parser in release build.
214-
#if ENABLE_DEBUG_CONFIG_OPTIONS
213+
// Only enable background parser in debug build.
214+
#ifdef DBG
215215
#define ENABLE_BACKGROUND_PARSING 1
216216
#endif
217217

lib/Parser/Hash.cpp

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -410,35 +410,6 @@ bool HashTbl::Contains(_In_reads_(cch) LPCOLESTR prgch, int32 cch)
410410

411411
#include "HashFunc.cpp"
412412

413-
414-
415-
416-
#pragma warning(push)
417-
#pragma warning(disable:4740) // flow in or out of inline asm code suppresses global optimization
418-
// Decide if token is keyword by string matching -
419-
// 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
420-
tokens HashTbl::TkFromNameLenColor(_In_reads_(cch) LPCOLESTR prgch, uint32 cch)
421-
{
422-
uint32 luHash = CaseSensitiveComputeHash(prgch, prgch + cch);
423-
424-
// look for a keyword
425-
#include "kwds_sw.h"
426-
427-
#define KEYWORD(tk,f,prec2,nop2,prec1,nop1,name) \
428-
LEqual_##name: \
429-
if (cch == g_ssym_##name.cch && \
430-
0 == memcmp(g_ssym_##name.sz, prgch, cch * sizeof(OLECHAR))) \
431-
{ \
432-
return tk; \
433-
} \
434-
goto LDefault;
435-
#include "keywords.h"
436-
437-
LDefault:
438-
return tkID;
439-
}
440-
#pragma warning(pop)
441-
442413
#pragma warning(push)
443414
#pragma warning(disable:4740) // flow in or out of inline asm code suppresses global optimization
444415

lib/Parser/Hash.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,6 @@ class HashTbl
384384
);
385385

386386
tokens TkFromNameLen(_In_reads_(cch) LPCOLESTR prgch, uint32 cch, bool isStrictMode);
387-
tokens TkFromNameLenColor(_In_reads_(cch) LPCOLESTR prgch, uint32 cch);
388387
NoReleaseAllocator* GetAllocator() {return &m_noReleaseAllocator;}
389388

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

lib/Parser/Parse.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10884,9 +10884,6 @@ ParseNodePtr Parser::Parse(LPCUTF8 pszSrc, size_t offset, size_t length, charcou
1088410884

1088510885
m_nextBlockId = 0;
1088610886

10887-
// Scanner should run in Running mode and not syntax coloring mode
10888-
grfscr &= ~fscrSyntaxColor;
10889-
1089010887
if (this->m_scriptContext->IsScriptContextInDebugMode()
1089110888
#ifdef ENABLE_PREJIT
1089210889
|| Js::Configuration::Global.flags.Prejit

lib/Parser/ParseFlags.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ enum
1515
fscrImplicitParents = 1 << 3, // the parents of 'this' are implicit
1616
fscrMapQuote = 1 << 4, // map single quote to double quote
1717
fscrDynamicCode = 1 << 5, // The code is being generated dynamically (eval, new Function, etc.)
18-
fscrSyntaxColor = 1 << 6, // used by the scanner for syntax coloring
18+
// Unused = 1 << 6,
1919
fscrNoImplicitHandlers = 1 << 7, // same as Opt NoConnect at start of block
2020

2121
// prevents the need to make a copy to strip off trailing html comments

lib/Parser/RegexParser.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3088,6 +3088,5 @@ namespace UnifiedRegex
30883088

30893089
// Instantiate the Parser
30903090
INSTANTIATE_REGEX_PARSER(NullTerminatedUnicodeEncodingPolicy);
3091-
INSTANTIATE_REGEX_PARSER(NullTerminatedUTF8EncodingPolicy);
30923091
INSTANTIATE_REGEX_PARSER(NotNullTerminatedUTF8EncodingPolicy);
30933092
}

lib/Parser/Scan.cpp

Lines changed: 3 additions & 153 deletions
Original file line numberDiff line numberDiff line change
@@ -35,60 +35,6 @@ int CountNewlines(LPCOLESTR psz, int cch)
3535
return cln;
3636
}
3737

38-
template< typename CharT >
39-
struct AorW
40-
{
41-
};
42-
43-
// Specialization for UTF8Char
44-
template<>
45-
struct AorW< UTF8Char >
46-
{
47-
// Expressing the args as "arrays of size N" ensures that the both args
48-
// are the same length. If not, we get a compile time error.
49-
template< size_t N >
50-
static const UTF8Char* Choose( const char (&a)[N], const char16 (&w)[N] )
51-
{
52-
// The reinterpret_cast is necessary to go from signed to unsigned char
53-
return reinterpret_cast< const UTF8Char* >(a);
54-
}
55-
56-
template< size_t N >
57-
static const bool Test(const char (&a)[N], const char16 (&w)[N], LPCUTF8 value)
58-
{
59-
return 0 == memcmp(a, value, (N - 1) * sizeof(utf8char_t));
60-
}
61-
62-
template< size_t N >
63-
static const bool Test(const char (&a)[N], const char16 (&w)[N], LPCUTF8 start, LPCUTF8 end)
64-
{
65-
return (end - start == N - 1) && (0 == memcmp(a, start, (N - 1) * sizeof(utf8char_t)));
66-
}
67-
};
68-
69-
// Specialization for OLECHAR
70-
template<>
71-
struct AorW< OLECHAR >
72-
{
73-
template< size_t N >
74-
static const char16* Choose( const char (&a)[N], const char16 (&w)[N] )
75-
{
76-
return w;
77-
}
78-
79-
template < size_t N >
80-
static bool Test(const char (&a)[N], const char16 (&w)[N], const char16 *value)
81-
{
82-
return 0 == memcmp(w, value, (N - 1) * sizeof(char16));
83-
}
84-
85-
template < size_t N >
86-
static bool Test(const char (&a)[N], const char16 (&w)[N], const char16 *start, const char16 *end)
87-
{
88-
return (end - start == N - 1) && (0 == memcmp(w, start, (N - 1) * sizeof(char16)));
89-
}
90-
};
91-
9238
BOOL Token::IsKeyword() const
9339
{
9440
// keywords (but not future reserved words)
@@ -202,7 +148,6 @@ void Scanner<EncodingPolicy>::SetText(EncodedCharPtr pszSrc, size_t offset, size
202148
m_ptoken->tk = tkNone;
203149
m_fIsModuleCode = (grfscr & fscrIsModuleCode) != 0;
204150
m_fHadEol = FALSE;
205-
m_fSyntaxColor = (grfscr & fscrSyntaxColor) != 0;
206151
m_DeferredParseFlags = ScanFlagNone;
207152
}
208153

@@ -537,15 +482,6 @@ tokens Scanner<EncodingPolicy>::ScanIdentifierContinue(bool identifyKwds, bool f
537482
tokens tk = m_phtbl->TkFromNameLen(m_tempChBuf.m_prgch, cch, IsStrictMode());
538483
return (!m_fYieldIsKeyword && tk == tkYIELD) || (!m_fAwaitIsKeyword && tk == tkAWAIT) ? tkID : tk;
539484
}
540-
else if (m_fSyntaxColor)
541-
{
542-
m_ptoken->SetIdentifier(NULL);
543-
// We always need to check TkFromNameLenColor because
544-
// the main Scan switch doesn't detect all non-keyword that needs coloring
545-
// (e.g. int)
546-
int32 cch = UnescapeToTempBuf(pchMin, p);
547-
return m_phtbl->TkFromNameLenColor(m_tempChBuf.m_prgch, cch);
548-
}
549485

550486
// UTF16 Scanner are only for syntax coloring, so it shouldn't come here.
551487
if (EncodingPolicy::MultiUnitEncoding && !fHasMultiChar && !fHasEscape)
@@ -995,9 +931,6 @@ tokens Scanner<EncodingPolicy>::ScanRegExpConstant(ArenaAllocator* alloc)
995931
#ifdef PROFILE_EXEC
996932
m_scriptContext->ProfileEnd(Js::RegexCompilePhase);
997933
#endif
998-
if (m_fSyntaxColor)
999-
return ScanError(m_currentCharacter + e.encodedPos, tkRegExp);
1000-
1001934
m_currentCharacter += e.encodedPos;
1002935
Error(e.error);
1003936
}
@@ -1030,7 +963,7 @@ tokens Scanner<EncodingPolicy>::ScanRegExpConstantNoAST(ArenaAllocator* alloc)
1030963
PROBE_STACK(m_scriptContext, Js::Constants::MinStackRegex);
1031964
}
1032965

1033-
ThreadContext *threadContext = m_fSyntaxColor ? ThreadContext::GetContextForCurrentThread() : m_scriptContext->GetThreadContext();
966+
ThreadContext *threadContext = m_scriptContext->GetThreadContext();
1034967
UnifiedRegex::StandardChars<EncodedChar>* standardEncodedChars = threadContext->GetStandardChars((EncodedChar*)0);
1035968
UnifiedRegex::StandardChars<char16>* standardChars = threadContext->GetStandardChars((char16*)0);
1036969
charcount_t totalLen = 0, bodyChars = 0, totalChars = 0, bodyLen = 0;
@@ -1050,9 +983,6 @@ tokens Scanner<EncodingPolicy>::ScanRegExpConstantNoAST(ArenaAllocator* alloc)
1050983
}
1051984
catch (UnifiedRegex::ParseError e)
1052985
{
1053-
if (m_fSyntaxColor)
1054-
return ScanError(m_currentCharacter + e.encodedPos, tkRegExp);
1055-
1056986
m_currentCharacter += e.encodedPos;
1057987
Error(e.error);
1058988
// never reached
@@ -1197,11 +1127,6 @@ tokens Scanner<EncodingPolicy>::ScanStringConstant(OLECHAR delim, EncodedCharPtr
11971127
}
11981128

11991129
m_currentCharacter = p - 1;
1200-
if (m_fSyntaxColor)
1201-
{
1202-
*pp = p - 1;
1203-
return ScanError(p - 1, tkStrCon);
1204-
}
12051130
Error(ERRnoStrEnd);
12061131

12071132
case '"':
@@ -1239,11 +1164,6 @@ tokens Scanner<EncodingPolicy>::ScanStringConstant(OLECHAR delim, EncodedCharPtr
12391164
if (p >= last)
12401165
{
12411166
m_currentCharacter = p - 1;
1242-
if (m_fSyntaxColor)
1243-
{
1244-
*pp = p - 1;
1245-
return ScanError(p - 1, tkStrCon);
1246-
}
12471167
Error(ERRnoStrEnd);
12481168
}
12491169
break;
@@ -1499,13 +1419,6 @@ tokens Scanner<EncodingPolicy>::ScanStringConstant(OLECHAR delim, EncodedCharPtr
14991419
m_currentCharacter = p;
15001420
ScanNewLine(ch);
15011421
p = m_currentCharacter;
1502-
if (m_fSyntaxColor && *p == 0)
1503-
{
1504-
// Special case for multi-line strings during colorization.
1505-
m_scanState = delim == '"' ? ScanStateMultiLineDoubleQuoteString : ScanStateMultiLineSingleQuoteString;
1506-
*pp = p;
1507-
return tkStrCon;
1508-
}
15091422
continue;
15101423

15111424
case 0:
@@ -1515,11 +1428,6 @@ tokens Scanner<EncodingPolicy>::ScanStringConstant(OLECHAR delim, EncodedCharPtr
15151428

15161429
ReturnScanError:
15171430
m_currentCharacter = p - 1;
1518-
if (m_fSyntaxColor)
1519-
{
1520-
*pp = p - 1;
1521-
return ScanError(p - 1, tkStrCon);
1522-
}
15231431
Error(errorType);
15241432
}
15251433
else if (stringTemplateMode)
@@ -1552,7 +1460,7 @@ tokens Scanner<EncodingPolicy>::ScanStringConstant(OLECHAR delim, EncodedCharPtr
15521460
LBreak:
15531461
bool createPid = true;
15541462

1555-
if (m_fSyntaxColor || (m_DeferredParseFlags & ScanFlagSuppressStrPid) != 0)
1463+
if ((m_DeferredParseFlags & ScanFlagSuppressStrPid) != 0)
15561464
{
15571465
createPid = false;
15581466

@@ -1605,11 +1513,6 @@ tokens Scanner<EncodingPolicy>::SkipComment(EncodedCharPtr *pp, /* out */ bool*
16051513
if (*p == '/')
16061514
{
16071515
*pp = p + 1;
1608-
if (m_fSyntaxColor)
1609-
{
1610-
m_scanState = ScanStateNormal;
1611-
return tkComment;
1612-
}
16131516
return tkNone;
16141517
}
16151518
break;
@@ -1634,11 +1537,6 @@ tokens Scanner<EncodingPolicy>::SkipComment(EncodedCharPtr *pp, /* out */ bool*
16341537
{
16351538
m_currentCharacter = p - 1;
16361539
*pp = p - 1;
1637-
if (m_fSyntaxColor)
1638-
{
1639-
m_scanState = ScanStateMultiLineComment;
1640-
return tkComment;
1641-
}
16421540
Error(ERRnoCmtEnd);
16431541
}
16441542
break;
@@ -1764,26 +1662,6 @@ tokens Scanner<EncodingPolicy>::ScanCore(bool identifyKwds)
17641662

17651663
if (m_scanState && *p != 0)
17661664
{
1767-
if (m_fSyntaxColor)
1768-
{
1769-
firstChar = 0;
1770-
secondChar = 0;
1771-
m_pchMinTok = p;
1772-
m_cMinTokMultiUnits = this->m_cMultiUnits;
1773-
switch (m_scanState)
1774-
{
1775-
case ScanStateMultiLineComment:
1776-
goto LMultiLineComment;
1777-
case ScanStateMultiLineSingleQuoteString:
1778-
ch = '\'';
1779-
m_scanState = ScanStateNormal;
1780-
goto LScanStringConstant;
1781-
case ScanStateMultiLineDoubleQuoteString:
1782-
ch = '"';
1783-
m_scanState = ScanStateNormal;
1784-
goto LScanStringConstant;
1785-
}
1786-
}
17871665
if (m_scanState == ScanStateStringTemplateMiddleOrEnd)
17881666
{
17891667
AssertMsg(m_fStringTemplateDepth > 0,
@@ -1852,11 +1730,6 @@ tokens Scanner<EncodingPolicy>::ScanCore(bool identifyKwds)
18521730
// All other types (except errors) are handled by the outer switch.
18531731
}
18541732
Assert(chType == _C_LET || chType == _C_ERR || chType == _C_UNK || chType == _C_BKQ || chType == _C_SHP || chType == _C_AT || chType == _C_DIG);
1855-
if (m_fSyntaxColor)
1856-
{
1857-
// No need to decrement the current position pointer as scanner will continue with scan next character onwards
1858-
return ScanError(p, tkID);
1859-
}
18601733
m_currentCharacter = p - 1;
18611734
Error(ERRillegalChar);
18621735
continue;
@@ -1869,11 +1742,6 @@ tokens Scanner<EncodingPolicy>::ScanCore(bool identifyKwds)
18691742

18701743
if (p + 1 < last)
18711744
{
1872-
if (m_fSyntaxColor)
1873-
{
1874-
return ScanError(p + 1, tkID);
1875-
}
1876-
18771745
// A \0 prior to the end of the text is an invalid character.
18781746
Error(ERRillegalChar);
18791747
}
@@ -1916,11 +1784,6 @@ tokens Scanner<EncodingPolicy>::ScanCore(bool identifyKwds)
19161784
if (p == pchT)
19171785
{
19181786
Assert(this->PeekFirst(p, last) != '.');
1919-
if (m_fSyntaxColor)
1920-
{
1921-
return ScanError(m_currentCharacter + 1, tkFltCon);
1922-
}
1923-
19241787
Error(ERRbadNumber);
19251788
}
19261789
Assert(!Js::NumberUtilities::IsNan(dbl));
@@ -2029,9 +1892,6 @@ tokens Scanner<EncodingPolicy>::ScanCore(bool identifyKwds)
20291892
if (tkScanError == token)
20301893
{
20311894
m_currentCharacter = p;
2032-
if (m_fSyntaxColor)
2033-
return ScanError(p, tkID);
2034-
20351895
Error(ERRillegalChar);
20361896
}
20371897
p = pchT;
@@ -2178,11 +2038,6 @@ tokens Scanner<EncodingPolicy>::ScanCore(bool identifyKwds)
21782038
case kchRET:
21792039
p--;
21802040
LCommentLineBreak:
2181-
if (m_fSyntaxColor)
2182-
{
2183-
token = tkComment;
2184-
goto LDone;
2185-
}
21862041
// Subtract the comment length from the total char count for the purpose
21872042
// of deciding whether to defer AST and byte code generation.
21882043
m_parser->ReduceDeferredScriptLength((ULONG)(p - m_pchMinTok));
@@ -2227,8 +2082,6 @@ tokens Scanner<EncodingPolicy>::ScanCore(bool identifyKwds)
22272082
secondChar = '\0';
22282083
}
22292084

2230-
2231-
LMultiLineComment:
22322085
pchT = p;
22332086
commentStartLine = m_line;
22342087
bool containTypeDef;
@@ -2364,7 +2217,6 @@ tokens Scanner<EncodingPolicy>::ScanCore(bool identifyKwds)
23642217
case '\'':
23652218
case '"':
23662219
Assert(chType == _C_QUO || chType == _C_APO);
2367-
LScanStringConstant:
23682220
pchT = p;
23692221
token = this->ScanStringConstant((OLECHAR)ch, &pchT);
23702222
p = pchT;
@@ -2384,7 +2236,7 @@ IdentPtr Scanner<EncodingPolicy>::GetSecondaryBufferAsPid()
23842236
{
23852237
bool createPid = true;
23862238

2387-
if (m_fSyntaxColor || (m_DeferredParseFlags & ScanFlagSuppressStrPid) != 0)
2239+
if ((m_DeferredParseFlags & ScanFlagSuppressStrPid) != 0)
23882240
{
23892241
createPid = false;
23902242
}
@@ -2531,6 +2383,4 @@ HRESULT Scanner<EncodingPolicy>::SysAllocErrorLine(int32 ichMinLine, __out BSTR*
25312383
return S_OK;
25322384
}
25332385

2534-
template class Scanner<NullTerminatedUnicodeEncodingPolicy>;
2535-
template class Scanner<NullTerminatedUTF8EncodingPolicy>;
25362386
template class Scanner<NotNullTerminatedUTF8EncodingPolicy>;

0 commit comments

Comments
 (0)