Uploaded image for project: 'Thrift'
  1. Thrift
  2. THRIFT-609

generator allows for fields that break code

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Duplicate
    • Affects Version/s: 0.2
    • Fix Version/s: None
    • Component/s: Ruby - Compiler
    • Labels:
      None

      Description

      affects latest SVN and latest snapshot.

      generator should allow for any possible known conflict with some ruby specific constant by either throwing an error for every known ruby specific constant name, or appending something like '__' to each of the fields. here is an example and a possible solution

      // EXAMPLE
      struct TimeInterval {
      1: UnixTime start,
      2: UnixTime end,
      }

      will generate invalid ruby code by trying to define "END":

      class TimeInterval
      include ::Thrift::Struct
      START = 1
      END = 2

      ::Thrift::Struct.field_accessor self, :start, :end
      FIELDS = {
      START => {:type => ::Thrift::Types::I32, :name => 'start'},
      END => {:type => ::Thrift::Types::I32, :name => 'end'}
      }

      def struct_fields; FIELDS; end

      def validate
      end

      end

      // POSSIBLE SOLUTION
      line 523:
      void t_rb_generator::generate_field_constants(std::ofstream& out, t_struct* tstruct) {
      const vector<t_field*>& fields = tstruct->get_members();
      vector<t_field*>::const_iterator f_iter;

      for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter)

      { std::string field_name = (*f_iter)->get_name(); std::string cap_field_name = upcase_string(field_name); // // append '__' to the end of field names cap_field_name = cap_field_name + "__"; // // indent(out) << cap_field_name << " = " << (*f_iter)->get_key() << endl; }

      out << endl;
      }
      line 551:
      void t_rb_generator::generate_field_defns(std::ofstream& out, t_struct* tstruct) {
      const vector<t_field*>& fields = tstruct->get_members();
      vector<t_field*>::const_iterator f_iter;

      indent(out) << "FIELDS = {" << endl;
      indent_up();
      for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
      if (f_iter != fields.begin())

      { out << "," << endl; }

      // generate the field docstrings within the FIELDS constant. no real better place...
      generate_rdoc(out, *f_iter);
      //
      //
      // add the '__' to the end of the field name
      indent(out) <<
      upcase_string((*f_iter)->get_name()) << "__ => ";
      //
      //
      generate_field_data(out, (*f_iter)>get_type(), (*f_iter)>get_name(), (*f_iter)->get_value(),
      (*f_iter)->get_req() == t_field::T_OPTIONAL);
      }
      indent_down();
      out << endl;
      indent(out) << "}" << endl << endl;

      indent(out) << "def struct_fields; FIELDS; end" << endl << endl;

      }

      this will then make all possible variations in ruby syntactically sound

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                trane Andrew Kuhnhausen
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: