diff options
Diffstat (limited to 'cpp')
-rw-r--r-- | cpp/src/slice2freeze/Main.cpp | 28 | ||||
-rw-r--r-- | cpp/src/slice2freezej/Main.cpp | 28 |
2 files changed, 52 insertions, 4 deletions
diff --git a/cpp/src/slice2freeze/Main.cpp b/cpp/src/slice2freeze/Main.cpp index 2c540f7b3e3..1f8bac6c4ef 100644 --- a/cpp/src/slice2freeze/Main.cpp +++ b/cpp/src/slice2freeze/Main.cpp @@ -19,6 +19,11 @@ struct DictIndex { string member; bool caseSensitive; + + bool operator==(const DictIndex& rhs) const + { + return member == rhs.member; + } }; struct Dict @@ -596,6 +601,13 @@ writeDict(const string& n, UnitPtr& u, const Dict& dict, Output& H, Output& C, c return false; } + if(!Dictionary::legalKeyType(valueType)) + { + cerr << n << ": `" << dict.value << "' is not a valid index type" << endl; + return false; + } + + if(index.caseSensitive == false) { // @@ -606,7 +618,7 @@ writeDict(const string& n, UnitPtr& u, const Dict& dict, Output& H, Output& C, c if(builtInType == 0 || builtInType->kind() != Builtin::KindString) { - cerr << n << ": VALUE is a `" << dict.value << "', not a string " << endl; + cerr << n << ": VALUE is a `" << dict.value << "', not a string" << endl; return false; } } @@ -653,6 +665,12 @@ writeDict(const string& n, UnitPtr& u, const Dict& dict, Output& H, Output& C, c TypePtr dataMemberType = dataMember->type(); + if(!Dictionary::legalKeyType(dataMemberType)) + { + cerr << n << ": `" << index.member << "' cannot be used as an index" << endl; + return false; + } + if(index.caseSensitive == false) { // @@ -661,7 +679,7 @@ writeDict(const string& n, UnitPtr& u, const Dict& dict, Output& H, Output& C, c BuiltinPtr memberType = BuiltinPtr::dynamicCast(dataMemberType); if(memberType == 0 || memberType->kind() != Builtin::KindString) { - cerr << n << ": `" << index.member << "'is not a string " << endl; + cerr << n << ": `" << index.member << "' is not a string " << endl; return false; } } @@ -1161,6 +1179,12 @@ main(int argc, char* argv[]) { if(p->name == dictName) { + if(find(p->indices.begin(), p->indices.end(), index) != p->indices.end()) + { + cerr << argv[0] << ": " << argv[idx] << " " << argv[idx + 1] + << ": this dict-index is defined twice" << endl; + return EXIT_FAILURE; + } p->indices.push_back(index); found = true; break; diff --git a/cpp/src/slice2freezej/Main.cpp b/cpp/src/slice2freezej/Main.cpp index 4f47302b2aa..90d8f41be66 100644 --- a/cpp/src/slice2freezej/Main.cpp +++ b/cpp/src/slice2freezej/Main.cpp @@ -18,6 +18,11 @@ struct DictIndex { string member; bool caseSensitive; + + bool operator==(const DictIndex& rhs) const + { + return member == rhs.member; + } }; struct Dict @@ -118,7 +123,13 @@ FreezeGenerator::generate(UnitPtr& u, const Dict& dict) cerr << _prog << ": bad index for dictionary `" << dict.name << "'" << endl; return false; } - + + if(!Dictionary::legalKeyType(valueType)) + { + cerr << _prog << ": `" << dict.value << "' is not a valid index type" << endl; + return false; + } + if(index.caseSensitive == false) { // @@ -179,6 +190,12 @@ FreezeGenerator::generate(UnitPtr& u, const Dict& dict) TypePtr dataMemberType = dataMember->type(); + if(!Dictionary::legalKeyType(dataMemberType)) + { + cerr << _prog << ": `" << index.member << "' cannot be used as an index" << endl; + return false; + } + if(index.caseSensitive == false) { // @@ -187,7 +204,7 @@ FreezeGenerator::generate(UnitPtr& u, const Dict& dict) BuiltinPtr memberType = BuiltinPtr::dynamicCast(dataMemberType); if(memberType == 0 || memberType->kind() != Builtin::KindString) { - cerr << _prog << ": `" << index.member << "'is not a string " << endl; + cerr << _prog << ": `" << index.member << "' is not a string " << endl; return false; } } @@ -1123,6 +1140,13 @@ main(int argc, char* argv[]) { if(p->name == dictName) { + if(find(p->indices.begin(), p->indices.end(), index) != p->indices.end()) + { + cerr << argv[0] << ": " << argv[idx] << " " << argv[idx + 1] + << ": this dict-index is defined twice" << endl; + return EXIT_FAILURE; + } + p->indices.push_back(index); found = true; break; |