You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by ns...@apache.org on 2016/09/25 16:43:15 UTC

[26/55] [abbrv] [partial] thrift git commit: THRIFT-2835 Add possibility to distribute generators separately from thrift core, and load them dynamically

http://git-wip-us.apache.org/repos/asf/thrift/blob/052abc39/compiler/cpp/src/generate/t_xml_generator.cc
----------------------------------------------------------------------
diff --git a/compiler/cpp/src/generate/t_xml_generator.cc b/compiler/cpp/src/generate/t_xml_generator.cc
deleted file mode 100644
index 5465b49..0000000
--- a/compiler/cpp/src/generate/t_xml_generator.cc
+++ /dev/null
@@ -1,687 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-#include <fstream>
-#include <iostream>
-#include <sstream>
-#include <limits>
-
-#include <stdlib.h>
-#include <sys/stat.h>
-#include <sstream>
-
-#include "t_generator.h"
-#include "platform.h"
-
-using std::map;
-using std::ofstream;
-using std::ostream;
-using std::ostringstream;
-using std::string;
-using std::stringstream;
-using std::vector;
-using std::stack;
-using std::set;
-
-static const string endl = "\n";
-static const string quot = "\"";
-
-static const string default_ns_prefix = "http://thrift.apache.org/xml/ns/";
-
-/**
- * This generator creates an XML model of the parsed IDL tree, and is designed
- * to make it easy to use this file as the input for other template engines,
- * such as XSLT.  To this end, the generated XML is slightly more verbose than
- * you might expect... for example, references to "id" types (such as structs,
- * unions, etc) always specify the name of the IDL document, even if the type
- * is defined in the same document as the reference.
- */
-class t_xml_generator : public t_generator {
-public:
-  t_xml_generator( t_program* program,
-                   const std::map<std::string, std::string>& parsed_options,
-                   const std::string& option_string)
-    : t_generator(program) {
-    (void)option_string;
-    std::map<std::string, std::string>::const_iterator iter;
-
-    should_merge_includes_ = false;
-    should_use_default_ns_ = true;
-    should_use_namespaces_ = true;
-    for( iter = parsed_options.begin(); iter != parsed_options.end(); ++iter) {
-      if( iter->first.compare("merge") == 0) {
-        should_merge_includes_ = true;
-      } else if( iter->first.compare("no_default_ns") == 0) {
-        should_use_default_ns_ = false;
-      } else if( iter->first.compare("no_namespaces") == 0) {
-        should_use_namespaces_ = false;
-      } else {
-        throw "unknown option xml:" + iter->first; 
-      }
-    }
-
-    out_dir_base_ = "gen-xml";
-  }
-
-  virtual ~t_xml_generator() {}
-
-  void init_generator();
-  void close_generator();
-  void generate_program();
-
-  void iterate_program(t_program* program);
-  void generate_typedef(t_typedef* ttypedef);
-  void generate_enum(t_enum* tenum);
-  void generate_function(t_function* tfunc);
-  void generate_field(t_field* field);
-
-  void generate_service(t_service* tservice);
-  void generate_struct(t_struct* tstruct);
-
-  void generate_annotations(std::map<std::string, std::string> annotations);
-
-private:
-  bool should_merge_includes_;
-  bool should_use_default_ns_;
-  bool should_use_namespaces_;
-
-  std::ofstream f_xml_;
- 
-  std::set<string> programs_;
-  std::stack<string> elements_;
-  bool top_element_is_empty;
-  bool top_element_is_open;
-
-  string target_namespace(t_program* program);
-  void write_element_start(const string name);
-  void close_top_element();
-  void write_element_end();
-  void write_attribute(string key, string val);
-  void write_int_attribute(string key, int val);
-  string escape_xml_string(const string& input);
-
-  void write_xml_comment(string msg);
-
-  void write_type(t_type* ttype);
-  void write_doc(t_doc* tdoc);
-
-  template <typename T>
-  string number_to_string(T t) {
-    std::ostringstream out;
-    out.imbue(std::locale::classic());
-    out.precision(std::numeric_limits<T>::digits10);
-    out << t;
-    return out.str();
-  }
-
-  template <typename T>
-  void write_number(T n) {
-    f_xml_ << number_to_string(n);
-  }
-
-  template <typename T>
-  void write_element_number(string name, T n) {
-    write_element_string(name, number_to_string(n));
-  }
-
-  string get_type_name(t_type* ttype);
-
-  void generate_constant(t_const* con);
-
-  void write_element_string(string name, string value);
-  void write_value(t_type* tvalue);
-  void write_const_value(t_const_value* value);
-  virtual std::string xml_autogen_comment() {
-    return std::string("\n") + " * Autogenerated by Thrift Compiler (" + THRIFT_VERSION + ")\n"
-           + " *\n" + " * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING\n";
-  }
-};
-
-void t_xml_generator::init_generator() {
-  MKDIR(get_out_dir().c_str());
-
-  string f_xml_name = get_out_dir() + program_->get_name() + ".xml";
-  f_xml_.open(f_xml_name.c_str());
-
-  top_element_is_open = false;
-}
-
-string t_xml_generator::target_namespace(t_program* program) {
-  std::map<std::string, std::string> map;
-  std::map<std::string, std::string>::iterator iter;
-  map = program->get_namespace_annotations("xml");
-  if ((iter = map.find("targetNamespace")) != map.end()) {
-    return iter->second;
-  }
-  map = program->get_namespaces();
-  if ((iter = map.find("xml")) != map.end()) {
-    return default_ns_prefix + iter->second;
-  }
-  map = program->get_namespace_annotations("*");
-  if ((iter = map.find("xml.targetNamespace")) != map.end()) {
-    return iter->second;
-  }
-  map = program->get_namespaces();
-  if ((iter = map.find("*")) != map.end()) {
-    return default_ns_prefix + iter->second;
-  }
-  return default_ns_prefix + program->get_name();
-}
-
-void t_xml_generator::write_xml_comment(string msg) {
-  close_top_element();
-  // TODO: indent any EOLs that may occur with msg
-  // TODO: proper msg escaping needed?
-  f_xml_ << indent() << "<!-- " << msg << " -->"  << endl;  
-  top_element_is_empty = false;  
-}
-
-void t_xml_generator::close_top_element() {
-  if( top_element_is_open) {
-    top_element_is_open = false;
-    if (elements_.size() > 0 && top_element_is_empty) {
-      f_xml_ << ">" << endl;
-    }
-  }
-}
-
-void t_xml_generator::write_element_start(string name) {
-  if (should_use_namespaces_ && !should_use_default_ns_) {
-    name = "idl:" + name;
-  }
-  close_top_element();
-  f_xml_ << indent() << "<" << name;
-  elements_.push(name);
-  top_element_is_empty = true;
-  top_element_is_open = true;
-  indent_up();
-}
-
-void t_xml_generator::write_element_end() {
-  indent_down();
-  if (top_element_is_empty && top_element_is_open) {
-    f_xml_ << " />" << endl;
-  } else {
-    f_xml_ << indent() << "</" << elements_.top() << ">" << endl;
-  }
-  top_element_is_empty = false;
-  elements_.pop();
-}
-
-void t_xml_generator::write_attribute(string key, string val) {
-  f_xml_ << " " << key << "=\"" << escape_xml_string(val) << "\"";
-}
-
-void t_xml_generator::write_int_attribute(string key, int val) {
-  write_attribute(key, number_to_string(val));
-}
-
-void t_xml_generator::write_element_string(string name, string val) {
-  if (should_use_namespaces_ && !should_use_default_ns_) {
-    name = "idl:" + name;
-  }
-  close_top_element();
-  top_element_is_empty = false;
-  f_xml_ << indent() 
-    << "<" << name << ">" << escape_xml_string(val) << "</" << name << ">"
-    << endl;
-}
-
-string t_xml_generator::escape_xml_string(const string& input) {
-  std::ostringstream ss;
-  for (std::string::const_iterator iter = input.begin(); iter != input.end(); iter++) {
-    switch (*iter) {
-    case '&':
-      ss << "&amp;";
-      break;
-    case '"':
-      ss << "&quot;";
-      break;
-    case '\'':
-      ss << "&apos;";
-      break;
-    case '<':
-      ss << "&lt;";
-      break;
-    case '>':
-      ss << "&gt;";
-      break;
-    default:
-      ss << *iter;
-      break;
-    }
-  }
-  return ss.str();
-}
-
-void t_xml_generator::close_generator() {
-  f_xml_.close();
-}
-
-void t_xml_generator::generate_program() {
-
-  init_generator();
-
-  write_element_start("idl");
-  if (should_use_namespaces_) {
-    if (should_use_default_ns_) {
-      write_attribute("xmlns", "http://thrift.apache.org/xml/idl");
-    }
-    write_attribute("xmlns:idl", "http://thrift.apache.org/xml/idl");
-  }
-
-  write_xml_comment( xml_autogen_comment());
-  
-  iterate_program(program_);
-  
-  write_element_end();
-
-  close_generator();
-
-}
-
-void t_xml_generator::iterate_program(t_program* program) {
-  
-  write_element_start("document");
-  write_attribute("name", program->get_name());
-  if (should_use_namespaces_) {
-    const string targetNamespace = target_namespace(program);
-    write_attribute("targetNamespace", targetNamespace);
-    write_attribute("xmlns:" + program->get_name(), targetNamespace);
-  }
-  write_doc(program);
-
-  const vector<t_program*> includes = program->get_includes();
-  vector<t_program*>::const_iterator inc_it;
-  for (inc_it = includes.begin(); inc_it != includes.end(); ++inc_it) {
-    write_element_start("include");
-    write_attribute("name", (*inc_it)->get_name());
-    write_element_end();
-  }
-
-  const map<string, string>& namespaces = program->get_namespaces();
-  map<string, string>::const_iterator ns_it;
-  for (ns_it = namespaces.begin(); ns_it != namespaces.end(); ++ns_it) {
-    write_element_start("namespace");
-    write_attribute("name", ns_it->first);
-    write_attribute("value", ns_it->second);
-    generate_annotations(program->get_namespace_annotations(ns_it->first));
-    write_element_end();
-  }
-
-  // TODO: can constants have annotations?
-  vector<t_const*> consts = program->get_consts();
-  vector<t_const*>::iterator c_iter;
-  for (c_iter = consts.begin(); c_iter != consts.end(); ++c_iter) {
-    generate_constant(*c_iter);
-  }
-
-  vector<t_typedef*> typedefs = program->get_typedefs();
-  vector<t_typedef*>::iterator td_iter;
-  for (td_iter = typedefs.begin(); td_iter != typedefs.end(); ++td_iter) {
-    generate_typedef(*td_iter);
-  }
-
-  vector<t_enum*> enums = program->get_enums();
-  vector<t_enum*>::iterator en_iter;
-  for (en_iter = enums.begin(); en_iter != enums.end(); ++en_iter) {
-    generate_enum(*en_iter);
-  }
-
-  vector<t_struct*> objects = program->get_objects();
-  vector<t_struct*>::iterator o_iter;
-  for (o_iter = objects.begin(); o_iter != objects.end(); ++o_iter) {
-    if ((*o_iter)->is_xception()) {
-      generate_xception(*o_iter);
-    } else {
-      generate_struct(*o_iter);
-    }
-  }
-
-  vector<t_service*> services = program->get_services();
-  vector<t_service*>::iterator sv_iter;
-  for (sv_iter = services.begin(); sv_iter != services.end(); ++sv_iter) {
-    generate_service(*sv_iter);
-  }
-
-  write_element_end();
-
-  if (should_merge_includes_) {
-    programs_.insert(program->get_name());
-    const vector<t_program*> programs = program->get_includes();
-    vector<t_program*>::const_iterator prog_it;
-    for (prog_it = programs.begin(); prog_it != programs.end(); ++prog_it) {
-      if (!programs_.count((*prog_it)->get_name())) {
-        iterate_program(*prog_it);
-      }
-    }
-  }
-
-}
-
-void t_xml_generator::generate_typedef(t_typedef* ttypedef) {
-  write_element_start("typedef");
-  write_attribute("name", ttypedef->get_name());
-  write_doc(ttypedef);
-  write_type(ttypedef->get_true_type());
-  generate_annotations(ttypedef->annotations_);
-  write_element_end();
-  return;
-}
-
-void t_xml_generator::write_type(t_type* ttype) {
-  const string type = get_type_name(ttype);
-  write_attribute("type", type);
-  if (type == "id") {
-    write_attribute("type-module", ttype->get_program()->get_name());
-    write_attribute("type-id", ttype->get_name());
-  } else if (type == "list" || type == "set") {
-    t_type* etype = ((t_list*)ttype)->get_elem_type();
-    write_element_start("elemType");
-    write_type(etype);
-    write_element_end();
-  } else if (type == "map") {
-    t_type* ktype = ((t_map*)ttype)->get_key_type();
-    write_element_start("keyType");
-    write_type(ktype);
-    write_element_end();
-    t_type* vtype = ((t_map*)ttype)->get_val_type();
-    write_element_start("valueType");
-    write_type(vtype);
-    write_element_end();
-  }
-}
-
-void t_xml_generator::write_doc(t_doc* tdoc) {
-  if (tdoc->has_doc()) {
-    string doc = tdoc->get_doc();
-    // for some reason there always seems to be a trailing newline on doc
-    // comments; loop below naively tries to strip off trailing cr/lf
-    int n = 0;
-    for (string::reverse_iterator i = doc.rbegin(); i != doc.rend(); i++,n++) {
-      if (*i != '\n' || *i == '\r') {
-        if (n > 0) {
-          doc.erase(doc.length() - n);
-        }
-        break;
-      }
-    }
-    write_attribute("doc", doc);
-  }
-}
-
-void t_xml_generator::generate_annotations(
-    std::map<std::string, std::string> annotations) {
-  std::map<std::string, std::string>::iterator iter;
-  for (iter = annotations.begin(); iter != annotations.end(); ++iter) {
-    write_element_start("annotation");
-    write_attribute("key", iter->first);
-    write_attribute("value", iter->second);
-    write_element_end();
-  }
-}
-
-void t_xml_generator::generate_constant(t_const* con) {
-  write_element_start("const");
-  write_attribute("name", con->get_name());
-  write_doc(con);
-  write_type(con->get_type());
-  write_const_value(con->get_value());
-  write_element_end();
-}
-
-void t_xml_generator::write_const_value(t_const_value* value) {
-
-  switch (value->get_type()) {
-
-  case t_const_value::CV_IDENTIFIER:
-  case t_const_value::CV_INTEGER:
-    write_element_number("int", value->get_integer());
-    break;
-
-  case t_const_value::CV_DOUBLE:
-    write_element_number("double", value->get_double());
-    break;
-
-  case t_const_value::CV_STRING:
-    write_element_string("string", value->get_string());
-    break;
-
-  case t_const_value::CV_LIST: {
-    write_element_start("list");
-    std::vector<t_const_value*> list = value->get_list();
-    std::vector<t_const_value*>::iterator lit;
-    for (lit = list.begin(); lit != list.end(); ++lit) {
-      write_element_start("entry");
-      write_const_value(*lit);
-      write_element_end();
-    }
-    write_element_end();
-    break;
-  }
-
-  case t_const_value::CV_MAP: {
-    write_element_start("map");
-    std::map<t_const_value*, t_const_value*> map = value->get_map();
-    std::map<t_const_value*, t_const_value*>::iterator mit;
-    for (mit = map.begin(); mit != map.end(); ++mit) {
-      write_element_start("entry");
-      write_element_start("key");
-      write_const_value(mit->first);
-      write_element_end();
-      write_element_start("value");
-      write_const_value(mit->second);
-      write_element_end();
-      write_element_end();
-    }
-    write_element_end();
-    break;
-  }
-
-  default:
-    indent_up();
-    f_xml_ << indent() << "<null />" << endl;
-    indent_down();
-    break;
-  }
-
-}
-
-void t_xml_generator::generate_enum(t_enum* tenum) {
-
-  write_element_start("enum");
-  write_attribute("name", tenum->get_name());
-  write_doc(tenum);
-
-  vector<t_enum_value*> values = tenum->get_constants();
-  vector<t_enum_value*>::iterator val_iter;
-  for (val_iter = values.begin(); val_iter != values.end(); ++val_iter) {
-    t_enum_value* val = (*val_iter);
-    write_element_start("member");
-    write_attribute("name", val->get_name());
-    write_int_attribute("value", val->get_value());
-    write_doc(val);
-    generate_annotations(val->annotations_);
-    write_element_end();
-  }
-
-  generate_annotations(tenum->annotations_);
-
-  write_element_end();
-
-}
-
-void t_xml_generator::generate_struct(t_struct* tstruct) {
-
-  string tagname = "struct";
-  if (tstruct->is_union()) {
-    tagname = "union";
-  } else if (tstruct->is_xception()) {
-    tagname = "exception";
-  }
-
-  write_element_start(tagname);
-  write_attribute("name", tstruct->get_name());
-  write_doc(tstruct);
-  vector<t_field*> members = tstruct->get_members();
-  vector<t_field*>::iterator mem_iter;
-  for (mem_iter = members.begin(); mem_iter != members.end(); mem_iter++) {
-    write_element_start("field");
-    generate_field(*mem_iter);
-    write_element_end();
-  }
-
-  generate_annotations(tstruct->annotations_);
- 
-  write_element_end();
-
-}
-
-void t_xml_generator::generate_field(t_field* field) {
-  write_attribute("name", field->get_name());
-  write_int_attribute("field-id", field->get_key());
-  write_doc(field); 
-  string requiredness;
-  switch (field->get_req()) {
-  case t_field::T_REQUIRED:
-    requiredness = "required";
-    break;
-  case t_field::T_OPTIONAL:
-    requiredness = "optional";
-    break;
-  default:
-    requiredness = "";
-    break;
-  }
-  if (requiredness != "") {
-    write_attribute("required", requiredness);
-  }
-  write_type(field->get_type());
-  if (field->get_value()) {
-    write_element_start("default");
-    write_const_value(field->get_value());
-    write_element_end();
-  }
-  generate_annotations(field->annotations_);
-}
-
-void t_xml_generator::generate_service(t_service* tservice) {
- 
-  write_element_start("service");
-  write_attribute("name", tservice->get_name());
-
-  if (should_use_namespaces_) {
-    string prog_ns = target_namespace(tservice->get_program());
-    if (*prog_ns.rbegin() != '/') {
-      prog_ns.push_back('/');
-    }
-    const string tns = prog_ns + tservice->get_name();
-    write_attribute("targetNamespace", tns);
-    write_attribute("xmlns:tns", tns);
-  }
- 
-  if (tservice->get_extends()) {
-    const t_service* extends = tservice->get_extends();
-    write_attribute("parent-module", extends->get_program()->get_name());
-    write_attribute("parent-id", extends->get_name());
-  }
-
-  write_doc(tservice);
-
-  vector<t_function*> functions = tservice->get_functions();
-  vector<t_function*>::iterator fn_iter = functions.begin();
-  for (; fn_iter != functions.end(); fn_iter++) {
-    generate_function(*fn_iter);
-  }
-  
-  generate_annotations(tservice->annotations_);
-  
-  write_element_end();
-
-}
-
-void t_xml_generator::generate_function(t_function* tfunc) {
- 
-  write_element_start("method");
-
-  write_attribute("name", tfunc->get_name());
-  if (tfunc->is_oneway()) {
-    write_attribute("oneway", "true");
-  }
-
-  write_doc(tfunc);
-
-  write_element_start("returns");
-  write_type(tfunc->get_returntype());
-  write_element_end();
-
-  vector<t_field*> members = tfunc->get_arglist()->get_members();
-  vector<t_field*>::iterator mem_iter = members.begin();
-  for (; mem_iter != members.end(); mem_iter++) {
-    write_element_start("arg");
-    generate_field(*mem_iter);
-    write_element_end();
-  }
- 
-  vector<t_field*> excepts = tfunc->get_xceptions()->get_members();
-  vector<t_field*>::iterator ex_iter = excepts.begin();
-  for (; ex_iter != excepts.end(); ex_iter++) {
-    write_element_start("throws");
-    generate_field(*ex_iter);
-    write_element_end();
-  }
-
-  generate_annotations(tfunc->annotations_);
-  
-  write_element_end();
-
-}
-
-string t_xml_generator::get_type_name(t_type* ttype) {
-  if (ttype->is_list()) {
-    return "list";
-  }
-  if (ttype->is_set()) {
-    return "set";
-  }
-  if (ttype->is_map()) {
-    return "map";
-  }
-  if ((ttype->is_enum()    )|| 
-      (ttype->is_struct()  )|| 
-      (ttype->is_typedef() )|| 
-      (ttype->is_xception())){
-    return "id";
-  }
-  if (ttype->is_base_type()) {
-    t_base_type* tbasetype = (t_base_type*)ttype;
-    if (tbasetype->is_binary() ) {
-      return "binary";
-    }
-    return t_base_type::t_base_name(tbasetype->get_base());
-  }
-  return "(unknown)";
-}
-
-THRIFT_REGISTER_GENERATOR(
-  xml,
-  "XML",
-  "    merge:           Generate output with included files merged\n"
-  "    no_default_ns:   Omit default xmlns and add idl: prefix to all elements\n"
-  "    no_namespaces:   Do not add namespace definitions to the XML model\n")

