diff options
author | nsrtvwls <oakjumper@gmail.com> | 2018-09-28 08:11:21 -0700 |
---|---|---|
committer | James E. King III <jking@apache.org> | 2018-09-28 11:11:21 -0400 |
commit | 014f53f6582fbae8146ae291d471382016091a06 (patch) | |
tree | ebd77be07d6be35c8c840278688bb2fee0a94c1a /compiler/cpp/src/thrift/generate/t_generator.cc | |
parent | c64389a194fe1516fef5830151dfb8b35f6c6bb2 (diff) | |
download | thrift-014f53f6582fbae8146ae291d471382016091a06.tar.gz |
THRIFT-4496: python specific list of keywords for python generator (#1567)
Client: py
Diffstat (limited to 'compiler/cpp/src/thrift/generate/t_generator.cc')
-rw-r--r-- | compiler/cpp/src/thrift/generate/t_generator.cc | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/compiler/cpp/src/thrift/generate/t_generator.cc b/compiler/cpp/src/thrift/generate/t_generator.cc index 7549d5dc2..ca3f5dd68 100644 --- a/compiler/cpp/src/thrift/generate/t_generator.cc +++ b/compiler/cpp/src/thrift/generate/t_generator.cc @@ -76,6 +76,77 @@ void t_generator::generate_program() { close_generator(); } +std::set<std::string> t_generator::lang_keywords() const { + std::string keywords[] = { "BEGIN", "END", "__CLASS__", "__DIR__", "__FILE__", "__FUNCTION__", + "__LINE__", "__METHOD__", "__NAMESPACE__", "abstract", "alias", "and", "args", "as", + "assert", "begin", "break", "case", "catch", "class", "clone", "continue", "declare", + "def", "default", "del", "delete", "do", "dynamic", "elif", "else", "elseif", "elsif", + "end", "enddeclare", "endfor", "endforeach", "endif", "endswitch", "endwhile", "ensure", + "except", "exec", "finally", "float", "for", "foreach", "from", "function", "global", + "goto", "if", "implements", "import", "in", "inline", "instanceof", "interface", "is", + "lambda", "module", "native", "new", "next", "nil", "not", "or", "package", "pass", + "public", "print", "private", "protected", "raise", "redo", "rescue", "retry", "register", + "return", "self", "sizeof", "static", "super", "switch", "synchronized", "then", "this", + "throw", "transient", "try", "undef", "unless", "unsigned", "until", "use", "var", + "virtual", "volatile", "when", "while", "with", "xor", "yield" }; + return std::set<std::string>(keywords, keywords + sizeof(keywords)/sizeof(keywords[0]) ); +} + +void t_generator::validate_input() const { + validate(program_->get_enums()); + validate(program_->get_typedefs()); + validate(program_->get_objects()); + validate(program_->get_consts()); + validate(program_->get_services()); +} + +template <typename T> +void t_generator::validate(const vector<T>& list) const{ + typename vector<T>::const_iterator it; + for(it=list.begin(); it != list.end(); ++it) { + validate(*it); + } +} + +void t_generator::validate(t_function const* f) const { + validate_id(f->get_name()); + validate(f->get_arglist()); + validate(f->get_xceptions()); +} + +void t_generator::validate(t_service const* s) const { + validate_id(s->get_name()); + validate(s->get_functions()); +} + +void t_generator::validate(t_enum const* en) const { + validate_id(en->get_name()); + validate(en->get_constants()); +} +void t_generator::validate(t_struct const* s) const { + validate_id(s->get_name()); + validate(s->get_members()); +} + +void t_generator::validate(t_enum_value const* en_val) const { + validate_id(en_val->get_name()); +} +void t_generator::validate(t_typedef const* td) const { + validate_id(td->get_name()); +} +void t_generator::validate(t_const const* c) const { + validate_id(c->get_name()); +} +void t_generator::validate(t_field const* f) const { + validate_id(f->get_name()); +} + +void t_generator::validate_id(const string& id) const { + if (keywords_.find(id) != keywords_.end()) { + failure("Cannot use reserved language keyword: \"%s\"", id.c_str()); + } +} + string t_generator::escape_string(const string& in) const { string result = ""; for (string::const_iterator it = in.begin(); it < in.end(); it++) { |