diff options
author | Manuel Klimek <klimek@google.com> | 2011-12-20 10:42:52 +0000 |
---|---|---|
committer | Manuel Klimek <klimek@google.com> | 2011-12-20 10:42:52 +0000 |
commit | 47151c37b674fadc89a9797f3d54d90402a61748 (patch) | |
tree | a2348ee94497c9f73c380144d0ca52664c2a1a1c /llvm/lib/Support/JSONParser.cpp | |
parent | 860d978ef6ae947487bb16576dd849ccf0796b5d (diff) | |
download | bcm5719-llvm-47151c37b674fadc89a9797f3d54d90402a61748.tar.gz bcm5719-llvm-47151c37b674fadc89a9797f3d54d90402a61748.zip |
Pulls the implementation of skip() into JSONParser.
This is the first step towards migrating more of the parser
implementation into the parser class.
llvm-svn: 146971
Diffstat (limited to 'llvm/lib/Support/JSONParser.cpp')
-rw-r--r-- | llvm/lib/Support/JSONParser.cpp | 35 |
1 files changed, 24 insertions, 11 deletions
diff --git a/llvm/lib/Support/JSONParser.cpp b/llvm/lib/Support/JSONParser.cpp index 36da12d3764..02187409cbf 100644 --- a/llvm/lib/Support/JSONParser.cpp +++ b/llvm/lib/Support/JSONParser.cpp @@ -40,7 +40,30 @@ JSONValue *JSONParser::parseRoot() { } bool JSONParser::validate() { - return parseRoot()->skip(); + return skip(*parseRoot()); +} + +template <typename ContainerT> +bool JSONParser::skipContainer(const ContainerT &Container) { + for (typename ContainerT::const_iterator I = Container.current(), + E = Container.end(); + I != E; ++I) { + assert(*I != 0); + if (!skip(**I)) + return false; + } + return !failed(); +} + +bool JSONParser::skip(const JSONAtom &Atom) { + switch(Atom.getKind()) { + case JSONAtom::JK_Array: return skipContainer(*cast<JSONArray>(&Atom)); + case JSONAtom::JK_Object: return skipContainer(*cast<JSONObject>(&Atom)); + case JSONAtom::JK_String: return true; + case JSONAtom::JK_KeyValuePair: + return skip(*cast<JSONKeyValuePair>(&Atom)->Value); + } + llvm_unreachable("Impossible enum value."); } // Sets the current error to: @@ -159,16 +182,6 @@ std::string JSONParser::getErrorMessage() const { return ErrorMessage; } -bool JSONAtom::skip() const { - switch (MyKind) { - case JK_Array: return cast<JSONArray>(this)->skip(); - case JK_Object: return cast<JSONObject>(this)->skip(); - case JK_String: return cast<JSONString>(this)->skip(); - case JK_KeyValuePair: return cast<JSONKeyValuePair>(this)->skip(); - } - llvm_unreachable("Impossible enum value."); -} - // Parses a JSONValue, assuming that the current position is at the first // character of the value. JSONValue *JSONParser::parseValue() { |