Changeset 89184 in webkit for trunk/Source/JavaScriptCore/runtime/LiteralParser.h
- Timestamp:
- Jun 17, 2011, 9:25:57 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/runtime/LiteralParser.h
r65177 r89184 27 27 #define LiteralParser_h 28 28 29 #include "Identifier.h" 29 30 #include "JSGlobalObjectFunctions.h" 30 31 #include "JSValue.h" … … 35 36 class LiteralParser { 36 37 public: 37 typedef enum { StrictJSON, NonStrictJSON } ParserMode;38 LiteralParser(ExecState* exec, const U String& s, ParserMode mode)38 typedef enum { StrictJSON, NonStrictJSON, JSONP } ParserMode; 39 LiteralParser(ExecState* exec, const UChar* characters, unsigned length, ParserMode mode) 39 40 : m_exec(exec) 40 , m_lexer( s, mode)41 , m_lexer(characters, length, mode) 41 42 , m_mode(mode) 42 43 { … … 47 48 m_lexer.next(); 48 49 JSValue result = parse(m_mode == StrictJSON ? StartParseExpression : StartParseStatement); 50 if (m_lexer.currentToken().type == TokSemi) 51 m_lexer.next(); 49 52 if (m_lexer.currentToken().type != TokEnd) 50 53 return JSValue(); 51 54 return result; 52 55 } 56 57 enum JSONPPathEntryType { 58 JSONPPathEntryTypeDeclare, // var pathEntryName = JSON 59 JSONPPathEntryTypeDot, // <prior entries>.pathEntryName = JSON 60 JSONPPathEntryTypeLookup // <prior entries>[pathIndex] = JSON 61 }; 62 63 struct JSONPPathEntry { 64 JSONPPathEntryType m_type; 65 Identifier m_pathEntryName; 66 int m_pathIndex; 67 }; 68 69 struct JSONPData { 70 Vector<JSONPPathEntry> m_path; 71 Strong<Unknown> m_value; 72 }; 73 74 bool tryJSONPParse(Vector<JSONPData>&); 75 53 76 private: 54 77 enum ParserState { StartParseObject, StartParseArray, StartParseExpression, … … 59 82 TokString, TokIdentifier, TokNumber, TokColon, 60 83 TokLParen, TokRParen, TokComma, TokTrue, TokFalse, 61 TokNull, TokEnd, Tok Error };62 84 TokNull, TokEnd, TokDot, TokAssign, TokSemi, TokError }; 85 63 86 class Lexer { 64 87 public: … … 67 90 const UChar* start; 68 91 const UChar* end; 69 UString stringToken; 70 double numberToken; 92 UString stringBuffer; 93 union { 94 double numberToken; 95 struct { 96 const UChar* stringToken; 97 int stringLength; 98 }; 99 }; 71 100 }; 72 Lexer(const UString& s, ParserMode mode) 73 : m_string(s) 74 , m_mode(mode) 75 , m_ptr(s.characters()) 76 , m_end(s.characters() + s.length()) 101 Lexer(const UChar* characters, unsigned length, ParserMode mode) 102 : m_mode(mode) 103 , m_ptr(characters) 104 , m_end(characters + length) 77 105 { 78 106 } 79 107 80 TokenType next() 81 { 82 return lex(m_currentToken); 83 } 108 TokenType next(); 84 109 85 110 const LiteralParserToken& currentToken() … … 89 114 90 115 private: 91 TokenType lex(LiteralParserToken&);92 template <ParserMode mode >TokenType lexString(LiteralParserToken&);93 TokenType lexNumber(LiteralParserToken&);116 template <ParserMode mode> TokenType lex(LiteralParserToken&); 117 template <ParserMode mode, UChar terminator> ALWAYS_INLINE TokenType lexString(LiteralParserToken&); 118 ALWAYS_INLINE TokenType lexNumber(LiteralParserToken&); 94 119 LiteralParserToken m_currentToken; 95 120 UString m_string; … … 105 130 LiteralParser::Lexer m_lexer; 106 131 ParserMode m_mode; 132 static unsigned const MaximumCachableCharacter = 128; 133 FixedArray<Identifier, MaximumCachableCharacter> m_shortIdentifiers; 134 FixedArray<Identifier, MaximumCachableCharacter> m_recentIdentifiers; 135 ALWAYS_INLINE const Identifier makeIdentifier(const UChar* characters, size_t length); 107 136 }; 137 108 138 } 109 139
Note:
See TracChangeset
for help on using the changeset viewer.