http://git-wip-us.apache.org/repos/asf/thrift/blob/052abc39/compiler/cpp/src/generate/t_xsd_generator.cc
----------------------------------------------------------------------
diff --git a/compiler/cpp/src/generate/t_xsd_generator.cc b/compiler/cpp/src/generate/t_xsd_generator.cc
deleted file mode 100644
index 2de860a..0000000
--- a/compiler/cpp/src/generate/t_xsd_generator.cc
+++ /dev/null
@@ -1,376 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-#include <fstream>
-#include <iostream>
-#include <sstream>
-
-#include <stdlib.h>
-#include <sys/stat.h>
-#include <sstream>
-#include "t_generator.h"
-#include "version.h"
-#include "platform.h"
-
-using std::map;
-using std::ofstream;
-using std::ostream;
-using std::ostringstream;
-using std::string;
-using std::stringstream;
-using std::vector;
-
-static const string endl = "\n"; // avoid ostream << std::endl flushes
-
-/**
- * XSD generator, creates an XSD for the base types etc.
- *
- */
-class t_xsd_generator : public t_generator {
-public:
-  t_xsd_generator(t_program* program,
-                  const std::map<std::string, std::string>& parsed_options,
-                  const std::string& option_string)
-    : t_generator(program) {
-    (void)option_string;
-    std::map<std::string, std::string>::const_iterator iter;
-
-    /* no options yet */
-    for( iter = parsed_options.begin(); iter != parsed_options.end(); ++iter) {
-      throw "unknown option xsd:" + iter->first; 
-    }
-
-    out_dir_base_ = "gen-xsd";
-  }
-
-  virtual ~t_xsd_generator() {}
-
-  /**
-   * Init and close methods
-   */
-
-  void init_generator();
-  void close_generator();
-
-  /**
-   * Program-level generation functions
-   */
-
-  void generate_typedef(t_typedef* ttypedef);
-  void generate_enum(t_enum* tenum) { (void)tenum; }
-
-  void generate_service(t_service* tservice);
-  void generate_struct(t_struct* tstruct);
-
-private:
-  void generate_element(std::ostream& out,
-                        std::string name,
-                        t_type* ttype,
-                        t_struct* attrs = NULL,
-                        bool optional = false,
-                        bool nillable = false,
-                        bool list_element = false);
-
-  std::string ns(std::string in, std::string ns) { return ns + ":" + in; }
-
-  std::string xsd(std::string in) { return ns(in, "xsd"); }
-
-  std::string type_name(t_type* ttype);
-  std::string base_type_name(t_base_type::t_base tbase);
-
-  virtual std::string xml_autogen_comment() {
-    return std::string("<!--\n") + " * Autogenerated by Thrift Compiler (" + THRIFT_VERSION + ")\n"
-           + " *\n" + " * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING\n"
-           + " -->\n";
-  }
-
-  /**
-   * Output xsd/php file
-   */
-  std::ofstream f_xsd_;
-  std::ofstream f_php_;
-
-  /**
-   * Output string stream
-   */
-  std::ostringstream s_xsd_types_;
-};
-
-void t_xsd_generator::init_generator() {
-  // Make output directory
-  MKDIR(get_out_dir().c_str());
-
-  // Make output file
-  string f_php_name = get_out_dir() + program_->get_name() + "_xsd.php";
-  f_php_.open(f_php_name.c_str());
-
-  f_php_ << "<?php" << endl
-         << autogen_comment() << endl;
-}
-
-void t_xsd_generator::close_generator() {
-  f_php_ << "?>" << endl;
-  f_php_.close();
-}
-
-void t_xsd_generator::generate_typedef(t_typedef* ttypedef) {
-  indent(s_xsd_types_) << "<xsd:simpleType name=\"" << ttypedef->get_name() << "\">" << endl;
-  indent_up();
-  if (ttypedef->get_type()->is_string() && ((t_base_type*)ttypedef->get_type())->is_string_enum()) {
-    indent(s_xsd_types_) << "<xsd:restriction base=\"" << type_name(ttypedef->get_type()) << "\">"
-                         << endl;
-    indent_up();
-    const vector<string>& values = ((t_base_type*)ttypedef->get_type())->get_string_enum_vals();
-    vector<string>::const_iterator v_iter;
-    for (v_iter = values.begin(); v_iter != values.end(); ++v_iter) {
-      indent(s_xsd_types_) << "<xsd:enumeration value=\"" << (*v_iter) << "\" />" << endl;
-    }
-    indent_down();
-    indent(s_xsd_types_) << "</xsd:restriction>" << endl;
-  } else {
-    indent(s_xsd_types_) << "<xsd:restriction base=\"" << type_name(ttypedef->get_type()) << "\" />"
-                         << endl;
-  }
-  indent_down();
-  indent(s_xsd_types_) << "</xsd:simpleType>" << endl << endl;
-}
-
-void t_xsd_generator::generate_struct(t_struct* tstruct) {
-  vector<t_field*>::const_iterator m_iter;
-  const vector<t_field*>& members = tstruct->get_members();
-  bool xsd_all = tstruct->get_xsd_all();
-
-  indent(s_xsd_types_) << "<xsd:complexType name=\"" << tstruct->get_name() << "\">" << endl;
-  indent_up();
-  if (xsd_all) {
-    indent(s_xsd_types_) << "<xsd:all>" << endl;
-  } else {
-    indent(s_xsd_types_) << "<xsd:sequence>" << endl;
-  }
-  indent_up();
-
-  for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
-    generate_element(s_xsd_types_,
-                     (*m_iter)->get_name(),
-                     (*m_iter)->get_type(),
-                     (*m_iter)->get_xsd_attrs(),
-                     (*m_iter)->get_xsd_optional() || xsd_all,
-                     (*m_iter)->get_xsd_nillable());
-  }
-
-  indent_down();
-  if (xsd_all) {
-    indent(s_xsd_types_) << "</xsd:all>" << endl;
-  } else {
-    indent(s_xsd_types_) << "</xsd:sequence>" << endl;
-  }
-  indent_down();
-  indent(s_xsd_types_) << "</xsd:complexType>" << endl << endl;
-}
-
-void t_xsd_generator::generate_element(ostream& out,
-                                       string name,
-                                       t_type* ttype,
-                                       t_struct* attrs,
-                                       bool optional,
-                                       bool nillable,
-                                       bool list_element) {
-  string sminOccurs = (optional || list_element) ? " minOccurs=\"0\"" : "";
-  string smaxOccurs = list_element ? " maxOccurs=\"unbounded\"" : "";
-  string soptional = sminOccurs + smaxOccurs;
-  string snillable = nillable ? " nillable=\"true\"" : "";
-
-  if (ttype->is_void() || ttype->is_list()) {
-    indent(out) << "<xsd:element name=\"" << name << "\"" << soptional << snillable << ">" << endl;
-    indent_up();
-    if (attrs == NULL && ttype->is_void()) {
-      indent(out) << "<xsd:complexType />" << endl;
-    } else {
-      indent(out) << "<xsd:complexType>" << endl;
-      indent_up();
-      if (ttype->is_list()) {
-        indent(out) << "<xsd:sequence minOccurs=\"0\" maxOccurs=\"unbounded\">" << endl;
-        indent_up();
-        string subname;
-        t_type* subtype = ((t_list*)ttype)->get_elem_type();
-        if (subtype->is_base_type() || subtype->is_container()) {
-          subname = name + "_elt";
-        } else {
-          subname = type_name(subtype);
-        }
-        f_php_ << "$GLOBALS['" << program_->get_name() << "_xsd_elt_" << name << "'] = '" << subname
-               << "';" << endl;
-        generate_element(out, subname, subtype, NULL, false, false, true);
-        indent_down();
-        indent(out) << "</xsd:sequence>" << endl;
-        indent(out) << "<xsd:attribute name=\"list\" type=\"xsd:boolean\" />" << endl;
-      }
-      if (attrs != NULL) {
-        const vector<t_field*>& members = attrs->get_members();
-        vector<t_field*>::const_iterator a_iter;
-        for (a_iter = members.begin(); a_iter != members.end(); ++a_iter) {
-          indent(out) << "<xsd:attribute name=\"" << (*a_iter)->get_name() << "\" type=\""
-                      << type_name((*a_iter)->get_type()) << "\" />" << endl;
-        }
-      }
-      indent_down();
-      indent(out) << "</xsd:complexType>" << endl;
-    }
-    indent_down();
-    indent(out) << "</xsd:element>" << endl;
-  } else {
-    if (attrs == NULL) {
-      indent(out) << "<xsd:element name=\"" << name << "\""
-                  << " type=\"" << type_name(ttype) << "\"" << soptional << snillable << " />"
-                  << endl;
-    } else {
-      // Wow, all this work for a SIMPLE TYPE with attributes?!?!?!
-      indent(out) << "<xsd:element name=\"" << name << "\"" << soptional << snillable << ">"
-                  << endl;
-      indent_up();
-      indent(out) << "<xsd:complexType>" << endl;
-      indent_up();
-      indent(out) << "<xsd:complexContent>" << endl;
-      indent_up();
-      indent(out) << "<xsd:extension base=\"" << type_name(ttype) << "\">" << endl;
-      indent_up();
-      const vector<t_field*>& members = attrs->get_members();
-      vector<t_field*>::const_iterator a_iter;
-      for (a_iter = members.begin(); a_iter != members.end(); ++a_iter) {
-        indent(out) << "<xsd:attribute name=\"" << (*a_iter)->get_name() << "\" type=\""
-                    << type_name((*a_iter)->get_type()) << "\" />" << endl;
-      }
-      indent_down();
-      indent(out) << "</xsd:extension>" << endl;
-      indent_down();
-      indent(out) << "</xsd:complexContent>" << endl;
-      indent_down();
-      indent(out) << "</xsd:complexType>" << endl;
-      indent_down();
-      indent(out) << "</xsd:element>" << endl;
-    }
-  }
-}
-
-
-void t_xsd_generator::generate_service(t_service* tservice) {
-  // Make output file
-  string f_xsd_name = get_out_dir() + tservice->get_name() + ".xsd";
-  f_xsd_.open(f_xsd_name.c_str());
-
-  string ns = program_->get_namespace("xsd");
-  const std::map<std::string, std::string> annot = program_->get_namespace_annotations("xsd");
-  const std::map<std::string, std::string>::const_iterator uri = annot.find("uri");
-  if (uri != annot.end()) {
-    ns = uri->second;
-  }
-  if (ns.size() > 0) {
-    ns = " targetNamespace=\"" + ns + "\" xmlns=\"" + ns + "\" "
-         + "elementFormDefault=\"qualified\"";
-  }
-
-  // Print the XSD header
-  f_xsd_ << "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" << endl
-         << "<xsd:schema xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"" << ns << ">" << endl
-         << xml_autogen_comment()
-         << endl;
-
-  // Print out the type definitions
-  indent(f_xsd_) << s_xsd_types_.str();
-
-  // Keep a list of all the possible exceptions that might get thrown
-  map<string, t_struct*> all_xceptions;
-
-  // List the elements that you might actually get
-  vector<t_function*> functions = tservice->get_functions();
-  vector<t_function*>::iterator f_iter;
-  for (f_iter = functions.begin(); f_iter != functions.end(); ++f_iter) {
-    string elemname = (*f_iter)->get_name() + "_response";
-    t_type* returntype = (*f_iter)->get_returntype();
-    generate_element(f_xsd_, elemname, returntype);
-    f_xsd_ << endl;
-
-    t_struct* xs = (*f_iter)->get_xceptions();
-    const std::vector<t_field*>& xceptions = xs->get_members();
-    vector<t_field*>::const_iterator x_iter;
-    for (x_iter = xceptions.begin(); x_iter != xceptions.end(); ++x_iter) {
-      all_xceptions[(*x_iter)->get_name()] = (t_struct*)((*x_iter)->get_type());
-    }
-  }
-
-  map<string, t_struct*>::iterator ax_iter;
-  for (ax_iter = all_xceptions.begin(); ax_iter != all_xceptions.end(); ++ax_iter) {
-    generate_element(f_xsd_, ax_iter->first, ax_iter->second);
-  }
-
-  // Close the XSD document
-  f_xsd_ << endl << "</xsd:schema>" << endl;
-  f_xsd_.close();
-}
-
-string t_xsd_generator::type_name(t_type* ttype) {
-  if (ttype->is_typedef()) {
-    return ttype->get_name();
-  }
-
-  if (ttype->is_base_type()) {
-    return xsd(base_type_name(((t_base_type*)ttype)->get_base()));
-  }
-
-  if (ttype->is_enum()) {
-    return xsd("int");
-  }
-
-  if (ttype->is_struct() || ttype->is_xception()) {
-    return ttype->get_name();
-  }
-
-  return "container";
-}
-
-/**
- * Returns the XSD type that corresponds to the thrift type.
- *
- * @param tbase The base type
- * @return Explicit XSD type, i.e. xsd:string
- */
-string t_xsd_generator::base_type_name(t_base_type::t_base tbase) {
-  switch (tbase) {
-  case t_base_type::TYPE_VOID:
-    return "void";
-  case t_base_type::TYPE_STRING:
-    return "string";
-  case t_base_type::TYPE_BOOL:
-    return "boolean";
-  case t_base_type::TYPE_I8:
-    return "byte";
-  case t_base_type::TYPE_I16:
-    return "short";
-  case t_base_type::TYPE_I32:
-    return "int";
-  case t_base_type::TYPE_I64:
-    return "long";
-  case t_base_type::TYPE_DOUBLE:
-    return "decimal";
-  default:
-    throw "compiler error: no XSD base type name for base type " + t_base_type::t_base_name(tbase);
-  }
-}
-
-THRIFT_REGISTER_GENERATOR(xsd, "XSD", "")

