This commit is contained in:
Alon Zakai 2014-11-03 17:49:42 -08:00
Родитель 048cc5b9b9
Коммит e037505db7
2 изменённых файлов: 16 добавлений и 13 удалений

Просмотреть файл

@ -18,13 +18,14 @@ struct Value;
// Reference to a value. Simple shared_ptr, plus [] operator for convenience - we work on lots of arrays
class Ref : public std::shared_ptr<Value> {
public:
Ref() {
reset();
}
Ref(Value *v) {
reset(v);
}
Ref& operator[](unsigned x) {
return (*this)[x];
}
Ref& operator[](unsigned x);
// special convenience for comparison to string, which is by value
bool operator==(const char *str);
@ -292,7 +293,11 @@ struct ArrayValue : public Value {
}
};
//
// Ref methods
Ref& Ref::operator[](unsigned x) {
return (*get())[x];
}
bool Ref::operator==(const char *str) {
return get()->isString() && get()->getString() == str;

Просмотреть файл

@ -15,7 +15,7 @@
// Globals
//==================
Value doc;
Ref doc;
//==================
// Infrastructure
@ -352,7 +352,7 @@ void simplifyIfs(Ref ast) {
Ref other = stats[stats->size()-1];
if (other[0] != "if") {
// our if block does not end with an if. perhaps if have an else we can flip
if (node->size() >= 4 && node[3][0] == "block") {
if (node->size() >= 4 && node[3][0] == "block") { // XXX node[3] is false, not an array
stats = node[3][1];
if (stats->size() == 0) break;
other = stats[stats->size()-1];
@ -535,11 +535,9 @@ int main(int argc, char **argv) {
char *comment = strstr(json, "//");
if (comment) *comment = 0; // drop off the comments; TODO: parse extra info
// Parse JSON source into a Document
doc.parse(json);
/*
doc.Parse(json);
assert(!doc.HasParseError());
// Parse JSON source into the document
doc = new Value();
doc->parse(json);
delete[] json;
// Run passes on the Document
@ -555,9 +553,9 @@ int main(int argc, char **argv) {
assert(0);
}
}
*/
// Emit JSON of modified Document
doc.stringify(std::cout);
doc->stringify(std::cout);
return 0;
}