1. 15 10月, 2015 1 次提交
  2. 13 10月, 2015 13 次提交
    • E
      qapi: Simplify gen_visit_fields() error handling · 18bdbc3a
      Eric Blake 提交于
      Since we have consolidated all generated code to use 'err' as
      the name of the local variable for error detection, we can
      simplify the decision on whether to skip error detection (useful
      for deallocation paths) to be a boolean.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1443565276-4535-18-git-send-email-eblake@redhat.com>
      [Change to gen_visit_fields() simplified]
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      18bdbc3a
    • E
      qapi: Share gen_visit_fields() · 82ca8e46
      Eric Blake 提交于
      Consolidate the code between visit, command marshalling, and
      event generation that iterates over the members of a struct.
      It reduces code duplication in the generator, so that a future
      patch can reduce the size of generated code while touching only
      one instead of three locations.
      
      There are no changes to the generated marshal code.
      
      The visitor code becomes slightly more verbose, but remains
      semantically equivalent, and is actually easier to read as
      it follows a more common idiom:
      
      |     visit_optional(v, &(*obj)->has_device, "device", &err);
      |-    if (!err && (*obj)->has_device) {
      |-        visit_type_str(v, &(*obj)->device, "device", &err);
      |-    }
      |     if (err) {
      |         goto out;
      |     }
      |+    if ((*obj)->has_device) {
      |+        visit_type_str(v, &(*obj)->device, "device", &err);
      |+        if (err) {
      |+            goto out;
      |+        }
      |+    }
      
      The event code becomes slightly more verbose, but this is
      arguably a bug fix: although the visitors are not well
      documented, use of an optional member should not be attempted
      unless guarded by a prior call to visit_optional().  Works only
      because the output qmp visitor has a no-op visit_optional():
      
      |+    visit_optional(v, &has_offset, "offset", &err);
      |+    if (err) {
      |+        goto out;
      |+    }
      |     if (has_offset) {
      |         visit_type_int(v, &offset, "offset", &err);
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1443565276-4535-17-git-send-email-eblake@redhat.com>
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      82ca8e46
    • E
      qapi: Share gen_err_check() · 1f353344
      Eric Blake 提交于
      qapi-commands has a nice helper gen_err_check(), but did not
      use it everywhere. In fact, using it in more places makes it
      easier to reduce the lines of code used for generating error
      checks.  This in turn will make it easier for later patches
      to consolidate another common pattern among the generators.
      
      The generated code has fewer blank lines in qapi-event.c functions,
      but has no semantic difference.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1443565276-4535-16-git-send-email-eblake@redhat.com>
      [Drop another blank line for symmetry]
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      1f353344
    • E
      qapi: Consistent generated code: minimize push_indent() usage · 05372f70
      Eric Blake 提交于
      We had some pointless differences in the generated code for visit,
      command marshalling, and events; unifying them makes it easier for
      future patches to consolidate to common helper functions.
      This is one patch of a series to clean up these differences.
      
      This patch reduces the number of push_indent()/pop_indent() pairs
      so that generated code is typically already at its natural output
      indentation in the python files.  It is easier to reason about
      generated code if the reader does not have to track how much
      spacing will be inserted alongside the code, and moreso when all
      of the generators use the same patterns (qapi-type and qapi-event
      were already using in-place indentation).
      
      Arguably, the resulting python may be a bit harder to read with C
      code at the same indentation as python; on the other hand, not
      having to think about push_indent() is a win, and most decent
      editors provide syntax highlighting that makes it easier to
      visually distinguish python code from string literals that will
      become C code.
      
      There is no change to the generated output.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1443565276-4535-15-git-send-email-eblake@redhat.com>
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      05372f70
    • E
      qapi: Consistent generated code: prefer common indentation · e36c714e
      Eric Blake 提交于
      We had some pointless differences in the generated code for visit,
      command marshalling, and events; unifying them makes it easier for
      future patches to consolidate to common helper functions.
      This is one patch of a series to clean up these differences.
      
      This patch adjusts gen_visit_union() to use the same indentation
      as other functions, namely, by jumping early to the error label
      if the object was not set rather than placing the rest of the
      body inside an if for when it is set.
      
      No change in semantics to the generated code.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1443565276-4535-14-git-send-email-eblake@redhat.com>
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      e36c714e
    • E
      qapi: Consistent generated code: prefer common labels · f782399c
      Eric Blake 提交于
      We had some pointless differences in the generated code for visit,
      command marshalling, and events; unifying them makes it easier for
      future patches to consolidate to common helper functions.
      This is one patch of a series to clean up these differences.
      
      This patch names the goto labels 'out' (not 'clean') and 'out_obj'
      (not 'out_end').  Additionally, the generator was inconsistent on
      whether labels had a leading space [our HACKING is silent; while
      emacs 'gnu' style adds the space to avoid littering column 1].
      For minimal churn, prefer no leading space; this also matches
      the style that is more prevalent in current qemu.git.
      
      No change in semantics to the generated code.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1443565276-4535-13-git-send-email-eblake@redhat.com>
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      f782399c
    • E
      qapi: Consistent generated code: prefer visitor 'v' · f8b7f1a8
      Eric Blake 提交于
      We had some pointless differences in the generated code for visit,
      command marshalling, and events; unifying them makes it easier for
      future patches to consolidate to common helper functions.
      This is one patch of a series to clean up these differences.
      
      This patch names the local visitor variable 'v' rather than 'm'.
      Related objects, such as 'QapiDeallocVisitor', are also named by
      their initials instead of an unrelated leading m.
      
      No change in semantics to the generated code.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1443565276-4535-12-git-send-email-eblake@redhat.com>
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      f8b7f1a8
    • E
      qapi: Consistent generated code: prefer error 'err' · 2a0f50e8
      Eric Blake 提交于
      We had some pointless differences in the generated code for visit,
      command marshalling, and events; unifying them makes it easier for
      future patches to consolidate to common helper functions.
      This is one patch of a series to clean up these differences.
      
      This patch consistently names the local error variable 'err' rather
      than 'local_err'.
      
      No change in semantics to the generated code.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1443565276-4535-11-git-send-email-eblake@redhat.com>
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      2a0f50e8
    • E
      qapi: Reuse code for flat union base validation · 376863ef
      Eric Blake 提交于
      Rather than open-code the check for a valid base type, we
      should reuse the common functionality. This allows for
      consistent error messages, and also makes it easier for a
      later patch to turn on support for inline anonymous base
      structures.
      
      Test flat-union-inline is updated to test only one feature
      (anonymous branch dictionaries), which can be implemented
      independently (test flat-union-bad-base already covers the
      idea of an anonymous base dictionary).
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1443565276-4535-10-git-send-email-eblake@redhat.com>
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      376863ef
    • E
      qapi: Avoid assertion failure on union 'type' collision · 7b2a5c2f
      Eric Blake 提交于
      The previous commit added two tests that triggered an assertion
      failure. It's fairly straightforward to avoid the failure by
      just outright forbidding the collision between a union's tag
      values and its discriminator name (including the implicit name
      'kind' supplied for simple unions [*]).  Ultimately, we'd like
      to move the collision detection into QAPISchema*.check(), but
      for now it is easier just to enhance the existing checks.
      
      [*] Of course, down the road, we have plans to rename the simple
      union tag name to 'type' to match the QMP wire name, but the
      idea of the collision will still be present even then.
      
      Technically, we could avoid the collision by naming the C union
      members representing each enum value as '_case_value' rather
      than 'value'; but until we have an actual qapi client (and not
      just our testsuite) that has a legitimate reason to match a
      case label to the name of a QMP key and needs the name munging
      to satisfy the compiler, it's easier to just reject the qapi
      as invalid.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1443565276-4535-7-git-send-email-eblake@redhat.com>
      [Polished a few comments]
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      7b2a5c2f
    • E
      qapi: Clean up qapi.py per pep8 · 437db254
      Eric Blake 提交于
      Silence pep8, and make pylint a bit happier.  Just style cleanups,
      plus killing a useless comment in camel_to_upper(); no semantic
      changes.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1443565276-4535-5-git-send-email-eblake@redhat.com>
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      437db254
    • E
      qapi: Invoke exception superclass initializer · 59b00542
      Eric Blake 提交于
      pylint recommends that every exception class should explicitly
      invoke the superclass __init__, even though things seem to work
      fine without it.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1443565276-4535-4-git-send-email-eblake@redhat.com>
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      59b00542
    • E
      qapi: Improve 'include' error message · 7408fb67
      Eric Blake 提交于
      Use of '"...%s" % include' to print non-strings can lead to
      ugly messages, such as this (if the .json change is applied
      without the qapi.py change):
       Expected a file name (string), got: OrderedDict()
      
      Better is to just omit the actual non-string value in the
      message.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1443565276-4535-3-git-send-email-eblake@redhat.com>
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      7408fb67
  3. 09 10月, 2015 1 次提交
  4. 25 9月, 2015 2 次提交
  5. 21 9月, 2015 22 次提交
    • M
      qapi-introspect: Hide type names · 1a9a507b
      Markus Armbruster 提交于
      To eliminate the temptation for clients to look up types by name
      (which are not ABI), replace all type names by meaningless strings.
      
      Reduces output of query-schema by 13 out of 85KiB.
      
      As a debugging aid, provide option -u to suppress the hiding.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1442401589-24189-27-git-send-email-armbru@redhat.com>
      1a9a507b
    • M
      qapi: New QMP command query-qmp-schema for QMP introspection · 39a18158
      Markus Armbruster 提交于
      qapi/introspect.json defines the introspection schema.  It's designed
      for QMP introspection, but should do for similar uses, such as QGA.
      
      The introspection schema does not reflect all the rules and
      restrictions that apply to QAPI schemata.  A valid QAPI schema has an
      introspection value conforming to the introspection schema, but the
      converse is not true.
      
      Introspection lowers away a number of schema details, and makes
      implicit things explicit:
      
      * The built-in types are declared with their JSON type.
      
        All integer types are mapped to 'int', because how many bits we use
        internally is an implementation detail.  It could be pressed into
        external interface service as very approximate range information,
        but that's a bad idea.  If we need range information, we better do
        it properly.
      
      * Implicit type definitions are made explicit, and given
        auto-generated names:
      
        - Array types, named by appending "List" to the name of their
          element type, like in generated C.
      
        - The enumeration types implicitly defined by simple union types,
          named by appending "Kind" to the name of their simple union type,
          like in generated C.
      
        - Types that don't occur in generated C.  Their names start with ':'
          so they don't clash with the user's names.
      
      * All type references are by name.
      
      * The struct and union types are generalized into an object type.
      
      * Base types are flattened.
      
      * Commands take a single argument and return a single result.
      
        Dictionary argument or list result is an implicit type definition.
      
        The empty object type is used when a command takes no arguments or
        produces no results.
      
        The argument is always of object type, but the introspection schema
        doesn't reflect that.
      
        The 'gen': false directive is omitted as implementation detail.
      
        The 'success-response' directive is omitted as well for now, even
        though it's not an implementation detail, because it's not used by
        QMP.
      
      * Events carry a single data value.
      
        Implicit type definition and empty object type use, just like for
        commands.
      
        The value is of object type, but the introspection schema doesn't
        reflect that.
      
      * Types not used by commands or events are omitted.
      
        Indirect use counts as use.
      
      * Optional members have a default, which can only be null right now
      
        Instead of a mandatory "optional" flag, we have an optional default.
        No default means mandatory, default null means optional without
        default value.  Non-null is available for optional with default
        (possible future extension).
      
      * Clients should *not* look up types by name, because type names are
        not ABI.  Look up the command or event you're interested in, then
        follow the references.
      
        TODO Should we hide the type names to eliminate the temptation?
      
      New generator scripts/qapi-introspect.py computes an introspection
      value for its input, and generates a C variable holding it.
      
      It can generate awfully long lines.  Marked TODO.
      
      A new test-qmp-input-visitor test case feeds its result for both
      tests/qapi-schema/qapi-schema-test.json and qapi-schema.json to a
      QmpInputVisitor to verify it actually conforms to the schema.
      
      New QMP command query-qmp-schema takes its return value from that
      variable.  Its reply is some 85KiBytes for me right now.
      
      If this turns out to be too much, we have a couple of options:
      
      * We can use shorter names in the JSON.  Not the QMP style.
      
      * Optionally return the sub-schema for commands and events given as
        arguments.
      
        Right now qmp_query_schema() sends the string literal computed by
        qmp-introspect.py.  To compute sub-schema at run time, we'd have to
        duplicate parts of qapi-introspect.py in C.  Unattractive.
      
      * Let clients cache the output of query-qmp-schema.
      
        It changes only on QEMU upgrades, i.e. rarely.  Provide a command
        query-qmp-schema-hash.  Clients can have a cache indexed by hash,
        and re-query the schema only when they don't have it cached.  Even
        simpler: put the hash in the QMP greeting.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      39a18158
    • M
      qapi: Pseudo-type '**' is now unused, drop it · 2d21291a
      Markus Armbruster 提交于
      'gen': false needs to stay for now, because netdev_add is still using
      it.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NDaniel P. Berrange <berrange@redhat.com>
      Message-Id: <1442401589-24189-25-git-send-email-armbru@redhat.com>
      2d21291a
    • M
      qom: Don't use 'gen': false for qom-get, qom-set, object-add · 6eb3937e
      Markus Armbruster 提交于
      With the previous commit, the generated marshalers just work, and save
      us a bit of handwritten code.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NDaniel P. Berrange <berrange@redhat.com>
      Message-Id: <1442401589-24189-23-git-send-email-armbru@redhat.com>
      6eb3937e
    • M
      qapi: Introduce a first class 'any' type · 28770e05
      Markus Armbruster 提交于
      It's first class, because unlike '**', it actually works, i.e. doesn't
      require 'gen': false.
      
      '**' will go away next.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NDaniel P. Berrange <berrange@redhat.com>
      28770e05
    • M
      qapi-commands: De-duplicate output marshaling functions · 56d92b00
      Markus Armbruster 提交于
      gen_marshal_output() uses its parameter name only for name of the
      generated function.  Name it after the type being marshaled instead of
      its caller, and drop duplicates.
      
      Saves 7 copies of qmp_marshal_output_int() in qemu-ga, and one copy of
      qmp_marshal_output_str() in qemu-system-*.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NDaniel P. Berrange <berrange@redhat.com>
      Message-Id: <1442401589-24189-19-git-send-email-armbru@redhat.com>
      56d92b00
    • M
      qapi: De-duplicate parameter list generation · 03b4367a
      Markus Armbruster 提交于
      Generated qapi-event.[ch] lose line breaks.  No change otherwise.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NDaniel P. Berrange <berrange@redhat.com>
      Message-Id: <1442401589-24189-18-git-send-email-armbru@redhat.com>
      03b4367a
    • M
      qapi: Rename qmp_marshal_input_FOO() to qmp_marshal_FOO() · 7fad30f0
      Markus Armbruster 提交于
      These functions marshal both input and output.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NDaniel P. Berrange <berrange@redhat.com>
      Message-Id: <1442401589-24189-17-git-send-email-armbru@redhat.com>
      7fad30f0
    • M
      qapi-commands: Rearrange code · f1538019
      Markus Armbruster 提交于
      Rename gen_marshal_input() to gen_marshal(), because the generated
      function marshals both arguments and results.
      
      Rename gen_visitor_input_containers_decl() to gen_marshal_vars(), and
      move the other variable declarations there, too.
      
      Rename gen_visitor_input_block() to gen_marshal_input_visit(), and
      rearrange its code slightly.
      
      Rename gen_marshal_input_decl() to gen_marshal_proto(), because the
      result isn't a full declaration, unlike gen_command_decl()'s.
      
      New gen_marshal_decl() actually returns a full declaration.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NDaniel P. Berrange <berrange@redhat.com>
      Message-Id: <1442401589-24189-16-git-send-email-armbru@redhat.com>
      f1538019
    • M
      qapi-visit: Rearrange code a bit · 60f8546a
      Markus Armbruster 提交于
      Move gen_visit_decl() to a better place.  Inline
      generate_visit_struct_body().
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NDaniel P. Berrange <berrange@redhat.com>
      Message-Id: <1442401589-24189-15-git-send-email-armbru@redhat.com>
      60f8546a
    • M
      qapi: Clean up after recent conversions to QAPISchemaVisitor · e98859a9
      Markus Armbruster 提交于
      Generate just 'FOO' instead of 'struct FOO' when possible.
      
      Drop helper functions that are now unused.
      
      Make pep8 and pylint reasonably happy.
      
      Rename generate_FOO() functions to gen_FOO() for consistency.
      
      Use more consistent and sensible variable names.
      
      Consistently use c_ for mapping keys when their value is a C
      identifier or type.
      
      Simplify gen_enum() and gen_visit_union()
      
      Consistently use single quotes for C text string literals.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Message-Id: <1442401589-24189-14-git-send-email-armbru@redhat.com>
      Reviewed-by: NDaniel P. Berrange <berrange@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      e98859a9
    • M
      qapi: Replace dirty is_c_ptr() by method c_null() · 5710153e
      Markus Armbruster 提交于
      is_c_ptr() looks whether the end of the C text for the type looks like
      a pointer.  Works, but is fragile.
      
      We now have a better tool: use QAPISchemaType method c_null().  The
      initializers for non-pointers become prettier: 0, false or the
      enumeration constant with the value 0 instead of {0}.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NDaniel P. Berrange <berrange@redhat.com>
      Message-Id: <1442401589-24189-13-git-send-email-armbru@redhat.com>
      5710153e
    • M
      qapi-event: Convert to QAPISchemaVisitor, fixing data with base · 05f43a96
      Markus Armbruster 提交于
      Fixes events whose data is struct with base to include the struct's
      base members.  Test case is qapi-schema-test.json's event
      __org.qemu_x-command:
      
          { 'event': '__ORG.QEMU_X-EVENT', 'data': '__org.qemu_x-Struct' }
      
          { 'struct': '__org.qemu_x-Struct', 'base': '__org.qemu_x-Base',
            'data': { '__org.qemu_x-member2': 'str' } }
      
          { 'struct': '__org.qemu_x-Base',
            'data': { '__org.qemu_x-member1': '__org.qemu_x-Enum' } }
      
      Patch's effect on generated qapi_event_send___org_qemu_x_event():
      
          -void qapi_event_send___org_qemu_x_event(const char *__org_qemu_x_member2,
          +void qapi_event_send___org_qemu_x_event(__org_qemu_x_Enum __org_qemu_x_member1,
          +                                        const char *__org_qemu_x_member2,
                                                   Error **errp)
           {
               QDict *qmp;
          @@ -224,6 +225,10 @@ void qapi_event_send___org_qemu_x_event(
                   goto clean;
               }
      
          +    visit_type___org_qemu_x_Enum(v, &__org_qemu_x_member1, "__org.qemu_x-member1", &local_err);
          +    if (local_err) {
          +        goto clean;
          +    }
               visit_type_str(v, (char **)&__org_qemu_x_member2, "__org.qemu_x-member2", &local_err);
               if (local_err) {
                   goto clean;
      
      Code is generated in a different order now, but that doesn't matter.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NDaniel P. Berrange <berrange@redhat.com>
      05f43a96
    • M
      qapi-event: Eliminate global variable event_enum_value · 7b24626c
      Markus Armbruster 提交于
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NDaniel P. Berrange <berrange@redhat.com>
      Message-Id: <1442401589-24189-11-git-send-email-armbru@redhat.com>
      7b24626c
    • M
      qapi: De-duplicate enum code generation · efd2eaa6
      Markus Armbruster 提交于
      Duplicated in commit 21cd70df.  Yes, we can't import qapi-types, but
      that's no excuse.  Move the helpers from qapi-types.py to qapi.py, and
      replace the duplicates in qapi-event.py.
      
      The generated event enumeration type's lookup table becomes
      const-correct (see commit 2e4450ff), and uses explicit indexes instead
      of relying on order (see commit 912ae9c8).
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Message-Id: <1442401589-24189-10-git-send-email-armbru@redhat.com>
      Reviewed-by: NDaniel P. Berrange <berrange@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      efd2eaa6
    • M
      qapi-commands: Convert to QAPISchemaVisitor · ee446028
      Markus Armbruster 提交于
      Output unchanged apart from reordering and white-space.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1442401589-24189-9-git-send-email-armbru@redhat.com>
      Reviewed-by: NDaniel P. Berrange <berrange@redhat.com>
      ee446028
    • M
      qapi-visit: Convert to QAPISchemaVisitor, fixing bugs · 441cbac0
      Markus Armbruster 提交于
      Fixes flat unions to visit the base's base members (the previous
      commit merely added them to the struct).  Same test case.
      
      Patch's effect on visit_type_UserDefFlatUnion():
      
           static void visit_type_UserDefFlatUnion_fields(Visitor *m, UserDefFlatUnion **obj, Error **errp)
           {
               Error *err = NULL;
      
          +    visit_type_int(m, &(*obj)->integer, "integer", &err);
          +    if (err) {
          +        goto out;
          +    }
               visit_type_str(m, &(*obj)->string, "string", &err);
               if (err) {
                   goto out;
      
      Test cases updated for the bug fix.
      
      Fixes alternates to generate a visitor for their implicit enumeration
      type.  None of them are currently used, obviously.  Example:
      block-core.json's BlockdevRef now generates
      visit_type_BlockdevRefKind().
      
      Code is generated in a different order now, and therefore has got a
      few new forward declarations.  Doesn't matter.
      
      The guard QAPI_VISIT_BUILTIN_VISITOR_DECL is renamed to
      QAPI_VISIT_BUILTIN.
      
      The previous commit's two ugly special cases exist here, too.  Mark
      both TODO.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NDaniel P. Berrange <berrange@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      441cbac0
    • M
      qapi-types: Convert to QAPISchemaVisitor, fixing flat unions · 2b162ccb
      Markus Armbruster 提交于
      Fixes flat unions to get the base's base members.  Test case is from
      commit 2fc00432, in qapi-schema-test.json:
      
          { 'union': 'UserDefFlatUnion',
            'base': 'UserDefUnionBase',
            'discriminator': 'enum1',
            'data': { 'value1' : 'UserDefA',
                      'value2' : 'UserDefB',
                      'value3' : 'UserDefB' } }
      
          { 'struct': 'UserDefUnionBase',
            'base': 'UserDefZero',
            'data': { 'string': 'str', 'enum1': 'EnumOne' } }
      
          { 'struct': 'UserDefZero',
            'data': { 'integer': 'int' } }
      
      Patch's effect on UserDefFlatUnion:
      
           struct UserDefFlatUnion {
               /* Members inherited from UserDefUnionBase: */
          +    int64_t integer;
               char *string;
               EnumOne enum1;
               /* Own members: */
               union { /* union tag is @enum1 */
                   void *data;
                   UserDefA *value1;
                   UserDefB *value2;
                   UserDefB *value3;
               };
           };
      
      Flat union visitors remain broken.  They'll be fixed next.
      
      Code is generated in a different order now, but that doesn't matter.
      
      The two guards QAPI_TYPES_BUILTIN_STRUCT_DECL and
      QAPI_TYPES_BUILTIN_CLEANUP_DECL are replaced by just
      QAPI_TYPES_BUILTIN.
      
      Two ugly special cases for simple unions now stand out like sore
      thumbs:
      
      1. The type tag is named 'type' everywhere, except in generated C,
         where it's 'kind'.
      
      2. QAPISchema lowers simple unions to semantically equivalent flat
         unions.  However, the C generated for a simple unions differs from
         the C generated for its equivalent flat union, and we therefore
         need special code to preserve that pointless difference for now.
      
      Mark both TODO.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NDaniel P. Berrange <berrange@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      2b162ccb
    • M
      qapi: New QAPISchemaVisitor · 3f7dc21b
      Markus Armbruster 提交于
      The visitor will help keeping the code generation code simple and
      reasonably separated from QAPISchema details.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Message-Id: <1442401589-24189-5-git-send-email-armbru@redhat.com>
      Reviewed-by: NDaniel P. Berrange <berrange@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      3f7dc21b
    • M
      qapi: QAPISchema code generation helper methods · f51d8c3d
      Markus Armbruster 提交于
      New methods c_name(), c_type(), c_null(), json_type(),
      alternate_qtype().
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Message-Id: <1442401589-24189-4-git-send-email-armbru@redhat.com>
      Reviewed-by: NDaniel P. Berrange <berrange@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      f51d8c3d
    • M
      qapi: New QAPISchema intermediate reperesentation · ac88219a
      Markus Armbruster 提交于
      The QAPI code generators work with a syntax tree (nested dictionaries)
      plus a few symbol tables (also dictionaries) on the side.
      
      They have clearly outgrown these simple data structures.  There's lots
      of rummaging around in dictionaries, and information is recomputed on
      the fly.  For the work I'm going to do, I want more clearly defined
      and more convenient interfaces.
      
      Going forward, I also want less coupling between the back-ends and the
      syntax tree, to make messing with the syntax easier.
      
      Create a bunch of classes to represent QAPI schemata.
      
      Have the QAPISchema initializer call the parser, then walk the syntax
      tree to create the new internal representation, and finally perform
      semantic analysis.
      
      Shortcut: the semantic analysis still relies on existing check_exprs()
      to do the actual semantic checking.  All this code needs to move into
      the classes.  Mark as TODO.
      
      Simple unions are lowered to flat unions.  Flat unions and structs are
      represented as a more general object type.
      
      Catching name collisions in generated code would be nice.  Mark as
      TODO.
      
      We generate array types eagerly, even though most of them aren't used.
      Mark as TODO.
      
      Nothing uses the new intermediate representation just yet, thus no
      change to generated files.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NDaniel P. Berrange <berrange@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      ac88219a
    • M
      qapi: Rename class QAPISchema to QAPISchemaParser · a4bcb208
      Markus Armbruster 提交于
      I want to name a new class QAPISchema.
      
      While there, make it a new-style class.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NDaniel P. Berrange <berrange@redhat.com>
      Message-Id: <1442401589-24189-2-git-send-email-armbru@redhat.com>
      a4bcb208
  6. 16 9月, 2015 1 次提交