http://git-wip-us.apache.org/repos/asf/thrift/blob/052abc39/compiler/cpp/src/globals.h
----------------------------------------------------------------------
diff --git a/compiler/cpp/src/globals.h b/compiler/cpp/src/globals.h
deleted file mode 100644
index 961c6ef..0000000
--- a/compiler/cpp/src/globals.h
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-#ifndef T_GLOBALS_H
-#define T_GLOBALS_H
-
-#include <set>
-#include <queue>
-#include <stack>
-#include <vector>
-#include <string>
-
-/**
- * This module contains all the global variables (slap on the wrist) that are
- * shared throughout the program. The reason for this is to facilitate simple
- * interaction between the parser and the rest of the program. Before calling
- * yyparse(), the main.cc program will make necessary adjustments to these
- * global variables such that the parser does the right thing and puts entries
- * into the right containers, etc.
- *
- */
-
-/**
- * Hooray for forward declaration of types!
- */
-
-class t_program;
-class t_scope;
-class t_type;
-
-/**
- * Parsing mode, two passes up in this gin rummy!
- */
-
-enum PARSE_MODE { INCLUDES = 1, PROGRAM = 2 };
-
-/**
- * Strictness level
- */
-extern int g_strict;
-
-/**
- * The master program parse tree. This is accessed from within the parser code
- * to build up the program elements.
- */
-extern t_program* g_program;
-
-/**
- * The scope that we are currently parsing into
- */
-extern t_scope* g_scope;
-
-/**
- * The parent scope to also load symbols into
- */
-extern t_scope* g_parent_scope;
-
-/**
- * The prefix for the parent scope entries
- */
-extern std::string g_parent_prefix;
-
-/**
- * The parsing pass that we are on. We do different things on each pass.
- */
-extern PARSE_MODE g_parse_mode;
-
-/**
- * Global time string, used in formatting error messages etc.
- */
-extern char* g_time_str;
-
-/**
- * The last parsed doctext comment.
- */
-extern char* g_doctext;
-
-/**
- * The location of the last parsed doctext comment.
- */
-extern int g_doctext_lineno;
-
-/**
- * Status of program level doctext candidate
- */
-enum PROGDOCTEXT_STATUS {
-  INVALID = 0,
-  STILL_CANDIDATE = 1,   // the text may or may not be the program doctext
-  ALREADY_PROCESSED = 2, // doctext has been used and is no longer available
-  ABSOLUTELY_SURE = 3,   // this is the program doctext
-  NO_PROGRAM_DOCTEXT = 4 // there is no program doctext
-};
-
-/**
- * The program level doctext. Stored separately to make parsing easier.
- */
-extern char* g_program_doctext_candidate;
-extern int g_program_doctext_lineno;
-extern PROGDOCTEXT_STATUS g_program_doctext_status;
-
-/**
- * Whether or not negative field keys are accepted.
- *
- * When a field does not have a user-specified key, thrift automatically
- * assigns a negative value.  However, this is fragile since changes to the
- * file may unintentionally change the key numbering, resulting in a new
- * protocol that is not backwards compatible.
- *
- * When g_allow_neg_field_keys is enabled, users can explicitly specify
- * negative keys.  This way they can write a .thrift file with explicitly
- * specified keys that is still backwards compatible with older .thrift files
- * that did not specify key values.
- */
-extern int g_allow_neg_field_keys;
-
-/**
- * Whether or not 64-bit constants will generate a warning.
- *
- * Some languages don't support 64-bit constants, but many do, so we can
- * suppress this warning for projects that don't use any non-64-bit-safe
- * languages.
- */
-extern int g_allow_64bit_consts;
-
-#endif

