Class Compiler.Phase1

All Implemented Interfaces:
PCDataVisitor
Enclosing class:
Compiler

protected class Compiler.Phase1 extends Compiler.Phase
First and main code generation phase.
Creates code for
(1) checks uniqueness and correctness of names and abbrevs.
(2) collects documentation into Compiler.desrcibes_argument_types.
(3) makes value fields and getter methods for all option arguments
(4) generates code for enabling conditions.
(currently only simple "equal()" have been tested. More to come)
(5) collects serialization/unparsing code in serializeText
(6) collect multi-lingual doc text into Compiler.descriptions (Only for options, not enums)
All this by adding to visitor's registers, from the "visit option" and the "visit field" level.
  • Field Details

    • argnum

      int argnum
      Globar register for the argument number which is currently processed. May refer to a top-level argument or part of a repeting group.
    • currentlen

      int currentlen
      THe number of arguments on top level or in repting group, needed only to synthesize documentation text.
    • commentfields

      int commentfields
      Running counter of comment fields. Used to synthesize a name, if necessary.
    • repetingValueClass

      @Opt @Opt GeneratedClass repetingValueClass
      Currently processed repeting group, or null when on top-level.
    • repetingValueElement

      Element_rep repetingValueElement
      Currently processed repeting group, or null when on top-level.
    • documentedMeth

      @Opt @Opt GeneratedMethod documentedMeth
      The pars-pro-toto meth which gets the user-level documentation of the whole option.
    • cmd_usage

      protected StringBuilder cmd_usage
      Accumulator for the user documentation of the argument types sequecen of the visited option.
    • cmd_checkActive

      protected String cmd_checkActive
      Accumulator for generated java code to check the activity of the visited option.
    • usage_checkActive

      protected String usage_checkActive
      Accumulator for the user documentation of the activity condition of the visited option.
    • serializeText

      protected String serializeText
      Accumulator for the generated java code for the serialization of the visited option.
    • name2el

      protected Map<String,Element_option> name2el
      Lists option definitions by their long naes.
    • abbrev2el

      protected Map<String,Element_option> abbrev2el
      Lists option definitions by their short naes.
    • pos

      protected Map<Integer,Element_option> pos
      Lists option definitions iff their short name is a decimal digit.
  • Constructor Details

    • Phase1

      protected Phase1()
  • Method Details

    • visit

      public void visit(Element_enumeration element)
      Do nothing and DO NOT descend.
      Overrides:
      visit in class Visitor
    • visit

      public void visit(Element_comment element)
      Here only the text translations are collected and stored under a dedicated key, which all are entered in Compiler.descriptions. This must be done this early, so that a language appearing ONLY in a comment (a rare case, probably erronuous) will correctly be considered!
      Overrides:
      visit in class Visitor
    • visit

      public void visit(Element_optionlist element)
      Entry point; initialize the global data to collect and on return compiles some of it into generated source.
      Overrides:
      visit in class Visitor
    • visit

      public void visit(Element_option element)
      See description of containing class Compiler.Phase1
      Overrides:
      visit in class Compiler.Phase
    • visit

      public void visit(Element_text el)
      Memorize description text for gui tool-tips. Store it in global map Compiler.descriptions. Element_comment and Element_enumeration are pruned by this visitor code, so we come here only via Element_option and then Element_desc.
      Overrides:
      visit in class Visitor
    • addFullCommentOrCrossRef

      protected void addFullCommentOrCrossRef(GeneratedMethod m)
      For the first call, put the (English) documentation text and arguments' regExp to that method, as a pars-pro-toto; later put references to that first method.
    • addLinkComment

      protected void addLinkComment(GeneratedAnnotationTarget m)
      Put the (English) documentation text which leads the user to the pars-pro-toto documentedMeth.
    • addLinkCommentEXT

      protected void addLinkCommentEXT(GeneratedAnnotationTarget gm, String name)
      Put the (English) documentation text which leads the user to the pars-pro-toto documentedMeth contained in a diffrent class. Currently only used from the repeting-group class to its containing Model class.
    • makeValueField

      protected void makeValueField(MetaType cl, @Opt @Opt TypedAttribute<String> userdef, String defdef)
      Convenience method to prcess one single position of an option's type structure which is neither String nor enumeratin nor switch.
    • makeValueField

      protected void makeValueField(MetaType cl, @Opt @Opt TypedAttribute<String> userdef, String defdef, boolean isString, @Opt @Opt String enumname, boolean isSwitch, boolean hexOut)
      Central method for processing one single position of an options's type signature. It is called for every position of the top-level type sequence or of the trailing repetition sequence. It creates the metajava field object in the current modelclass, including its initializer and its getter method. It extends the serialization (un-parsing) method and the signature documentation text.
      Parameters:
      cl - the class of the model field to generate.
      userdef - (maybe null) the attribute carrying the default from the xml input.
      defdef - the default for the default value, if no default is specified in the xml input.
      isString - the default value is inserted in the generated code literally, so it must be additionally escaped iff it is a String.
      enumname - needed only as prefix for the default value / initializer
      isSwitch - is a argument-less option which only acts by mere presence.
      hexOut - that an integer value shall be serialized in hex format
    • makeNoArgSwitch

      public void makeNoArgSwitch()
      Make a special boolean value field plus methods plus usage() documentation for a "switch type" / "flag type" option.
    • visit

      public void visit(Element_int el)
      Make value field plus methods plus usage() documentation for an int type argument.
      Overrides:
      visit in class Visitor
    • visit

      public void visit(Element_float el)
      Make value field plus methods plus usage() documentation for a float type argument.
      Overrides:
      visit in class Visitor
    • visit

      public void visit(Element_rat el)
      Make value field plus methods plus usage() documentation for a rational type argument.
      Overrides:
      visit in class Visitor
    • visit

      public void visit(Element_bool el)
      Make value field plus methods plus usage() documentation for a boolean type argument.
      Overrides:
      visit in class Visitor
    • visit

      public void visit(Element_string el)
      Make value field plus methods plus usage() documentation for a String type argument. ATTENTION: The default value of a String field is not Java source, but the argument's value, as typed on an command line.
      Overrides:
      visit in class Visitor
    • visit

      public void visit(Element_uri el)
      Make value field plus methods plus usage() documentation for an URI / file path type argument. ATTENTION: The default value of a String field (and a string-like field as this) is not Java source, but directly the argument's value, as typed on an command line.
      Overrides:
      visit in class Visitor
    • visit

      public void visit(Element_enum el)
      Make value field plus methods plus usage() documentation for an enumeration type argument.
      Overrides:
      visit in class Visitor
    • visit

      public void visit(Element_enumset el)
      Make value field plus methods plus usage() documentation for an enum set type argument.
      Overrides:
      visit in class Visitor
    • visit

      public void visit(Element_rep el)
      Generate a class representing the repeting goup and fill this with field and method definitions using the same methods as implied for the top-level Model.
      Overrides:
      visit in class Visitor
    • visit

      public void visit(Element_and el)
      Stores Java source and user documentation for the "and" combinator in an enabling condition.
      Overrides:
      visit in class Visitor
    • visit

      public void visit(Element_or el)
      Stores Java source and user documentation for the "or" combinator in an enabling condition.
      Overrides:
      visit in class Visitor
    • visit

      public void visit(Element_not el)
      Stores Java source and user documentation for the "not" combinator in an enabling condition.
      Overrides:
      visit in class Visitor
    • visit

      public void visit(Element_testequal el)
      Stores Java source and user documentation for the equality test in an enabling condition.
      ATTENTION uses ".equals()" iff one of the arguments is a string constant starting with a double quotes or a call to "Rational" appears in one of the texts. Otherwise use "==".
      Overrides:
      visit in class Visitor
    • visit

      public void visit(Element_testgreater el)
      Stores Java source and user documentation for the "is grater" combinator in an enabling condition.
      Overrides:
      visit in class Visitor
    • visit

      public void visit(Element_constant el)
      Stores Java source and user documentation for a constant in an enabling condition. Each such constant (a) must be verbatim valid Java source and (b) shows up in the usage() documentation.
      Overrides:
      visit in class Visitor
    • visit

      public void visit(Element_optarg el)
      Stores Java source and user documentation for the reference to an option's arguemt in an enabling condition.
      Overrides:
      visit in class Visitor
    • visit

      public void visit(Element_enumSetContains el)
      Stores Java source and user documentation for the reference to an option's arguemt in an enabling condition.
      Overrides:
      visit in class Visitor