From 9ce6937701cd28fb2aafdd3ec950fb0e70bae8cd Mon Sep 17 00:00:00 2001 From: Manuel Klimek Date: Tue, 20 Dec 2011 10:42:52 +0000 Subject: Pulls the implementation of skip() into JSONParser. This is the first step towards migrating more of the parser implementation into the parser class. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@146971 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Support/JSONParser.cpp | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) (limited to 'lib/Support/JSONParser.cpp') diff --git a/lib/Support/JSONParser.cpp b/lib/Support/JSONParser.cpp index 36da12d376..02187409cb 100644 --- a/lib/Support/JSONParser.cpp +++ b/lib/Support/JSONParser.cpp @@ -40,7 +40,30 @@ JSONValue *JSONParser::parseRoot() { } bool JSONParser::validate() { - return parseRoot()->skip(); + return skip(*parseRoot()); +} + +template +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(&Atom)); + case JSONAtom::JK_Object: return skipContainer(*cast(&Atom)); + case JSONAtom::JK_String: return true; + case JSONAtom::JK_KeyValuePair: + return skip(*cast(&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(this)->skip(); - case JK_Object: return cast(this)->skip(); - case JK_String: return cast(this)->skip(); - case JK_KeyValuePair: return cast(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() { -- cgit v1.2.3-18-g5258