http://git-wip-us.apache.org/repos/asf/thrift/blob/052abc39/compiler/cpp/src/logging.cc
----------------------------------------------------------------------
diff --git a/compiler/cpp/src/logging.cc b/compiler/cpp/src/logging.cc
deleted file mode 100644
index 2daaaec..0000000
--- a/compiler/cpp/src/logging.cc
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-/**
- * Logging functions copied from main.cc to avoid link errors for plugins
- */
-
-#include "logging.h"
-#include "globals.h"
-#include <cstdarg>
-#include <cstdio>
-#include <cstdlib>
-
-// TODO: make plugins accept log options from main compiler
-int g_debug = 0;
-int g_warn = 1;
-int g_verbose = 0;
-
-void pdebug(const char* fmt, ...) {
-  if (g_debug == 0) {
-    return;
-  }
-  va_list args;
-  // printf("[PARSE:%d] ", yylineno);
-  va_start(args, fmt);
-  vprintf(fmt, args);
-  va_end(args);
-  printf("\n");
-}
-
-void pverbose(const char* fmt, ...) {
-  if (g_verbose == 0) {
-    return;
-  }
-  va_list args;
-  va_start(args, fmt);
-  vprintf(fmt, args);
-  va_end(args);
-}
-
-void pwarning(int level, const char* fmt, ...) {
-  if (g_warn < level) {
-    return;
-  }
-  va_list args;
-  // printf("[WARNING:%s:%d] ", g_curpath.c_str(), yylineno);
-  va_start(args, fmt);
-  vprintf(fmt, args);
-  va_end(args);
-  printf("\n");
-}
-
-void failure(const char* fmt, ...) {
-  va_list args;
-  // fprintf(stderr, "[FAILURE:%s:%d] ", g_curpath.c_str(), yylineno);
-  va_start(args, fmt);
-  vfprintf(stderr, fmt, args);
-  va_end(args);
-  printf("\n");
-  exit(1);
-}

http://git-wip-us.apache.org/repos/asf/thrift/blob/052abc39/compiler/cpp/src/logging.h
----------------------------------------------------------------------
diff --git a/compiler/cpp/src/logging.h b/compiler/cpp/src/logging.h
deleted file mode 100644
index ebefbf2..0000000
--- a/compiler/cpp/src/logging.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-#ifndef T_LOGGING_H
-#define T_LOGGING_H
-
-extern int g_debug;
-extern int g_warn;
-extern int g_verbose;
-
-/**
- * Parse debugging output, used to print helpful info
- */
-void pdebug(const char* fmt, ...);
-
-/**
- * Parser warning
- */
-void pwarning(int level, const char* fmt, ...);
-
-/**
- * Print verbose output message
- */
-void pverbose(const char* fmt, ...);
-
-/**
- * Failure!
- */
-void failure(const char* fmt, ...);
-
-#endif

