diff options
author | Ryan Harrison <rharrison@chromium.org> | 2017-07-25 11:10:15 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-07-25 15:26:28 +0000 |
commit | 952477dbee761a6e38ce675f2095bbfc9cfd7450 (patch) | |
tree | c248f649135de60d81d87d9b0afebc153a589d69 /xfa/fxfa/fm2js | |
parent | 364d18b13575a2b569e9fc175cb0dd60106fa954 (diff) | |
download | pdfium-952477dbee761a6e38ce675f2095bbfc9cfd7450.tar.xz |
Clean up data passing in FormCalc Lexerchromium/3167
This CL removes the pattern used in the lexer of passing the lexing
member variables around as args to methods. Instead it uses the fact
that they are member variables in the methods.
This CL also includes renaming of variable and function names to
remove unneeded details or make them more precise.
BUG=pdfium:814
Change-Id: Id4c592338db9ff462835314252d39ab3b4b2b2ab
Reviewed-on: https://pdfium-review.googlesource.com/8850
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'xfa/fxfa/fm2js')
-rw-r--r-- | xfa/fxfa/fm2js/cxfa_fmlexer.cpp | 382 | ||||
-rw-r--r-- | xfa/fxfa/fm2js/cxfa_fmlexer.h | 36 | ||||
-rw-r--r-- | xfa/fxfa/fm2js/cxfa_fmlexer_unittest.cpp | 40 | ||||
-rw-r--r-- | xfa/fxfa/fm2js/cxfa_fmparse.cpp | 80 |
4 files changed, 268 insertions, 270 deletions
diff --git a/xfa/fxfa/fm2js/cxfa_fmlexer.cpp b/xfa/fxfa/fm2js/cxfa_fmlexer.cpp index 04db1dbe1c..c8a064fad0 100644 --- a/xfa/fxfa/fm2js/cxfa_fmlexer.cpp +++ b/xfa/fxfa/fm2js/cxfa_fmlexer.cpp @@ -14,17 +14,17 @@ namespace { -bool IsValidFormCalcCharacter(wchar_t c) { +bool IsFormCalcCharacter(wchar_t c) { return c == 0 || (c >= 0x09 && c <= 0x0D) || (c >= 0x20 && c <= 0xd7FF) || (c >= 0xE000 && c <= 0xFFFD); } -bool IsValidIdentifierCharacter(wchar_t c) { +bool IsIdentifierCharacter(wchar_t c) { return u_isalnum(c) || c == 0x005F || // '_' c == 0x0024; // '$' } -bool IsValidInitialIdentifierCharacter(wchar_t c) { +bool IsInitialIdentifierCharacter(wchar_t c) { return u_isalpha(c) || c == 0x005F || // '_' c == 0x0024 || // '$' c == 0x0021; // '!' @@ -101,9 +101,9 @@ XFA_FM_TOKEN TokenizeIdentifier(const CFX_WideStringC& str) { const XFA_FMKeyword* result = std::lower_bound(std::begin(keyWords) + KEYWORD_START, std::end(keyWords), key, [](const XFA_FMKeyword& iter, const uint32_t& val) { - return iter.m_uHash < val; + return iter.m_hash < val; }); - if (result != std::end(keyWords) && result->m_uHash == key) { + if (result != std::end(keyWords) && result->m_hash == key) { return result->m_type; } return TOKidentifier; @@ -117,46 +117,46 @@ const wchar_t* XFA_FM_KeywordToString(XFA_FM_TOKEN op) { return keyWords[op].m_keyword; } -CXFA_FMToken::CXFA_FMToken() : m_type(TOKreserver), m_uLinenum(1) {} +CXFA_FMToken::CXFA_FMToken() : m_type(TOKreserver), m_line_num(1) {} -CXFA_FMToken::CXFA_FMToken(uint32_t uLineNum) - : m_type(TOKreserver), m_uLinenum(uLineNum) {} +CXFA_FMToken::CXFA_FMToken(uint32_t line_num) + : m_type(TOKreserver), m_line_num(line_num) {} CXFA_FMToken::~CXFA_FMToken() {} CXFA_FMLexer::CXFA_FMLexer(const CFX_WideStringC& wsFormCalc) - : m_ptr(wsFormCalc.unterminated_c_str()), - m_end(m_ptr + wsFormCalc.GetLength() - 1), - m_uCurrentLine(1), - m_LexerError(false) {} + : m_cursor(wsFormCalc.unterminated_c_str()), + m_end(m_cursor + wsFormCalc.GetLength() - 1), + m_current_line(1), + m_lexer_error(false) {} CXFA_FMLexer::~CXFA_FMLexer() {} CXFA_FMToken* CXFA_FMLexer::NextToken() { - m_pToken = pdfium::MakeUnique<CXFA_FMToken>(m_uCurrentLine); - while (m_ptr <= m_end && *m_ptr) { - if (!IsValidFormCalcCharacter(*m_ptr)) { - m_LexerError = true; - return m_pToken.get(); + m_token = pdfium::MakeUnique<CXFA_FMToken>(m_current_line); + while (m_cursor <= m_end && *m_cursor) { + if (!IsFormCalcCharacter(*m_cursor)) { + m_lexer_error = true; + return m_token.get(); } - switch (*m_ptr) { + switch (*m_cursor) { case 0x0A: - ++m_uCurrentLine; - m_pToken->m_uLinenum = m_uCurrentLine; - ++m_ptr; + ++m_current_line; + m_token->m_line_num = m_current_line; + ++m_cursor; break; case 0x0D: - ++m_ptr; + ++m_cursor; break; case ';': { - m_ptr = AdvanceForComment(m_ptr); + AdvanceForComment(); break; } case '"': { - m_pToken->m_type = TOKstring; - m_ptr = AdvanceForString(m_pToken.get(), m_ptr); - return m_pToken.get(); + m_token->m_type = TOKstring; + AdvanceForString(); + return m_token.get(); } case '0': case '1': @@ -168,257 +168,255 @@ CXFA_FMToken* CXFA_FMLexer::NextToken() { case '7': case '8': case '9': { - m_pToken->m_type = TOKnumber; - m_ptr = AdvanceForNumber(m_pToken.get(), m_ptr); - return m_pToken.get(); + m_token->m_type = TOKnumber; + AdvanceForNumber(); + return m_token.get(); } case '=': - ++m_ptr; - if (m_ptr > m_end) { - m_pToken->m_type = TOKassign; - return m_pToken.get(); + ++m_cursor; + if (m_cursor > m_end) { + m_token->m_type = TOKassign; + return m_token.get(); } - if (IsValidFormCalcCharacter(*m_ptr)) { - if (*m_ptr == '=') { - m_pToken->m_type = TOKeq; - ++m_ptr; + if (IsFormCalcCharacter(*m_cursor)) { + if (*m_cursor == '=') { + m_token->m_type = TOKeq; + ++m_cursor; } else { - m_pToken->m_type = TOKassign; + m_token->m_type = TOKassign; } } else { - m_LexerError = true; + m_lexer_error = true; } - return m_pToken.get(); + return m_token.get(); case '<': - ++m_ptr; - if (m_ptr > m_end) { - m_pToken->m_type = TOKlt; - return m_pToken.get(); + ++m_cursor; + if (m_cursor > m_end) { + m_token->m_type = TOKlt; + return m_token.get(); } - if (IsValidFormCalcCharacter(*m_ptr)) { - if (*m_ptr == '=') { - m_pToken->m_type = TOKle; - ++m_ptr; - } else if (*m_ptr == '>') { - m_pToken->m_type = TOKne; - ++m_ptr; + if (IsFormCalcCharacter(*m_cursor)) { + if (*m_cursor == '=') { + m_token->m_type = TOKle; + ++m_cursor; + } else if (*m_cursor == '>') { + m_token->m_type = TOKne; + ++m_cursor; } else { - m_pToken->m_type = TOKlt; + m_token->m_type = TOKlt; } } else { - m_LexerError = true; + m_lexer_error = true; } - return m_pToken.get(); + return m_token.get(); case '>': - ++m_ptr; - if (m_ptr > m_end) { - m_pToken->m_type = TOKgt; - return m_pToken.get(); + ++m_cursor; + if (m_cursor > m_end) { + m_token->m_type = TOKgt; + return m_token.get(); } - if (IsValidFormCalcCharacter(*m_ptr)) { - if (*m_ptr == '=') { - m_pToken->m_type = TOKge; - ++m_ptr; + if (IsFormCalcCharacter(*m_cursor)) { + if (*m_cursor == '=') { + m_token->m_type = TOKge; + ++m_cursor; } else { - m_pToken->m_type = TOKgt; + m_token->m_type = TOKgt; } } else { - m_LexerError = true; + m_lexer_error = true; } - return m_pToken.get(); + return m_token.get(); case ',': - m_pToken->m_type = TOKcomma; - ++m_ptr; - return m_pToken.get(); + m_token->m_type = TOKcomma; + ++m_cursor; + return m_token.get(); case '(': - m_pToken->m_type = TOKlparen; - ++m_ptr; - return m_pToken.get(); + m_token->m_type = TOKlparen; + ++m_cursor; + return m_token.get(); case ')': - m_pToken->m_type = TOKrparen; - ++m_ptr; - return m_pToken.get(); + m_token->m_type = TOKrparen; + ++m_cursor; + return m_token.get(); case '[': - m_pToken->m_type = TOKlbracket; - ++m_ptr; - return m_pToken.get(); + m_token->m_type = TOKlbracket; + ++m_cursor; + return m_token.get(); case ']': - m_pToken->m_type = TOKrbracket; - ++m_ptr; - return m_pToken.get(); + m_token->m_type = TOKrbracket; + ++m_cursor; + return m_token.get(); case '&': - ++m_ptr; - m_pToken->m_type = TOKand; - return m_pToken.get(); + ++m_cursor; + m_token->m_type = TOKand; + return m_token.get(); case '|': - ++m_ptr; - m_pToken->m_type = TOKor; - return m_pToken.get(); + ++m_cursor; + m_token->m_type = TOKor; + return m_token.get(); case '+': - ++m_ptr; - m_pToken->m_type = TOKplus; - return m_pToken.get(); + ++m_cursor; + m_token->m_type = TOKplus; + return m_token.get(); case '-': - ++m_ptr; - m_pToken->m_type = TOKminus; - return m_pToken.get(); + ++m_cursor; + m_token->m_type = TOKminus; + return m_token.get(); case '*': - ++m_ptr; - m_pToken->m_type = TOKmul; - return m_pToken.get(); + ++m_cursor; + m_token->m_type = TOKmul; + return m_token.get(); case '/': { - ++m_ptr; - if (m_ptr > m_end) { - m_pToken->m_type = TOKdiv; - return m_pToken.get(); + ++m_cursor; + if (m_cursor > m_end) { + m_token->m_type = TOKdiv; + return m_token.get(); } - if (!IsValidFormCalcCharacter(*m_ptr)) { - m_LexerError = true; - return m_pToken.get(); + if (!IsFormCalcCharacter(*m_cursor)) { + m_lexer_error = true; + return m_token.get(); } - if (*m_ptr != '/') { - m_pToken->m_type = TOKdiv; - return m_pToken.get(); + if (*m_cursor != '/') { + m_token->m_type = TOKdiv; + return m_token.get(); } - m_ptr = AdvanceForComment(m_ptr); + AdvanceForComment(); break; } case '.': - ++m_ptr; - if (m_ptr > m_end) { - m_pToken->m_type = TOKdot; - return m_pToken.get(); + ++m_cursor; + if (m_cursor > m_end) { + m_token->m_type = TOKdot; + return m_token.get(); } - if (IsValidFormCalcCharacter(*m_ptr)) { - if (*m_ptr == '.') { - m_pToken->m_type = TOKdotdot; - ++m_ptr; - } else if (*m_ptr == '*') { - m_pToken->m_type = TOKdotstar; - ++m_ptr; - } else if (*m_ptr == '#') { - m_pToken->m_type = TOKdotscream; - ++m_ptr; - } else if (*m_ptr <= '9' && *m_ptr >= '0') { - m_pToken->m_type = TOKnumber; - --m_ptr; - m_ptr = AdvanceForNumber(m_pToken.get(), m_ptr); - } else { - m_pToken->m_type = TOKdot; - } + if (!IsFormCalcCharacter(*m_cursor)) { + m_lexer_error = true; + return m_token.get(); + } + + if (*m_cursor == '.') { + m_token->m_type = TOKdotdot; + ++m_cursor; + } else if (*m_cursor == '*') { + m_token->m_type = TOKdotstar; + ++m_cursor; + } else if (*m_cursor == '#') { + m_token->m_type = TOKdotscream; + ++m_cursor; + } else if (*m_cursor <= '9' && *m_cursor >= '0') { + m_token->m_type = TOKnumber; + --m_cursor; + AdvanceForNumber(); } else { - m_LexerError = true; + m_token->m_type = TOKdot; } - return m_pToken.get(); + return m_token.get(); case 0x09: case 0x0B: case 0x0C: case 0x20: - ++m_ptr; + ++m_cursor; break; default: { - if (!IsValidInitialIdentifierCharacter(*m_ptr)) { - m_LexerError = true; - return m_pToken.get(); + if (!IsInitialIdentifierCharacter(*m_cursor)) { + m_lexer_error = true; + return m_token.get(); } - m_ptr = AdvanceForIdentifier(m_pToken.get(), m_ptr); - return m_pToken.get(); + AdvanceForIdentifier(); + return m_token.get(); } } } // If there isn't currently a token type then mark it EOF. - if (m_pToken->m_type == TOKreserver) - m_pToken->m_type = TOKeof; - return m_pToken.get(); + if (m_token->m_type == TOKreserver) + m_token->m_type = TOKeof; + return m_token.get(); } -const wchar_t* CXFA_FMLexer::AdvanceForNumber(CXFA_FMToken* t, - const wchar_t* p) { - // This will set pEnd to the character after the end of the AdvanceForNumber. - wchar_t* pEnd = nullptr; - if (p) - wcstod(const_cast<wchar_t*>(p), &pEnd); - if (pEnd && FXSYS_iswalpha(*pEnd)) { - m_LexerError = true; - return pEnd; +void CXFA_FMLexer::AdvanceForNumber() { + // This will set end to the character after the end of the number. + wchar_t* end = nullptr; + if (m_cursor) + wcstod(const_cast<wchar_t*>(m_cursor), &end); + if (end && FXSYS_iswalpha(*end)) { + m_lexer_error = true; + return; } - t->m_wstring = CFX_WideStringC(p, (pEnd - p)); - return pEnd; + m_token->m_string = CFX_WideStringC(m_cursor, (end - m_cursor)); + m_cursor = end; } -const wchar_t* CXFA_FMLexer::AdvanceForString(CXFA_FMToken* t, - const wchar_t* p) { - const wchar_t* start = p; - ++p; - while (p <= m_end && *p) { - if (!IsValidFormCalcCharacter(*p)) +void CXFA_FMLexer::AdvanceForString() { + const wchar_t* start = m_cursor; + ++m_cursor; + while (m_cursor <= m_end && *m_cursor) { + if (!IsFormCalcCharacter(*m_cursor)) break; - if (*p == '"') { + if (*m_cursor == '"') { // Check for escaped "s, i.e. "". - ++p; + ++m_cursor; // If the end of the input has been reached it was not escaped. - if (p > m_end) { - t->m_wstring = CFX_WideStringC(start, (p - start)); - return p; + if (m_cursor > m_end) { + m_token->m_string = CFX_WideStringC(start, (m_cursor - start)); + return; } // If the next character is not a " then the end of the string has been // found. - if (*p != '"') { - if (!IsValidFormCalcCharacter(*p)) { + if (*m_cursor != '"') { + if (!IsFormCalcCharacter(*m_cursor)) { break; } - t->m_wstring = CFX_WideStringC(start, (p - start)); - return p; + m_token->m_string = CFX_WideStringC(start, (m_cursor - start)); + return; } } - ++p; + ++m_cursor; } // Didn't find the end of the string. - t->m_wstring = CFX_WideStringC(start, (p - start)); - m_LexerError = true; - return p; + m_token->m_string = CFX_WideStringC(start, (m_cursor - start)); + m_lexer_error = true; } -const wchar_t* CXFA_FMLexer::AdvanceForIdentifier(CXFA_FMToken* t, - const wchar_t* p) { - const wchar_t* pStart = p; - ++p; - while (p <= m_end && *p) { - if (!IsValidFormCalcCharacter(*p)) { - t->m_wstring = CFX_WideStringC(pStart, (p - pStart)); - m_LexerError = true; - return p; +void CXFA_FMLexer::AdvanceForIdentifier() { + const wchar_t* start = m_cursor; + ++m_cursor; + while (m_cursor <= m_end && *m_cursor) { + if (!IsFormCalcCharacter(*m_cursor)) { + m_token->m_string = CFX_WideStringC(start, (m_cursor - start)); + m_lexer_error = true; + return; } - if (!IsValidIdentifierCharacter(*p)) { + if (!IsIdentifierCharacter(*m_cursor)) { break; } - ++p; + ++m_cursor; } - t->m_wstring = CFX_WideStringC(pStart, (p - pStart)); - t->m_type = TokenizeIdentifier(t->m_wstring); - return p; + m_token->m_string = CFX_WideStringC(start, (m_cursor - start)); + m_token->m_type = TokenizeIdentifier(m_token->m_string); } -const wchar_t* CXFA_FMLexer::AdvanceForComment(const wchar_t* p) { - p++; - while (p <= m_end && *p) { - if (*p == L'\r') - return ++p; - if (*p == L'\n') { - ++m_uCurrentLine; - return ++p; +void CXFA_FMLexer::AdvanceForComment() { + m_cursor++; + while (m_cursor <= m_end && *m_cursor) { + if (*m_cursor == L'\r') { + ++m_cursor; + return; + } + if (*m_cursor == L'\n') { + ++m_current_line; + ++m_cursor; + return; } - ++p; + ++m_cursor; } - return p; } diff --git a/xfa/fxfa/fm2js/cxfa_fmlexer.h b/xfa/fxfa/fm2js/cxfa_fmlexer.h index b1f0552b40..c944266d37 100644 --- a/xfa/fxfa/fm2js/cxfa_fmlexer.h +++ b/xfa/fxfa/fm2js/cxfa_fmlexer.h @@ -85,7 +85,7 @@ enum XFA_FM_TOKEN { struct XFA_FMKeyword { XFA_FM_TOKEN m_type; - uint32_t m_uHash; + uint32_t m_hash; const wchar_t* m_keyword; }; @@ -94,12 +94,12 @@ const wchar_t* XFA_FM_KeywordToString(XFA_FM_TOKEN op); class CXFA_FMToken { public: CXFA_FMToken(); - explicit CXFA_FMToken(uint32_t uLineNum); + explicit CXFA_FMToken(uint32_t line_num); ~CXFA_FMToken(); - CFX_WideStringC m_wstring; + CFX_WideStringC m_string; XFA_FM_TOKEN m_type; - uint32_t m_uLinenum; + uint32_t m_line_num; }; class CXFA_FMLexer { @@ -108,27 +108,27 @@ class CXFA_FMLexer { ~CXFA_FMLexer(); CXFA_FMToken* NextToken(); - bool HasError() const { return m_LexerError; } + bool HasError() const { return m_lexer_error; } - void SetCurrentLine(uint32_t line) { m_uCurrentLine = line; } - void SetToken(std::unique_ptr<CXFA_FMToken> pToken) { - m_pToken = std::move(pToken); + void SetCurrentLine(uint32_t line) { m_current_line = line; } + void SetToken(std::unique_ptr<CXFA_FMToken> token) { + m_token = std::move(token); } - const wchar_t* GetPos() { return m_ptr; } - void SetPos(const wchar_t* pPos) { m_ptr = pPos; } + const wchar_t* GetPos() { return m_cursor; } + void SetPos(const wchar_t* pos) { m_cursor = pos; } private: - const wchar_t* AdvanceForNumber(CXFA_FMToken* t, const wchar_t* p); - const wchar_t* AdvanceForString(CXFA_FMToken* t, const wchar_t* p); - const wchar_t* AdvanceForIdentifier(CXFA_FMToken* t, const wchar_t* p); - const wchar_t* AdvanceForComment(const wchar_t* p); + void AdvanceForNumber(); + void AdvanceForString(); + void AdvanceForIdentifier(); + void AdvanceForComment(); - const wchar_t* m_ptr; + const wchar_t* m_cursor; const wchar_t* const m_end; - uint32_t m_uCurrentLine; - std::unique_ptr<CXFA_FMToken> m_pToken; - bool m_LexerError; + uint32_t m_current_line; + std::unique_ptr<CXFA_FMToken> m_token; + bool m_lexer_error; }; #endif // XFA_FXFA_FM2JS_CXFA_FMLEXER_H_ diff --git a/xfa/fxfa/fm2js/cxfa_fmlexer_unittest.cpp b/xfa/fxfa/fm2js/cxfa_fmlexer_unittest.cpp index 5a8139d416..92b8fa93b3 100644 --- a/xfa/fxfa/fm2js/cxfa_fmlexer_unittest.cpp +++ b/xfa/fxfa/fm2js/cxfa_fmlexer_unittest.cpp @@ -22,44 +22,44 @@ TEST(CXFA_FMLexerTest, Numbers) { // TODO(dsinclair): Should this return -12 instead of two tokens? EXPECT_EQ(TOKminus, token->m_type); token = lexer->NextToken(); - EXPECT_EQ(L"12", token->m_wstring); + EXPECT_EQ(L"12", token->m_string); token = lexer->NextToken(); EXPECT_EQ(TOKeof, token->m_type); lexer = pdfium::MakeUnique<CXFA_FMLexer>(L"1.5362"); token = lexer->NextToken(); EXPECT_EQ(TOKnumber, token->m_type); - EXPECT_EQ(L"1.5362", token->m_wstring); + EXPECT_EQ(L"1.5362", token->m_string); lexer = pdfium::MakeUnique<CXFA_FMLexer>(L"0.875"); token = lexer->NextToken(); EXPECT_EQ(TOKnumber, token->m_type); - EXPECT_EQ(L"0.875", token->m_wstring); + EXPECT_EQ(L"0.875", token->m_string); lexer = pdfium::MakeUnique<CXFA_FMLexer>(L"5.56e-2"); token = lexer->NextToken(); EXPECT_EQ(TOKnumber, token->m_type); - EXPECT_EQ(L"5.56e-2", token->m_wstring); + EXPECT_EQ(L"5.56e-2", token->m_string); lexer = pdfium::MakeUnique<CXFA_FMLexer>(L"1.234E10"); token = lexer->NextToken(); EXPECT_EQ(TOKnumber, token->m_type); - EXPECT_EQ(L"1.234E10", token->m_wstring); + EXPECT_EQ(L"1.234E10", token->m_string); lexer = pdfium::MakeUnique<CXFA_FMLexer>(L"123456789.012345678"); token = lexer->NextToken(); EXPECT_EQ(TOKnumber, token->m_type); // TODO(dsinclair): This should round as per IEEE 64-bit values. - // EXPECT_EQ(L"123456789.01234567", token->m_wstring); - EXPECT_EQ(L"123456789.012345678", token->m_wstring); + // EXPECT_EQ(L"123456789.01234567", token->m_string); + EXPECT_EQ(L"123456789.012345678", token->m_string); lexer = pdfium::MakeUnique<CXFA_FMLexer>(L"99999999999999999"); token = lexer->NextToken(); EXPECT_EQ(TOKnumber, token->m_type); // TODO(dsinclair): This is spec'd as rounding when > 16 significant digits // prior to the exponent. - // EXPECT_EQ(L"100000000000000000", token->m_wstring); - EXPECT_EQ(L"99999999999999999", token->m_wstring); + // EXPECT_EQ(L"100000000000000000", token->m_string); + EXPECT_EQ(L"99999999999999999", token->m_string); } // The quotes are stripped in CXFA_FMStringExpression::ToJavaScript. @@ -68,7 +68,7 @@ TEST(CXFA_FMLexerTest, Strings) { pdfium::MakeUnique<CXFA_FMLexer>(L"\"The cat jumped over the fence.\""); CXFA_FMToken* token = lexer->NextToken(); EXPECT_EQ(TOKstring, token->m_type); - EXPECT_EQ(L"\"The cat jumped over the fence.\"", token->m_wstring); + EXPECT_EQ(L"\"The cat jumped over the fence.\"", token->m_string); token = lexer->NextToken(); EXPECT_EQ(TOKeof, token->m_type); @@ -76,14 +76,14 @@ TEST(CXFA_FMLexerTest, Strings) { lexer = pdfium::MakeUnique<CXFA_FMLexer>(L"\"\""); token = lexer->NextToken(); EXPECT_EQ(TOKstring, token->m_type); - EXPECT_EQ(L"\"\"", token->m_wstring); + EXPECT_EQ(L"\"\"", token->m_string); lexer = pdfium::MakeUnique<CXFA_FMLexer>( L"\"The message reads: \"\"Warning: Insufficient Memory\"\"\""); token = lexer->NextToken(); EXPECT_EQ(TOKstring, token->m_type); EXPECT_EQ(L"\"The message reads: \"\"Warning: Insufficient Memory\"\"\"", - token->m_wstring); + token->m_string); lexer = pdfium::MakeUnique<CXFA_FMLexer>( L"\"\\u0047\\u006f\\u0066\\u0069\\u0073\\u0068\\u0021\\u000d\\u000a\""); @@ -91,7 +91,7 @@ TEST(CXFA_FMLexerTest, Strings) { EXPECT_EQ(TOKstring, token->m_type); EXPECT_EQ( L"\"\\u0047\\u006f\\u0066\\u0069\\u0073\\u0068\\u0021\\u000d\\u000a\"", - token->m_wstring); + token->m_string); } // Note, 'this' is a keyword but is not matched by the lexer. @@ -178,11 +178,11 @@ TEST(CXFA_FMLexerTest, Comments) { lexer = pdfium::MakeUnique<CXFA_FMLexer>(L"123 // Empty.\n\"str\""); token = lexer->NextToken(); EXPECT_EQ(TOKnumber, token->m_type); - EXPECT_EQ(L"123", token->m_wstring); + EXPECT_EQ(L"123", token->m_string); token = lexer->NextToken(); EXPECT_EQ(TOKstring, token->m_type); - EXPECT_EQ(L"\"str\"", token->m_wstring); + EXPECT_EQ(L"\"str\"", token->m_string); token = lexer->NextToken(); EXPECT_EQ(TOKeof, token->m_type); @@ -198,11 +198,11 @@ TEST(CXFA_FMLexerTest, Comments) { lexer = pdfium::MakeUnique<CXFA_FMLexer>(L"123 ;Empty.\n\"str\""); token = lexer->NextToken(); EXPECT_EQ(TOKnumber, token->m_type); - EXPECT_EQ(L"123", token->m_wstring); + EXPECT_EQ(L"123", token->m_string); token = lexer->NextToken(); EXPECT_EQ(TOKstring, token->m_type); - EXPECT_EQ(L"\"str\"", token->m_wstring); + EXPECT_EQ(L"\"str\"", token->m_string); token = lexer->NextToken(); EXPECT_EQ(TOKeof, token->m_type); @@ -215,7 +215,7 @@ TEST(CXFA_FMLexerTest, ValidIdentifiers) { auto lexer = pdfium::MakeUnique<CXFA_FMLexer>(ident); CXFA_FMToken* token = lexer->NextToken(); EXPECT_EQ(TOKidentifier, token->m_type); - EXPECT_EQ(ident, token->m_wstring); + EXPECT_EQ(ident, token->m_string); } } @@ -260,11 +260,11 @@ TEST(CXFA_FMLexerTest, Whitespace) { lexer = pdfium::MakeUnique<CXFA_FMLexer>(L"123 \t\xc\x9\xb 456"); token = lexer->NextToken(); EXPECT_EQ(TOKnumber, token->m_type); - EXPECT_EQ(L"123", token->m_wstring); + EXPECT_EQ(L"123", token->m_string); token = lexer->NextToken(); EXPECT_EQ(TOKnumber, token->m_type); - EXPECT_EQ(L"456", token->m_wstring); + EXPECT_EQ(L"456", token->m_string); token = lexer->NextToken(); EXPECT_EQ(TOKeof, token->m_type); diff --git a/xfa/fxfa/fm2js/cxfa_fmparse.cpp b/xfa/fxfa/fm2js/cxfa_fmparse.cpp index 50e60d3269..723a735936 100644 --- a/xfa/fxfa/fm2js/cxfa_fmparse.cpp +++ b/xfa/fxfa/fm2js/cxfa_fmparse.cpp @@ -77,12 +77,12 @@ std::unique_ptr<CXFA_FMExpression> CXFA_FMParse::ParseFunction() { CFX_WideStringC ident; std::vector<CFX_WideStringC> arguments; std::vector<std::unique_ptr<CXFA_FMExpression>> expressions; - uint32_t line = m_pToken->m_uLinenum; + uint32_t line = m_pToken->m_line_num; NextToken(); if (m_pToken->m_type != TOKidentifier) { m_ParserError = true; } else { - ident = m_pToken->m_wstring; + ident = m_pToken->m_string; NextToken(); } Check(TOKlparen); @@ -91,7 +91,7 @@ std::unique_ptr<CXFA_FMExpression> CXFA_FMParse::ParseFunction() { } else { while (1) { if (m_pToken->m_type == TOKidentifier) { - arguments.push_back(m_pToken->m_wstring); + arguments.push_back(m_pToken->m_string); NextToken(); if (m_pToken->m_type == TOKcomma) { NextToken(); @@ -124,7 +124,7 @@ std::unique_ptr<CXFA_FMExpression> CXFA_FMParse::ParseFunction() { std::unique_ptr<CXFA_FMExpression> CXFA_FMParse::ParseExpression() { std::unique_ptr<CXFA_FMExpression> expr; - uint32_t line = m_pToken->m_uLinenum; + uint32_t line = m_pToken->m_line_num; switch (m_pToken->m_type) { case TOKvar: expr = ParseVarExpression(); @@ -172,12 +172,12 @@ std::unique_ptr<CXFA_FMExpression> CXFA_FMParse::ParseExpression() { std::unique_ptr<CXFA_FMExpression> CXFA_FMParse::ParseVarExpression() { CFX_WideStringC ident; - uint32_t line = m_pToken->m_uLinenum; + uint32_t line = m_pToken->m_line_num; NextToken(); if (m_pToken->m_type != TOKidentifier) { m_ParserError = true; } else { - ident = m_pToken->m_wstring; + ident = m_pToken->m_string; NextToken(); } std::unique_ptr<CXFA_FMExpression> expr; @@ -192,7 +192,7 @@ std::unique_ptr<CXFA_FMExpression> CXFA_FMParse::ParseVarExpression() { } std::unique_ptr<CXFA_FMSimpleExpression> CXFA_FMParse::ParseSimpleExpression() { - uint32_t line = m_pToken->m_uLinenum; + uint32_t line = m_pToken->m_line_num; std::unique_ptr<CXFA_FMSimpleExpression> pExp1 = ParseLogicalOrExpression(); int level = 1; while (m_pToken->m_type == TOKassign) { @@ -211,7 +211,7 @@ std::unique_ptr<CXFA_FMSimpleExpression> CXFA_FMParse::ParseSimpleExpression() { } std::unique_ptr<CXFA_FMExpression> CXFA_FMParse::ParseExpExpression() { - uint32_t line = m_pToken->m_uLinenum; + uint32_t line = m_pToken->m_line_num; std::unique_ptr<CXFA_FMSimpleExpression> pExp1 = ParseSimpleExpression(); if (HasError()) return nullptr; @@ -221,7 +221,7 @@ std::unique_ptr<CXFA_FMExpression> CXFA_FMParse::ParseExpExpression() { std::unique_ptr<CXFA_FMSimpleExpression> CXFA_FMParse::ParseLogicalOrExpression() { - uint32_t line = m_pToken->m_uLinenum; + uint32_t line = m_pToken->m_line_num; std::unique_ptr<CXFA_FMSimpleExpression> e1 = ParseLogicalAndExpression(); for (;;) { switch (m_pToken->m_type) { @@ -248,7 +248,7 @@ CXFA_FMParse::ParseLogicalOrExpression() { std::unique_ptr<CXFA_FMSimpleExpression> CXFA_FMParse::ParseLogicalAndExpression() { - uint32_t line = m_pToken->m_uLinenum; + uint32_t line = m_pToken->m_line_num; std::unique_ptr<CXFA_FMSimpleExpression> e1 = ParseEqualityExpression(); for (;;) { switch (m_pToken->m_type) { @@ -274,7 +274,7 @@ CXFA_FMParse::ParseLogicalAndExpression() { std::unique_ptr<CXFA_FMSimpleExpression> CXFA_FMParse::ParseEqualityExpression() { - uint32_t line = m_pToken->m_uLinenum; + uint32_t line = m_pToken->m_line_num; std::unique_ptr<CXFA_FMSimpleExpression> e1 = ParseRelationalExpression(); for (;;) { std::unique_ptr<CXFA_FMSimpleExpression> e2; @@ -311,7 +311,7 @@ CXFA_FMParse::ParseEqualityExpression() { std::unique_ptr<CXFA_FMSimpleExpression> CXFA_FMParse::ParseRelationalExpression() { - uint32_t line = m_pToken->m_uLinenum; + uint32_t line = m_pToken->m_line_num; std::unique_ptr<CXFA_FMSimpleExpression> e1 = ParseAddtiveExpression(); for (;;) { std::unique_ptr<CXFA_FMSimpleExpression> e2; @@ -370,7 +370,7 @@ CXFA_FMParse::ParseRelationalExpression() { std::unique_ptr<CXFA_FMSimpleExpression> CXFA_FMParse::ParseAddtiveExpression() { - uint32_t line = m_pToken->m_uLinenum; + uint32_t line = m_pToken->m_line_num; std::unique_ptr<CXFA_FMSimpleExpression> e1 = ParseMultiplicativeExpression(); for (;;) { std::unique_ptr<CXFA_FMSimpleExpression> e2; @@ -405,7 +405,7 @@ CXFA_FMParse::ParseAddtiveExpression() { std::unique_ptr<CXFA_FMSimpleExpression> CXFA_FMParse::ParseMultiplicativeExpression() { - uint32_t line = m_pToken->m_uLinenum; + uint32_t line = m_pToken->m_line_num; std::unique_ptr<CXFA_FMSimpleExpression> e1 = ParseUnaryExpression(); for (;;) { std::unique_ptr<CXFA_FMSimpleExpression> e2; @@ -440,7 +440,7 @@ CXFA_FMParse::ParseMultiplicativeExpression() { std::unique_ptr<CXFA_FMSimpleExpression> CXFA_FMParse::ParseUnaryExpression() { std::unique_ptr<CXFA_FMSimpleExpression> expr; - uint32_t line = m_pToken->m_uLinenum; + uint32_t line = m_pToken->m_line_num; switch (m_pToken->m_type) { case TOKplus: NextToken(); @@ -476,20 +476,20 @@ std::unique_ptr<CXFA_FMSimpleExpression> CXFA_FMParse::ParseUnaryExpression() { std::unique_ptr<CXFA_FMSimpleExpression> CXFA_FMParse::ParsePrimaryExpression() { std::unique_ptr<CXFA_FMSimpleExpression> expr; - uint32_t line = m_pToken->m_uLinenum; + uint32_t line = m_pToken->m_line_num; switch (m_pToken->m_type) { case TOKnumber: - expr = pdfium::MakeUnique<CXFA_FMNumberExpression>(line, - m_pToken->m_wstring); + expr = + pdfium::MakeUnique<CXFA_FMNumberExpression>(line, m_pToken->m_string); NextToken(); break; case TOKstring: - expr = pdfium::MakeUnique<CXFA_FMStringExpression>(line, - m_pToken->m_wstring); + expr = + pdfium::MakeUnique<CXFA_FMStringExpression>(line, m_pToken->m_string); NextToken(); break; case TOKidentifier: { - CFX_WideStringC wsIdentifier(m_pToken->m_wstring); + CFX_WideStringC wsIdentifier(m_pToken->m_string); NextToken(); if (m_pToken->m_type == TOKlbracket) { std::unique_ptr<CXFA_FMSimpleExpression> s = ParseIndexExpression(); @@ -506,7 +506,7 @@ CXFA_FMParse::ParsePrimaryExpression() { } case TOKif: expr = pdfium::MakeUnique<CXFA_FMIdentifierExpression>( - line, m_pToken->m_wstring); + line, m_pToken->m_string); NextToken(); break; case TOKnull: @@ -529,7 +529,7 @@ CXFA_FMParse::ParsePrimaryExpression() { std::unique_ptr<CXFA_FMSimpleExpression> CXFA_FMParse::ParsePostExpression( std::unique_ptr<CXFA_FMSimpleExpression> expr) { - uint32_t line = m_pToken->m_uLinenum; + uint32_t line = m_pToken->m_line_num; while (1) { switch (m_pToken->m_type) { case TOKlparen: { @@ -572,8 +572,8 @@ std::unique_ptr<CXFA_FMSimpleExpression> CXFA_FMParse::ParsePostExpression( case TOKdot: NextToken(); if (m_pToken->m_type == TOKidentifier) { - CFX_WideStringC tempStr = m_pToken->m_wstring; - uint32_t tempLine = m_pToken->m_uLinenum; + CFX_WideStringC tempStr = m_pToken->m_string; + uint32_t tempLine = m_pToken->m_line_num; NextToken(); if (m_pToken->m_type == TOKlparen) { std::unique_ptr<CXFA_FMSimpleExpression> pExpCall; @@ -640,8 +640,8 @@ std::unique_ptr<CXFA_FMSimpleExpression> CXFA_FMParse::ParsePostExpression( case TOKdotdot: NextToken(); if (m_pToken->m_type == TOKidentifier) { - CFX_WideStringC tempStr = m_pToken->m_wstring; - uint32_t tempLine = m_pToken->m_uLinenum; + CFX_WideStringC tempStr = m_pToken->m_string; + uint32_t tempLine = m_pToken->m_line_num; NextToken(); if (m_pToken->m_type == TOKlbracket) { std::unique_ptr<CXFA_FMSimpleExpression> s = ParseIndexExpression(); @@ -669,8 +669,8 @@ std::unique_ptr<CXFA_FMSimpleExpression> CXFA_FMParse::ParsePostExpression( m_ParserError = true; return expr; } - CFX_WideStringC tempStr = m_pToken->m_wstring; - uint32_t tempLine = m_pToken->m_uLinenum; + CFX_WideStringC tempStr = m_pToken->m_string; + uint32_t tempLine = m_pToken->m_line_num; NextToken(); if (m_pToken->m_type != TOKlbracket) { std::unique_ptr<CXFA_FMSimpleExpression> s = @@ -706,7 +706,7 @@ std::unique_ptr<CXFA_FMSimpleExpression> CXFA_FMParse::ParsePostExpression( std::unique_ptr<CXFA_FMSimpleExpression> CXFA_FMParse::ParseIndexExpression() { std::unique_ptr<CXFA_FMSimpleExpression> pExp; - uint32_t line = m_pToken->m_uLinenum; + uint32_t line = m_pToken->m_line_num; NextToken(); std::unique_ptr<CXFA_FMSimpleExpression> s; XFA_FM_AccessorIndex accessorIndex = ACCESSOR_NO_RELATIVEINDEX; @@ -746,7 +746,7 @@ std::unique_ptr<CXFA_FMSimpleExpression> CXFA_FMParse::ParseParenExpression() { return nullptr; } - uint32_t line = m_pToken->m_uLinenum; + uint32_t line = m_pToken->m_line_num; std::unique_ptr<CXFA_FMSimpleExpression> pExp1 = ParseLogicalOrExpression(); int level = 1; @@ -767,7 +767,7 @@ std::unique_ptr<CXFA_FMSimpleExpression> CXFA_FMParse::ParseParenExpression() { } std::unique_ptr<CXFA_FMExpression> CXFA_FMParse::ParseBlockExpression() { - uint32_t line = m_pToken->m_uLinenum; + uint32_t line = m_pToken->m_line_num; std::unique_ptr<CXFA_FMExpression> expr; std::vector<std::unique_ptr<CXFA_FMExpression>> expressions; @@ -807,7 +807,7 @@ std::unique_ptr<CXFA_FMExpression> CXFA_FMParse::ParseBlockExpression() { } std::unique_ptr<CXFA_FMExpression> CXFA_FMParse::ParseIfExpression() { - uint32_t line = m_pToken->m_uLinenum; + uint32_t line = m_pToken->m_line_num; const wchar_t* pStartPos = m_lexer->GetPos(); NextToken(); Check(TOKlparen); @@ -824,7 +824,7 @@ std::unique_ptr<CXFA_FMExpression> CXFA_FMParse::ParseIfExpression() { auto pNewToken = pdfium::MakeUnique<CXFA_FMToken>(line); m_pToken = pNewToken.get(); m_pToken->m_type = TOKidentifier; - m_pToken->m_wstring = L"if"; + m_pToken->m_string = L"if"; m_lexer->SetToken(std::move(pNewToken)); m_lexer->SetPos(pStartPos); return ParseExpExpression(); @@ -864,7 +864,7 @@ std::unique_ptr<CXFA_FMExpression> CXFA_FMParse::ParseIfExpression() { } std::unique_ptr<CXFA_FMExpression> CXFA_FMParse::ParseWhileExpression() { - uint32_t line = m_pToken->m_uLinenum; + uint32_t line = m_pToken->m_line_num; NextToken(); std::unique_ptr<CXFA_FMSimpleExpression> pCondition = ParseParenExpression(); Check(TOKdo); @@ -895,12 +895,12 @@ CXFA_FMParse::ParseSubassignmentInForExpression() { std::unique_ptr<CXFA_FMExpression> CXFA_FMParse::ParseForExpression() { CFX_WideStringC wsVariant; - uint32_t line = m_pToken->m_uLinenum; + uint32_t line = m_pToken->m_line_num; NextToken(); if (m_pToken->m_type != TOKidentifier) m_ParserError = true; - wsVariant = m_pToken->m_wstring; + wsVariant = m_pToken->m_string; NextToken(); std::unique_ptr<CXFA_FMSimpleExpression> pAssignment; if (m_pToken->m_type == TOKassign) { @@ -942,12 +942,12 @@ std::unique_ptr<CXFA_FMExpression> CXFA_FMParse::ParseForeachExpression() { CFX_WideStringC wsIdentifier; std::vector<std::unique_ptr<CXFA_FMSimpleExpression>> pAccessors; std::unique_ptr<CXFA_FMExpression> pList; - uint32_t line = m_pToken->m_uLinenum; + uint32_t line = m_pToken->m_line_num; NextToken(); if (m_pToken->m_type != TOKidentifier) m_ParserError = true; - wsIdentifier = m_pToken->m_wstring; + wsIdentifier = m_pToken->m_string; NextToken(); Check(TOKin); Check(TOKlparen); @@ -976,7 +976,7 @@ std::unique_ptr<CXFA_FMExpression> CXFA_FMParse::ParseForeachExpression() { } std::unique_ptr<CXFA_FMExpression> CXFA_FMParse::ParseDoExpression() { - uint32_t line = m_pToken->m_uLinenum; + uint32_t line = m_pToken->m_line_num; NextToken(); std::unique_ptr<CXFA_FMExpression> expr = ParseBlockExpression(); Check(TOKend); |