http://git-wip-us.apache.org/repos/asf/thrift/blob/052abc39/compiler/cpp/src/main.cc
----------------------------------------------------------------------
diff --git a/compiler/cpp/src/main.cc b/compiler/cpp/src/main.cc
deleted file mode 100644
index 510d69f..0000000
--- a/compiler/cpp/src/main.cc
+++ /dev/null
@@ -1,1307 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-/**
- * thrift - a lightweight cross-language rpc/serialization tool
- *
- * This file contains the main compiler engine for Thrift, which invokes the
- * scanner/parser to build the thrift object tree. The interface generation
- * code for each language lives in a file by the language name under the
- * generate/ folder, and all parse structures live in parse/
- *
- */
-
-#include <cassert>
-#include <stdlib.h>
-#include <stdio.h>
-#include <stdarg.h>
-#include <time.h>
-#include <string>
-#include <algorithm>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <errno.h>
-#include <limits.h>
-
-#ifdef _WIN32
-#include <windows.h> /* for GetFullPathName */
-#endif
-
-// Careful: must include globals first for extern definitions
-#include "common.h"
-#include "globals.h"
-
-#include "platform.h"
-#include "main.h"
-#include "parse/t_program.h"
-#include "parse/t_scope.h"
-#include "generate/t_generator.h"
-#include "audit/t_audit.h"
-#ifdef THRIFT_ENABLE_PLUGIN
-#include "plugin/plugin_output.h"
-#endif
-
-#include "version.h"
-
-using namespace std;
-
-/**
- * Global program tree
- */
-t_program* g_program;
-
-/**
- * Global scope
- */
-t_scope* g_scope;
-
-/**
- * Parent scope to also parse types
- */
-t_scope* g_parent_scope;
-
-/**
- * Prefix for putting types in parent scope
- */
-string g_parent_prefix;
-
-/**
- * Parsing pass
- */
-PARSE_MODE g_parse_mode;
-
-/**
- * Current directory of file being parsed
- */
-string g_curdir;
-
-/**
- * Current file being parsed
- */
-string g_curpath;
-
-/**
- * Search path for inclusions
- */
-vector<string> g_incl_searchpath;
-
-/**
- * Global debug state
- */
-int g_debug = 0;
-
-/**
- * Strictness level
- */
-int g_strict = 127;
-
-/**
- * Warning level
- */
-int g_warn = 1;
-
-/**
- * Verbose output
- */
-int g_verbose = 0;
-
-/**
- * Global time string
- */
-char* g_time_str;
-
-/**
- * The last parsed doctext comment.
- */
-char* g_doctext;
-
-/**
- * The First doctext comment
- */
-char* g_program_doctext_candidate;
-
-/**
- * Whether or not negative field keys are accepted.
- */
-int g_allow_neg_field_keys;
-
-/**
- * Whether or not 64-bit constants will generate a warning.
- */
-int g_allow_64bit_consts = 0;
-
-/**
- * Flags to control code generation
- */
-bool gen_recurse = false;
-
-/**
- * Flags to control thrift audit
- */
-bool g_audit = false;
-
-/**
- * Flag to control return status
- */
-bool g_return_failure = false;
-bool g_audit_fatal = true;
-bool g_generator_failure = false;
-
-/**
- * Win32 doesn't have realpath, so use fallback implementation in that case,
- * otherwise this just calls through to realpath
- */
-char* saferealpath(const char* path, char* resolved_path) {
-#ifdef _WIN32
-  char buf[MAX_PATH];
-  char* basename;
-  DWORD len = GetFullPathName(path, MAX_PATH, buf, &basename);
-  if (len == 0 || len > MAX_PATH - 1) {
-    strcpy(resolved_path, path);
-  } else {
-    strcpy(resolved_path, buf);
-  }
-
-  // Replace backslashes with forward slashes so the
-  // rest of the code behaves correctly.
-  size_t resolved_len = strlen(resolved_path);
-  for (size_t i = 0; i < resolved_len; i++) {
-    if (resolved_path[i] == '\\') {
-      resolved_path[i] = '/';
-    }
-  }
-  return resolved_path;
-#else
-  return realpath(path, resolved_path);
-#endif
-}
-
-bool check_is_directory(const char* dir_name) {
-#ifdef _WIN32
-  DWORD attributes = ::GetFileAttributesA(dir_name);
-  if (attributes == INVALID_FILE_ATTRIBUTES) {
-    fprintf(stderr,
-            "Output directory %s is unusable: GetLastError() = %ld\n",
-            dir_name,
-            GetLastError());
-    return false;
-  }
-  if ((attributes & FILE_ATTRIBUTE_DIRECTORY) != FILE_ATTRIBUTE_DIRECTORY) {
-    fprintf(stderr, "Output directory %s exists but is not a directory\n", dir_name);
-    return false;
-  }
-  return true;
-#else
-  struct stat sb;
-  if (stat(dir_name, &sb) < 0) {
-    fprintf(stderr, "Output directory %s is unusable: %s\n", dir_name, strerror(errno));
-    return false;
-  }
-  if (!S_ISDIR(sb.st_mode)) {
-    fprintf(stderr, "Output directory %s exists but is not a directory\n", dir_name);
-    return false;
-  }
-  return true;
-#endif
-}
-
-/**
- * Report an error to the user. This is called yyerror for historical
- * reasons (lex and yacc expect the error reporting routine to be called
- * this). Call this function to report any errors to the user.
- * yyerror takes printf style arguments.
- *
- * @param fmt C format string followed by additional arguments
- */
-void yyerror(const char* fmt, ...) {
-  va_list args;
-  fprintf(stderr, "[ERROR:%s:%d] (last token was '%s')\n", g_curpath.c_str(), yylineno, yytext);
-
-  va_start(args, fmt);
-  vfprintf(stderr, fmt, args);
-  va_end(args);
-
-  fprintf(stderr, "\n");
-}
-
-/**
- * Prints a debug message from the parser.
- *
- * @param fmt C format string followed by additional arguments
- */
-void pdebug(const char* fmt, ...) {
-  if (g_debug == 0) {
-    return;
-  }
-  va_list args;
-  printf("[PARSE:%d] ", yylineno);
-  va_start(args, fmt);
-  vprintf(fmt, args);
-  va_end(args);
-  printf("\n");
-}
-
-/**
- * Prints a verbose output mode message
- *
- * @param fmt C format string followed by additional arguments
- */
-void pverbose(const char* fmt, ...) {
-  if (g_verbose == 0) {
-    return;
-  }
-  va_list args;
-  va_start(args, fmt);
-  vprintf(fmt, args);
-  va_end(args);
-}
-
-/**
- * Prints a warning message
- *
- * @param fmt C format string followed by additional arguments
- */
-void pwarning(int level, const char* fmt, ...) {
-  if (g_warn < level) {
-    return;
-  }
-  va_list args;
-  printf("[WARNING:%s:%d] ", g_curpath.c_str(), yylineno);
-  va_start(args, fmt);
-  vprintf(fmt, args);
-  va_end(args);
-  printf("\n");
-}
-
-/**
- * Prints a failure message and exits
- *
- * @param fmt C format string followed by additional arguments
- */
-void failure(const char* fmt, ...) {
-  va_list args;
-  fprintf(stderr, "[FAILURE:%s:%d] ", g_curpath.c_str(), yylineno);
-  va_start(args, fmt);
-  vfprintf(stderr, fmt, args);
-  va_end(args);
-  printf("\n");
-  exit(1);
-}
-
-/**
- * Converts a string filename into a thrift program name
- */
-string program_name(string filename) {
-  string::size_type slash = filename.rfind("/");
-  if (slash != string::npos) {
-    filename = filename.substr(slash + 1);
-  }
-  string::size_type dot = filename.rfind(".");
-  if (dot != string::npos) {
-    filename = filename.substr(0, dot);
-  }
-  return filename;
-}
-
-/**
- * Gets the directory path of a filename
- */
-string directory_name(string filename) {
-  string::size_type slash = filename.rfind("/");
-  // No slash, just use the current directory
-  if (slash == string::npos) {
-    return ".";
-  }
-  return filename.substr(0, slash);
-}
-
-/**
- * Finds the appropriate file path for the given filename
- */
-string include_file(string filename) {
-  // Absolute path? Just try that
-  if (filename[0] == '/') {
-    // Realpath!
-    char rp[THRIFT_PATH_MAX];
-    // cppcheck-suppress uninitvar
-    if (saferealpath(filename.c_str(), rp) == NULL) {
-      pwarning(0, "Cannot open include file %s\n", filename.c_str());
-      return std::string();
-    }
-
-    // Stat this file
-    struct stat finfo;
-    if (stat(rp, &finfo) == 0) {
-      return rp;
-    }
-  } else { // relative path, start searching
-    // new search path with current dir global
-    vector<string> sp = g_incl_searchpath;
-    sp.insert(sp.begin(), g_curdir);
-
-    // iterate through paths
-    vector<string>::iterator it;
-    for (it = sp.begin(); it != sp.end(); it++) {
-      string sfilename = *(it) + "/" + filename;
-
-      // Realpath!
-      char rp[THRIFT_PATH_MAX];
-      // cppcheck-suppress uninitvar
-      if (saferealpath(sfilename.c_str(), rp) == NULL) {
-        continue;
-      }
-
-      // Stat this files
-      struct stat finfo;
-      if (stat(rp, &finfo) == 0) {
-        return rp;
-      }
-    }
-  }
-
-  // Uh oh
-  pwarning(0, "Could not find include file %s\n", filename.c_str());
-  return std::string();
-}
-
-/**
- * Clears any previously stored doctext string.
- * Also prints a warning if we are discarding information.
- */
-void clear_doctext() {
-  if (g_doctext != NULL) {
-    pwarning(2, "Uncaptured doctext at on line %d.", g_doctext_lineno);
-  }
-  free(g_doctext);
-  g_doctext = NULL;
-}
-
-/**
- * Reset program doctext information after processing a file
- */
-void reset_program_doctext_info() {
-  if (g_program_doctext_candidate != NULL) {
-    free(g_program_doctext_candidate);
-    g_program_doctext_candidate = NULL;
-  }
-  g_program_doctext_lineno = 0;
-  g_program_doctext_status = INVALID;
-  pdebug("%s", "program doctext set to INVALID");
-}
-
-/**
- * We are sure the program doctext candidate is really the program doctext.
- */
-void declare_valid_program_doctext() {
-  if ((g_program_doctext_candidate != NULL) && (g_program_doctext_status == STILL_CANDIDATE)) {
-    g_program_doctext_status = ABSOLUTELY_SURE;
-    pdebug("%s", "program doctext set to ABSOLUTELY_SURE");
-  } else {
-    g_program_doctext_status = NO_PROGRAM_DOCTEXT;
-    pdebug("%s", "program doctext set to NO_PROGRAM_DOCTEXT");
-  }
-}
-
-/**
- * Cleans up text commonly found in doxygen-like comments
- *
- * Warning: if you mix tabs and spaces in a non-uniform way,
- * you will get what you deserve.
- */
-char* clean_up_doctext(char* doctext) {
-  // Convert to C++ string, and remove Windows's carriage returns.
-  string docstring = doctext;
-  docstring.erase(remove(docstring.begin(), docstring.end(), '\r'), docstring.end());
-
-  // Separate into lines.
-  vector<string> lines;
-  string::size_type pos = string::npos;
-  string::size_type last;
-  while (true) {
-    last = (pos == string::npos) ? 0 : pos + 1;
-    pos = docstring.find('\n', last);
-    if (pos == string::npos) {
-      // First bit of cleaning.  If the last line is only whitespace, drop it.
-      string::size_type nonwhite = docstring.find_first_not_of(" \t", last);
-      if (nonwhite != string::npos) {
-        lines.push_back(docstring.substr(last));
-      }
-      break;
-    }
-    lines.push_back(docstring.substr(last, pos - last));
-  }
-
-  // A very profound docstring.
-  if (lines.empty()) {
-    return NULL;
-  }
-
-  // Clear leading whitespace from the first line.
-  pos = lines.front().find_first_not_of(" \t");
-  lines.front().erase(0, pos);
-
-  // If every nonblank line after the first has the same number of spaces/tabs,
-  // then a star, remove them.
-  bool have_prefix = true;
-  bool found_prefix = false;
-  string::size_type prefix_len = 0;
-  vector<string>::iterator l_iter;
-  for (l_iter = lines.begin() + 1; l_iter != lines.end(); ++l_iter) {
-    if (l_iter->empty()) {
-      continue;
-    }
-
-    pos = l_iter->find_first_not_of(" \t");
-    if (!found_prefix) {
-      if (pos != string::npos) {
-        if (l_iter->at(pos) == '*') {
-          found_prefix = true;
-          prefix_len = pos;
-        } else {
-          have_prefix = false;
-          break;
-        }
-      } else {
-        // Whitespace-only line.  Truncate it.
-        l_iter->clear();
-      }
-    } else if (l_iter->size() > pos && l_iter->at(pos) == '*' && pos == prefix_len) {
-      // Business as usual.
-    } else if (pos == string::npos) {
-      // Whitespace-only line.  Let's truncate it for them.
-      l_iter->clear();
-    } else {
-      // The pattern has been broken.
-      have_prefix = false;
-      break;
-    }
-  }
-
-  // If our prefix survived, delete it from every line.
-  if (have_prefix) {
-    // Get the star too.
-    prefix_len++;
-    for (l_iter = lines.begin() + 1; l_iter != lines.end(); ++l_iter) {
-      l_iter->erase(0, prefix_len);
-    }
-  }
-
-  // Now delete the minimum amount of leading whitespace from each line.
-  prefix_len = string::npos;
-  for (l_iter = lines.begin() + 1; l_iter != lines.end(); ++l_iter) {
-    if (l_iter->empty()) {
-      continue;
-    }
-    pos = l_iter->find_first_not_of(" \t");
-    if (pos != string::npos && (prefix_len == string::npos || pos < prefix_len)) {
-      prefix_len = pos;
-    }
-  }
-
-  // If our prefix survived, delete it from every line.
-  if (prefix_len != string::npos) {
-    for (l_iter = lines.begin() + 1; l_iter != lines.end(); ++l_iter) {
-      l_iter->erase(0, prefix_len);
-    }
-  }
-
-  // Remove trailing whitespace from every line.
-  for (l_iter = lines.begin(); l_iter != lines.end(); ++l_iter) {
-    pos = l_iter->find_last_not_of(" \t");
-    if (pos != string::npos && pos != l_iter->length() - 1) {
-      l_iter->erase(pos + 1);
-    }
-  }
-
-  // If the first line is empty, remove it.
-  // Don't do this earlier because a lot of steps skip the first line.
-  if (lines.front().empty()) {
-    lines.erase(lines.begin());
-  }
-
-  // Now rejoin the lines and copy them back into doctext.
-  docstring.clear();
-  for (l_iter = lines.begin(); l_iter != lines.end(); ++l_iter) {
-    docstring += *l_iter;
-    docstring += '\n';
-  }
-
-  // assert(docstring.length() <= strlen(doctext));  may happen, see THRIFT-1755
-  if (docstring.length() <= strlen(doctext)) {
-    strcpy(doctext, docstring.c_str());
-  } else {
-    free(doctext); // too short
-    doctext = strdup(docstring.c_str());
-  }
-  return doctext;
-}
-
-/** Set to true to debug docstring parsing */
-static bool dump_docs = false;
-
-/**
- * Dumps docstrings to stdout
- * Only works for top-level definitions and the whole program doc
- * (i.e., not enum constants, struct fields, or functions.
- */
-void dump_docstrings(t_program* program) {
-  string progdoc = program->get_doc();
-  if (!progdoc.empty()) {
-    printf("Whole program doc:\n%s\n", progdoc.c_str());
-  }
-  const vector<t_typedef*>& typedefs = program->get_typedefs();
-  vector<t_typedef*>::const_iterator t_iter;
-  for (t_iter = typedefs.begin(); t_iter != typedefs.end(); ++t_iter) {
-    t_typedef* td = *t_iter;
-    if (td->has_doc()) {
-      printf("typedef %s:\n%s\n", td->get_name().c_str(), td->get_doc().c_str());
-    }
-  }
-  const vector<t_enum*>& enums = program->get_enums();
-  vector<t_enum*>::const_iterator e_iter;
-  for (e_iter = enums.begin(); e_iter != enums.end(); ++e_iter) {
-    t_enum* en = *e_iter;
-    if (en->has_doc()) {
-      printf("enum %s:\n%s\n", en->get_name().c_str(), en->get_doc().c_str());
-    }
-  }
-  const vector<t_const*>& consts = program->get_consts();
-  vector<t_const*>::const_iterator c_iter;
-  for (c_iter = consts.begin(); c_iter != consts.end(); ++c_iter) {
-    t_const* co = *c_iter;
-    if (co->has_doc()) {
-      printf("const %s:\n%s\n", co->get_name().c_str(), co->get_doc().c_str());
-    }
-  }
-  const vector<t_struct*>& structs = program->get_structs();
-  vector<t_struct*>::const_iterator s_iter;
-  for (s_iter = structs.begin(); s_iter != structs.end(); ++s_iter) {
-    t_struct* st = *s_iter;
-    if (st->has_doc()) {
-      printf("struct %s:\n%s\n", st->get_name().c_str(), st->get_doc().c_str());
-    }
-  }
-  const vector<t_struct*>& xceptions = program->get_xceptions();
-  vector<t_struct*>::const_iterator x_iter;
-  for (x_iter = xceptions.begin(); x_iter != xceptions.end(); ++x_iter) {
-    t_struct* xn = *x_iter;
-    if (xn->has_doc()) {
-      printf("xception %s:\n%s\n", xn->get_name().c_str(), xn->get_doc().c_str());
-    }
-  }
-  const vector<t_service*>& services = program->get_services();
-  vector<t_service*>::const_iterator v_iter;
-  for (v_iter = services.begin(); v_iter != services.end(); ++v_iter) {
-    t_service* sv = *v_iter;
-    if (sv->has_doc()) {
-      printf("service %s:\n%s\n", sv->get_name().c_str(), sv->get_doc().c_str());
-    }
-  }
-}
-
-/**
- * Emits a warning on list<byte>, binary type is typically a much better choice.
- */
-void check_for_list_of_bytes(t_type* list_elem_type) {
-  if ((g_parse_mode == PROGRAM) && (list_elem_type != NULL) && list_elem_type->is_base_type()) {
-    t_base_type* tbase = (t_base_type*)list_elem_type;
-    if (tbase->get_base() == t_base_type::TYPE_I8) {
-      pwarning(1, "Consider using the more efficient \"binary\" type instead of \"list<byte>\".");
-    }
-  }
-}
-
-static bool g_byte_warning_emitted = false;
-
-/**
- * Emits a one-time warning on byte type, promoting the new i8 type instead
- */
-void emit_byte_type_warning() {
-  if (!g_byte_warning_emitted) {
-    pwarning(1,
-             "The \"byte\" type is a compatibility alias for \"i8\". Use \"i8\" to emphasize the "
-             "signedness of this type.\n");
-    g_byte_warning_emitted = true;
-  }
-}
-
-/**
- * Prints deprecation notice for old NS declarations that are no longer supported
- * If new_form is NULL, old_form is assumed to be a language identifier, such as "cpp"
- * If new_form is not NULL, both arguments are used exactly as given
- */
-void error_unsupported_namespace_decl(const char* old_form, const char* new_form) {
-  const char* remainder = "";
-  if( new_form == NULL) {
-    new_form = old_form;
-    remainder = "_namespace";
-  }
-  failure("Unsupported declaration '%s%s'. Use 'namespace %s' instead.", old_form, remainder, new_form);
-}
-
-/**
- * Prints the version number
- */
-void version() {
-  printf("Thrift version %s\n", THRIFT_VERSION);
-}
-
-/**
- * Display the usage message and then exit with an error code.
- */
-void usage() {
-  fprintf(stderr, "Usage: thrift [options] file\n\n");
-  fprintf(stderr, "Use thrift -help for a list of options\n");
-  exit(1);
-}
-
-/**
- * Diplays the help message and then exits with an error code.
- */
-void help() {
-  fprintf(stderr, "Usage: thrift [options] file\n");
-  fprintf(stderr, "Options:\n");
-  fprintf(stderr, "  -version    Print the compiler version\n");
-  fprintf(stderr, "  -o dir      Set the output directory for gen-* packages\n");
-  fprintf(stderr, "               (default: current directory)\n");
-  fprintf(stderr, "  -out dir    Set the ouput location for generated files.\n");
-  fprintf(stderr, "               (no gen-* folder will be created)\n");
-  fprintf(stderr, "  -I dir      Add a directory to the list of directories\n");
-  fprintf(stderr, "                searched for include directives\n");
-  fprintf(stderr, "  -nowarn     Suppress all compiler warnings (BAD!)\n");
-  fprintf(stderr, "  -strict     Strict compiler warnings on\n");
-  fprintf(stderr, "  -v[erbose]  Verbose mode\n");
-  fprintf(stderr, "  -r[ecurse]  Also generate included files\n");
-  fprintf(stderr, "  -debug      Parse debug trace to stdout\n");
-  fprintf(stderr,
-          "  --allow-neg-keys  Allow negative field keys (Used to "
-          "preserve protocol\n");
-  fprintf(stderr, "                compatibility with older .thrift files)\n");
-  fprintf(stderr, "  --allow-64bit-consts  Do not print warnings about using 64-bit constants\n");
-  fprintf(stderr, "  --gen STR   Generate code with a dynamically-registered generator.\n");
-  fprintf(stderr, "                STR has the form language[:key1=val1[,key2[,key3=val3]]].\n");
-  fprintf(stderr, "                Keys and values are options passed to the generator.\n");
-  fprintf(stderr, "                Many options will not require values.\n");
-  fprintf(stderr, "\n");
-  fprintf(stderr, "Options related to audit operation\n");
-  fprintf(stderr, "   --audit OldFile   Old Thrift file to be audited with 'file'\n");
-  fprintf(stderr, "  -Iold dir    Add a directory to the list of directories\n");
-  fprintf(stderr, "                searched for include directives for old thrift file\n");
-  fprintf(stderr, "  -Inew dir    Add a directory to the list of directories\n");
-  fprintf(stderr, "                searched for include directives for new thrift file\n");
-  fprintf(stderr, "\n");
-  fprintf(stderr, "Available generators (and options):\n");
-
-  t_generator_registry::gen_map_t gen_map = t_generator_registry::get_generator_map();
-  t_generator_registry::gen_map_t::iterator iter;
-  for (iter = gen_map.begin(); iter != gen_map.end(); ++iter) {
-    fprintf(stderr,
-            "  %s (%s):\n",
-            iter->second->get_short_name().c_str(),
-            iter->second->get_long_name().c_str());
-    fprintf(stderr, "%s", iter->second->get_documentation().c_str());
-  }
-  exit(1);
-}
-
-/**
- * You know, when I started working on Thrift I really thought it wasn't going
- * to become a programming language because it was just a generator and it
- * wouldn't need runtime type information and all that jazz. But then we
- * decided to add constants, and all of a sudden that means runtime type
- * validation and inference, except the "runtime" is the code generator
- * runtime.
- */
-void validate_const_rec(std::string name, t_type* type, t_const_value* value) {
-  if (type->is_void()) {
-    throw "type error: cannot declare a void const: " + name;
-  }
-
-  if (type->is_base_type()) {
-    t_base_type::t_base tbase = ((t_base_type*)type)->get_base();
-    switch (tbase) {
-    case t_base_type::TYPE_STRING:
-      if (value->get_type() != t_const_value::CV_STRING) {
-        throw "type error: const \"" + name + "\" was declared as string";
-      }
-      break;
-    case t_base_type::TYPE_BOOL:
-      if (value->get_type() != t_const_value::CV_INTEGER) {
-        throw "type error: const \"" + name + "\" was declared as bool";
-      }
-      break;
-    case t_base_type::TYPE_I8:
-      if (value->get_type() != t_const_value::CV_INTEGER) {
-        throw "type error: const \"" + name + "\" was declared as byte";
-      }
-      break;
-    case t_base_type::TYPE_I16:
-      if (value->get_type() != t_const_value::CV_INTEGER) {
-        throw "type error: const \"" + name + "\" was declared as i16";
-      }
-      break;
-    case t_base_type::TYPE_I32:
-      if (value->get_type() != t_const_value::CV_INTEGER) {
-        throw "type error: const \"" + name + "\" was declared as i32";
-      }
-      break;
-    case t_base_type::TYPE_I64:
-      if (value->get_type() != t_const_value::CV_INTEGER) {
-        throw "type error: const \"" + name + "\" was declared as i64";
-      }
-      break;
-    case t_base_type::TYPE_DOUBLE:
-      if (value->get_type() != t_const_value::CV_INTEGER
-          && value->get_type() != t_const_value::CV_DOUBLE) {
-        throw "type error: const \"" + name + "\" was declared as double";
-      }
-      break;
-    default:
-      throw "compiler error: no const of base type " + t_base_type::t_base_name(tbase) + name;
-    }
-  } else if (type->is_enum()) {
-    if (value->get_type() != t_const_value::CV_IDENTIFIER) {
-      throw "type error: const \"" + name + "\" was declared as enum";
-    }
-
-    // see if there's a dot in the identifier
-    std::string name_portion = value->get_identifier_name();
-
-    const vector<t_enum_value*>& enum_values = ((t_enum*)type)->get_constants();
-    vector<t_enum_value*>::const_iterator c_iter;
-    bool found = false;
-
-    for (c_iter = enum_values.begin(); c_iter != enum_values.end(); ++c_iter) {
-      if ((*c_iter)->get_name() == name_portion) {
-        found = true;
-        break;
-      }
-    }
-    if (!found) {
-      throw "type error: const " + name + " was declared as type " + type->get_name()
-          + " which is an enum, but " + value->get_identifier()
-          + " is not a valid value for that enum";
-    }
-  } else if (type->is_struct() || type->is_xception()) {
-    if (value->get_type() != t_const_value::CV_MAP) {
-      throw "type error: const \"" + name + "\" was declared as struct/xception";
-    }
-    const vector<t_field*>& fields = ((t_struct*)type)->get_members();
-    vector<t_field*>::const_iterator f_iter;
-
-    const map<t_const_value*, t_const_value*>& val = value->get_map();
-    map<t_const_value*, t_const_value*>::const_iterator v_iter;
-    for (v_iter = val.begin(); v_iter != val.end(); ++v_iter) {
-      if (v_iter->first->get_type() != t_const_value::CV_STRING) {
-        throw "type error: " + name + " struct key must be string";
-      }
-      t_type* field_type = NULL;
-      for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
-        if ((*f_iter)->get_name() == v_iter->first->get_string()) {
-          field_type = (*f_iter)->get_type();
-        }
-      }
-      if (field_type == NULL) {
-        throw "type error: " + type->get_name() + " has no field " + v_iter->first->get_string();
-      }
-
-      validate_const_rec(name + "." + v_iter->first->get_string(), field_type, v_iter->second);
-    }
-  } else if (type->is_map()) {
-    t_type* k_type = ((t_map*)type)->get_key_type();
-    t_type* v_type = ((t_map*)type)->get_val_type();
-    const map<t_const_value*, t_const_value*>& val = value->get_map();
-    map<t_const_value*, t_const_value*>::const_iterator v_iter;
-    for (v_iter = val.begin(); v_iter != val.end(); ++v_iter) {
-      validate_const_rec(name + "<key>", k_type, v_iter->first);
-      validate_const_rec(name + "<val>", v_type, v_iter->second);
-    }
-  } else if (type->is_list() || type->is_set()) {
-    t_type* e_type;
-    if (type->is_list()) {
-      e_type = ((t_list*)type)->get_elem_type();
-    } else {
-      e_type = ((t_set*)type)->get_elem_type();
-    }
-    const vector<t_const_value*>& val = value->get_list();
-    vector<t_const_value*>::const_iterator v_iter;
-    for (v_iter = val.begin(); v_iter != val.end(); ++v_iter) {
-      validate_const_rec(name + "<elem>", e_type, *v_iter);
-    }
-  }
-}
-
-/**
- * Check simple identifier names
- * It's easier to do it this way instead of rewriting the whole grammar etc.
- */
-void validate_simple_identifier(const char* identifier) {
-  string name(identifier);
-  if (name.find(".") != string::npos) {
-    yyerror("Identifier %s can't have a dot.", identifier);
-    exit(1);
-  }
-}
-
-/**
- * Check the type of the parsed const information against its declared type
- */
-void validate_const_type(t_const* c) {
-  validate_const_rec(c->get_name(), c->get_type(), c->get_value());
-}
-
-/**
- * Check the type of a default value assigned to a field.
- */
-void validate_field_value(t_field* field, t_const_value* cv) {
-  validate_const_rec(field->get_name(), field->get_type(), cv);
-}
-
-/**
- * Check that all the elements of a throws block are actually exceptions.
- */
-bool validate_throws(t_struct* throws) {
-  const vector<t_field*>& members = throws->get_members();
-  vector<t_field*>::const_iterator m_iter;
-  for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
-    if (!t_generator::get_true_type((*m_iter)->get_type())->is_xception()) {
-      return false;
-    }
-  }
-  return true;
-}
-
-/**
- * Skips UTF-8 BOM if there is one
- */
-bool skip_utf8_bom(FILE* f) {
-
-  // pretty straightforward, but works
-  if (fgetc(f) == 0xEF) {
-    if (fgetc(f) == 0xBB) {
-      if (fgetc(f) == 0xBF) {
-        return true;
-      }
-    }
-  }
-
-  rewind(f);
-  return false;
-}
-
-/**
- * Parses a program
- */
-void parse(t_program* program, t_program* parent_program) {
-  // Get scope file path
-  string path = program->get_path();
-
-  // Set current dir global, which is used in the include_file function
-  g_curdir = directory_name(path);
-  g_curpath = path;
-
-  // Open the file
-  // skip UTF-8 BOM if there is one
-  yyin = fopen(path.c_str(), "r");
-  if (yyin == 0) {
-    failure("Could not open input file: \"%s\"", path.c_str());
-  }
-  if (skip_utf8_bom(yyin))
-    pverbose("Skipped UTF-8 BOM at %s\n", path.c_str());
-
-  // Create new scope and scan for includes
-  pverbose("Scanning %s for includes\n", path.c_str());
-  g_parse_mode = INCLUDES;
-  g_program = program;
-  g_scope = program->scope();
-  try {
-    yylineno = 1;
-    if (yyparse() != 0) {
-      failure("Parser error during include pass.");
-    }
-  } catch (string x) {
-    failure(x.c_str());
-  }
-  fclose(yyin);
-
-  // Recursively parse all the include programs
-  vector<t_program*>& includes = program->get_includes();
-  vector<t_program*>::iterator iter;
-  for (iter = includes.begin(); iter != includes.end(); ++iter) {
-    parse(*iter, program);
-  }
-
-  // reset program doctext status before parsing a new file
-  reset_program_doctext_info();
-
-  // Parse the program file
-  g_parse_mode = PROGRAM;
-  g_program = program;
-  g_scope = program->scope();
-  g_parent_scope = (parent_program != NULL) ? parent_program->scope() : NULL;
-  g_parent_prefix = program->get_name() + ".";
-  g_curpath = path;
-
-  // Open the file
-  // skip UTF-8 BOM if there is one
-  yyin = fopen(path.c_str(), "r");
-  if (yyin == 0) {
-    failure("Could not open input file: \"%s\"", path.c_str());
-  }
-  if (skip_utf8_bom(yyin))
-    pverbose("Skipped UTF-8 BOM at %s\n", path.c_str());
-
-  pverbose("Parsing %s for types\n", path.c_str());
-  yylineno = 1;
-  try {
-    if (yyparse() != 0) {
-      failure("Parser error during types pass.");
-    }
-  } catch (string x) {
-    failure(x.c_str());
-  }
-  fclose(yyin);
-}
-
-/**
- * Generate code
- */
-void generate(t_program* program, const vector<string>& generator_strings) {
-  // Oooohh, recursive code generation, hot!!
-  if (gen_recurse) {
-    const vector<t_program*>& includes = program->get_includes();
-    for (size_t i = 0; i < includes.size(); ++i) {
-      // Propagate output path from parent to child programs
-      includes[i]->set_out_path(program->get_out_path(), program->is_out_path_absolute());
-
-      generate(includes[i], generator_strings);
-    }
-  }
-
-  // Generate code!
-  try {
-    pverbose("Program: %s\n", program->get_path().c_str());
-
-    if (dump_docs) {
-      dump_docstrings(program);
-    }
-
-    vector<string>::const_iterator iter;
-    for (iter = generator_strings.begin(); iter != generator_strings.end(); ++iter) {
-      t_generator* generator = t_generator_registry::get_generator(program, *iter);
-
-      if (generator == NULL) {
-#ifdef THRIFT_ENABLE_PLUGIN
-        switch (plugin_output::delegateToPlugin(program, *iter)) {
-          case plugin_output::PLUGIN_NOT_FOUND:
-            pwarning(1, "Unable to get a generator for \"%s\".\n", iter->c_str());
-            g_generator_failure = true;
-            break;
-          case plugin_output::PLUGIN_FAILURE:
-            pwarning(1, "Plugin generator for \"%s\" failed.\n", iter->c_str());
-            g_generator_failure = true;
-            break;
-          case plugin_output::PLUGIN_SUCCEESS:
-            break;
-          default:
-            assert(false);
-            break;
-        }
-#else
-        pwarning(1, "Unable to get a generator for \"%s\".\n", iter->c_str());
-        g_generator_failure = true;
-#endif
-      } else if (generator) {
-        pverbose("Generating \"%s\"\n", iter->c_str());
-        generator->generate_program();
-        delete generator;
-      }
-    }
-  } catch (string s) {
-    failure("Error: %s\n", s.c_str());
-  } catch (const char* exc) {
-    failure("Error: %s\n", exc);
-  }
-}
-
-void audit(t_program* new_program,
-           t_program* old_program,
-           string new_thrift_include_path,
-           string old_thrift_include_path) {
-  vector<string> temp_incl_searchpath = g_incl_searchpath;
-  if (!old_thrift_include_path.empty()) {
-    g_incl_searchpath.push_back(old_thrift_include_path);
-  }
-
-  parse(old_program, NULL);
-
-  g_incl_searchpath = temp_incl_searchpath;
-  if (!new_thrift_include_path.empty()) {
-    g_incl_searchpath.push_back(new_thrift_include_path);
-  }
-
-  parse(new_program, NULL);
-
-  compare_namespace(new_program, old_program);
-  compare_services(new_program->get_services(), old_program->get_services());
-  compare_enums(new_program->get_enums(), old_program->get_enums());
-  compare_structs(new_program->get_structs(), old_program->get_structs());
-  compare_structs(new_program->get_xceptions(), old_program->get_xceptions());
-  compare_consts(new_program->get_consts(), old_program->get_consts());
-}
-
-/**
- * Parse it up.. then spit it back out, in pretty much every language. Alright
- * not that many languages, but the cool ones that we care about.
- */
-int main(int argc, char** argv) {
-  int i;
-  std::string out_path;
-  bool out_path_is_absolute = false;
-
-  // Setup time string
-  time_t now = time(NULL);
-  g_time_str = ctime(&now);
-
-  // Check for necessary arguments, you gotta have at least a filename and
-  // an output language flag
-  if (argc < 2) {
-    usage();
-  }
-
-  vector<string> generator_strings;
-  string old_thrift_include_path;
-  string new_thrift_include_path;
-  string old_input_file;
-
-  // Set the current path to a dummy value to make warning messages clearer.
-  g_curpath = "arguments";
-
-  // Hacky parameter handling... I didn't feel like using a library sorry!
-  for (i = 1; i < argc - 1; i++) {
-    char* arg;
-
-    arg = strtok(argv[i], " ");
-    while (arg != NULL) {
-      // Treat double dashes as single dashes
-      if (arg[0] == '-' && arg[1] == '-') {
-        ++arg;
-      }
-
-      if (strcmp(arg, "-help") == 0) {
-        help();
-      } else if (strcmp(arg, "-version") == 0) {
-        version();
-        exit(0);
-      } else if (strcmp(arg, "-debug") == 0) {
-        g_debug = 1;
-      } else if (strcmp(arg, "-nowarn") == 0) {
-        g_warn = 0;
-      } else if (strcmp(arg, "-strict") == 0) {
-        g_strict = 255;
-        g_warn = 2;
-      } else if (strcmp(arg, "-v") == 0 || strcmp(arg, "-verbose") == 0) {
-        g_verbose = 1;
-      } else if (strcmp(arg, "-r") == 0 || strcmp(arg, "-recurse") == 0) {
-        gen_recurse = true;
-      } else if (strcmp(arg, "-allow-neg-keys") == 0) {
-        g_allow_neg_field_keys = true;
-      } else if (strcmp(arg, "-allow-64bit-consts") == 0) {
-        g_allow_64bit_consts = true;
-      } else if (strcmp(arg, "-gen") == 0) {
-        arg = argv[++i];
-        if (arg == NULL) {
-          fprintf(stderr, "Missing generator specification\n");
-          usage();
-        }
-        generator_strings.push_back(arg);
-      } else if (strcmp(arg, "-I") == 0) {
-        // An argument of "-I\ asdf" is invalid and has unknown results
-        arg = argv[++i];
-
-        if (arg == NULL) {
-          fprintf(stderr, "Missing Include directory\n");
-          usage();
-        }
-        g_incl_searchpath.push_back(arg);
-      } else if ((strcmp(arg, "-o") == 0) || (strcmp(arg, "-out") == 0)) {
-        out_path_is_absolute = (strcmp(arg, "-out") == 0) ? true : false;
-        arg = argv[++i];
-        if (arg == NULL) {
-          fprintf(stderr, "-o: missing output directory\n");
-          usage();
-        }
-        out_path = arg;
-
-#ifdef _WIN32
-        // strip out trailing \ on Windows
-        std::string::size_type last = out_path.length() - 1;
-        if (out_path[last] == '\\') {
-          out_path.erase(last);
-        }
-#endif
-        if (!check_is_directory(out_path.c_str()))
-          return -1;
-      } else if (strcmp(arg, "-audit") == 0) {
-        g_audit = true;
-        arg = argv[++i];
-        if (arg == NULL) {
-          fprintf(stderr, "Missing old thrift file name for audit operation\n");
-          usage();
-        }
-        char old_thrift_file_rp[THRIFT_PATH_MAX];
-
-        // cppcheck-suppress uninitvar
-        if (saferealpath(arg, old_thrift_file_rp) == NULL) {
-          failure("Could not open input file with realpath: %s", arg);
-        }
-        old_input_file = string(old_thrift_file_rp);
-      } else if (strcmp(arg, "-audit-nofatal") == 0) {
-        g_audit_fatal = false;
-      } else if (strcmp(arg, "-Iold") == 0) {
-        arg = argv[++i];
-        if (arg == NULL) {
-          fprintf(stderr, "Missing Include directory for old thrift file\n");
-          usage();
-        }
-        old_thrift_include_path = string(arg);
-      } else if (strcmp(arg, "-Inew") == 0) {
-        arg = argv[++i];
-        if (arg == NULL) {
-          fprintf(stderr, "Missing Include directory for new thrift file\n");
-          usage();
-        }
-        new_thrift_include_path = string(arg);
-      } else {
-        fprintf(stderr, "Unrecognized option: %s\n", arg);
-        usage();
-      }
-
-      // Tokenize more
-      arg = strtok(NULL, " ");
-    }
-  }
-
-  // display help
-  if ((strcmp(argv[argc - 1], "-help") == 0) || (strcmp(argv[argc - 1], "--help") == 0)) {
-    help();
-  }
-
-  // if you're asking for version, you have a right not to pass a file
-  if ((strcmp(argv[argc - 1], "-version") == 0) || (strcmp(argv[argc - 1], "--version") == 0)) {
-    version();
-    exit(0);
-  }
-
-  // Initialize global types
-  initGlobals();
-
-  if (g_audit) {
-    // Audit operation
-
-    if (old_input_file.empty()) {
-      fprintf(stderr, "Missing file name of old thrift file for audit\n");
-      usage();
-    }
-
-    char new_thrift_file_rp[THRIFT_PATH_MAX];
-    if (argv[i] == NULL) {
-      fprintf(stderr, "Missing file name of new thrift file for audit\n");
-      usage();
-    }
-    // cppcheck-suppress uninitvar
-    if (saferealpath(argv[i], new_thrift_file_rp) == NULL) {
-      failure("Could not open input file with realpath: %s", argv[i]);
-    }
-    string new_input_file(new_thrift_file_rp);
-
-    t_program new_program(new_input_file);
-    t_program old_program(old_input_file);
-
-    audit(&new_program, &old_program, new_thrift_include_path, old_thrift_include_path);
-
-  } else {
-    // Generate options
-
-    // You gotta generate something!
-    if (generator_strings.empty()) {
-      fprintf(stderr, "No output language(s) specified\n");
-      usage();
-    }
-
-    // Real-pathify it
-    char rp[THRIFT_PATH_MAX];
-    if (argv[i] == NULL) {
-      fprintf(stderr, "Missing file name\n");
-      usage();
-    }
-    // cppcheck-suppress uninitvar
-    if (saferealpath(argv[i], rp) == NULL) {
-      failure("Could not open input file with realpath: %s", argv[i]);
-    }
-    string input_file(rp);
-
-    // Instance of the global parse tree
-    t_program* program = new t_program(input_file);
-    if (out_path.size()) {
-      program->set_out_path(out_path, out_path_is_absolute);
-    }
-
-    // Compute the cpp include prefix.
-    // infer this from the filename passed in
-    string input_filename = argv[i];
-    string include_prefix;
-
-    string::size_type last_slash = string::npos;
-    if ((last_slash = input_filename.rfind("/")) != string::npos) {
-      include_prefix = input_filename.substr(0, last_slash);
-    }
-
-    program->set_include_prefix(include_prefix);
-
-    // Parse it!
-    parse(program, NULL);
-
-    // The current path is not really relevant when we are doing generation.
-    // Reset the variable to make warning messages clearer.
-    g_curpath = "generation";
-    // Reset yylineno for the heck of it.  Use 1 instead of 0 because
-    // That is what shows up during argument parsing.
-    yylineno = 1;
-
-    // Generate it!
-    generate(program, generator_strings);
-    delete program;
-  }
-
-  // Clean up. Who am I kidding... this program probably orphans heap memory
-  // all over the place, but who cares because it is about to exit and it is
-  // all referenced and used by this wacky parse tree up until now anyways.
-  clearGlobals();
-
-  // Finished
-  if (g_return_failure && g_audit_fatal) {
-    exit(2);
-  }
-  if (g_generator_failure) {
-    exit(3);
-  }
-  // Finished
-  return 0;
-}

http://git-wip-us.apache.org/repos/asf/thrift/blob/052abc39/compiler/cpp/src/main.h
----------------------------------------------------------------------
diff --git a/compiler/cpp/src/main.h b/compiler/cpp/src/main.h
deleted file mode 100644
index b0af5a7..0000000
--- a/compiler/cpp/src/main.h
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-#ifndef T_MAIN_H
-#define T_MAIN_H
-
-#include <string>
-#include <cstdio>
-
-#include "logging.h"
-
-#include "parse/t_const.h"
-#include "parse/t_field.h"
-
-/**
- * Defined in the flex library
- */
-
-extern "C" { int yylex(void); }
-
-int yyparse(void);
-
-/**
- * Expected to be defined by Flex/Bison
- */
-void yyerror(const char* fmt, ...);
-
-/**
- * Check simple identifier names
- */
-void validate_simple_identifier(const char* identifier);
-
-/**
- * Check constant types
- */
-void validate_const_type(t_const* c);
-
-/**
- * Check constant types
- */
-void validate_field_value(t_field* field, t_const_value* cv);
-
-/**
- * Check members of a throws block
- */
-bool validate_throws(t_struct* throws);
-
-/**
- * Converts a string filename into a thrift program name
- */
-std::string program_name(std::string filename);
-
-/**
- * Gets the directory path of a filename
- */
-std::string directory_name(std::string filename);
-
-/**
- * Get the absolute path for an include file
- */
-std::string include_file(std::string filename);
-
-/**
- * Clears any previously stored doctext string.
- */
-void clear_doctext();
-
-/**
- * Cleans up text commonly found in doxygen-like comments
- */
-char* clean_up_doctext(char* doctext);
-
-/**
- * We are sure the program doctext candidate is really the program doctext.
- */
-void declare_valid_program_doctext();
-
-/**
- * Emits a warning on list<byte>, binary type is typically a much better choice.
- */
-void check_for_list_of_bytes(t_type* list_elem_type);
-
-/**
- * Emits a one-time warning on byte type, promoting the new i8 type instead
- */
-void emit_byte_type_warning();
-
-/**
- * Prints deprecation notice for old NS declarations that are no longer supported
- * If new_form is NULL, old_form is assumed to be a language identifier, such as "cpp"
- * If new_form is not NULL, both arguments are used exactly as given
- */
-void error_unsupported_namespace_decl(const char* old_form, const char* new_form = NULL);
-
-/**
- * Flex utilities
- */
-
-extern int yylineno;
-extern char yytext[];
-extern std::FILE* yyin;
-
-#endif

http://git-wip-us.apache.org/repos/asf/thrift/blob/052abc39/compiler/cpp/src/parse/parse.cc
----------------------------------------------------------------------
diff --git a/compiler/cpp/src/parse/parse.cc b/compiler/cpp/src/parse/parse.cc
deleted file mode 100644
index 81a557b..0000000
--- a/compiler/cpp/src/parse/parse.cc
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-#include "t_type.h"
-#include "t_typedef.h"
-
-#include "main.h"
-
-t_type* t_type::get_true_type() {
-  t_type* type = this;
-  while (type->is_typedef()) {
-    type = ((t_typedef*)type)->get_type();
-  }
-  return type;
-}
-
-const t_type* t_type::get_true_type() const {
-  const t_type* type = this;
-  while (type->is_typedef()) {
-    type = ((t_typedef*)type)->get_type();
-  }
-  return type;
-}