Ejemplo n.º 1
0
  /**
   * Clear this configuration and reset to the contents of the parsed string.
   *
   * @param text Git style text file listing configuration properties.
   * @throws ConfigInvalidException the text supplied is not formatted correctly. No changes were
   *     made to {@code this}.
   */
  public void fromText(final String text) throws ConfigInvalidException {
    final List<Entry> newEntries = new ArrayList<Entry>();
    final StringReader in = new StringReader(text);
    Entry last = null;
    Entry e = new Entry();
    for (; ; ) {
      int input = in.read();
      if (-1 == input) break;

      final char c = (char) input;
      if ('\n' == c) {
        // End of this entry.
        newEntries.add(e);
        if (e.section != null) last = e;
        e = new Entry();

      } else if (e.suffix != null) {
        // Everything up until the end-of-line is in the suffix.
        e.suffix += c;

      } else if (';' == c || '#' == c) {
        // The rest of this line is a comment; put into suffix.
        e.suffix = String.valueOf(c);

      } else if (e.section == null && Character.isWhitespace(c)) {
        // Save the leading whitespace (if any).
        if (e.prefix == null) e.prefix = "";
        e.prefix += c;

      } else if ('[' == c) {
        // This is a section header.
        e.section = readSectionName(in);
        input = in.read();
        if ('"' == input) {
          e.subsection = readValue(in, true, '"');
          input = in.read();
        }
        if (']' != input) throw new ConfigInvalidException(JGitText.get().badGroupHeader);
        e.suffix = "";

      } else if (last != null) {
        // Read a value.
        e.section = last.section;
        e.subsection = last.subsection;
        in.reset();
        e.name = readKeyName(in);
        if (e.name.endsWith("\n")) {
          e.name = e.name.substring(0, e.name.length() - 1);
          e.value = MAGIC_EMPTY_VALUE;
        } else e.value = readValue(in, false, -1);

      } else throw new ConfigInvalidException(JGitText.get().invalidLineInConfigFile);
    }

    state.set(newState(newEntries));
  }
Ejemplo n.º 2
0
 Entry forValue(final String newValue) {
   final Entry e = new Entry();
   e.prefix = prefix;
   e.section = section;
   e.subsection = subsection;
   e.name = name;
   e.value = newValue;
   e.suffix = suffix;
   return e;
 }
Ejemplo n.º 3
0
 public Chain updateBy(Entity<?> entity) {
   if (null != entity) {
     Entry current = head;
     while (current != null) {
       MappingField ef = entity.getField(current.name);
       if (null != ef) {
         current.name = ef.getColumnName();
       }
       current = current.next;
     }
   }
   return head();
 }
Ejemplo n.º 4
0
  public Entry getOrPutMethods(String name, Header header) {
    final Class cls = header.cls;
    int h = hash(header.clsHashCode31 + name.hashCode());
    final Entry[] t = table;
    final int index = h & (t.length - 1);
    Entry e = t[index];
    for (; e != null; e = e.nextHashEntry)
      if (e.hash == h && cls == e.cls && (e.name == name || e.name.equals(name))) return e;

    Entry entry = new Entry();
    entry.nextHashEntry = t[index];
    entry.hash = h;
    entry.name = name.intern();
    entry.cls = cls;
    t[index] = entry;

    entry.nextClassEntry = header.head;
    header.head = entry;

    if (++size == threshold) resize(2 * t.length);

    return entry;
  }
Ejemplo n.º 5
0
  private State replaceStringList(
      final State srcState,
      final String section,
      final String subsection,
      final String name,
      final List<String> values) {
    final List<Entry> entries = copy(srcState, values);
    int entryIndex = 0;
    int valueIndex = 0;
    int insertPosition = -1;

    // Reset the first n Entry objects that match this input name.
    //
    while (entryIndex < entries.size() && valueIndex < values.size()) {
      final Entry e = entries.get(entryIndex);
      if (e.match(section, subsection, name)) {
        entries.set(entryIndex, e.forValue(values.get(valueIndex++)));
        insertPosition = entryIndex + 1;
      }
      entryIndex++;
    }

    // Remove any extra Entry objects that we no longer need.
    //
    if (valueIndex == values.size() && entryIndex < entries.size()) {
      while (entryIndex < entries.size()) {
        final Entry e = entries.get(entryIndex++);
        if (e.match(section, subsection, name)) entries.remove(--entryIndex);
      }
    }

    // Insert new Entry objects for additional/new values.
    //
    if (valueIndex < values.size() && entryIndex == entries.size()) {
      if (insertPosition < 0) {
        // We didn't find a matching key above, but maybe there
        // is already a section available that matches. Insert
        // after the last key of that section.
        //
        insertPosition = findSectionEnd(entries, section, subsection);
      }
      if (insertPosition < 0) {
        // We didn't find any matching section header for this key,
        // so we must create a new section header at the end.
        //
        final Entry e = new Entry();
        e.section = section;
        e.subsection = subsection;
        entries.add(e);
        insertPosition = entries.size();
      }
      while (valueIndex < values.size()) {
        final Entry e = new Entry();
        e.section = section;
        e.subsection = subsection;
        e.name = name;
        e.value = values.get(valueIndex++);
        entries.add(insertPosition++, e);
      }
    }

    return newState(entries);
  }
Ejemplo n.º 6
0
  // ###############################################################
  // method: yyparse : parse input and execute indicated items
  // ###############################################################
  int yyparse() {
    boolean doaction;
    init_stacks();
    yynerrs = 0;
    yyerrflag = 0;
    yychar = -1; // impossible char forces a read
    yystate = 0; // initial state
    state_push(yystate); // save it
    while (true) // until parsing is done, either correctly, or w/error
    {
      doaction = true;
      // if (yydebug) debug("loop");
      // #### NEXT ACTION (from reduction table)
      for (yyn = yydefred[yystate]; yyn == 0; yyn = yydefred[yystate]) {
        // if (yydebug) debug("yyn:"+yyn+"  state:"+yystate+"  yychar:"+yychar);
        if (yychar < 0) // we want a char?
        {
          yychar = yylex(); // get next token
          // if (yydebug) debug(" next yychar:"+yychar);
          // #### ERROR CHECK ####
          // if (yychar < 0)    //it it didn't work/error
          //  {
          //  yychar = 0;      //change it to default string (no -1!)
          // if (yydebug)
          //  yylexdebug(yystate,yychar);
          //  }
        } // yychar<0
        yyn = yysindex[yystate]; // get amount to shift by (shift index)
        if ((yyn != 0) && (yyn += yychar) >= 0 && yyn <= YYTABLESIZE && yycheck[yyn] == yychar) {
          // if (yydebug)
          // debug("state "+yystate+", shifting to state "+yytable[yyn]);
          // #### NEXT STATE ####
          yystate = yytable[yyn]; // we are in a new state
          state_push(yystate); // save it
          val_push(yylval); // push our lval as the input for next rule
          yychar = -1; // since we have 'eaten' a token, say we need another
          if (yyerrflag > 0) // have we recovered an error?
          --yyerrflag; // give ourselves credit
          doaction = false; // but don't process yet
          break; // quit the yyn=0 loop
        }

        yyn = yyrindex[yystate]; // reduce
        if ((yyn != 0)
            && (yyn += yychar) >= 0
            && yyn <= YYTABLESIZE
            && yycheck[yyn] == yychar) { // we reduced!
          // if (yydebug) debug("reduce");
          yyn = yytable[yyn];
          doaction = true; // get ready to execute
          break; // drop down to actions
        } else // ERROR RECOVERY
        {
          if (yyerrflag == 0) {
            yyerror("syntax error");
            yynerrs++;
          }
          if (yyerrflag < 3) // low error count?
          {
            yyerrflag = 3;
            while (true) // do until break
            {
              if (stateptr < 0 || valptr < 0) // check for under & overflow here
              {
                return 1;
              }
              yyn = yysindex[state_peek(0)];
              if ((yyn != 0)
                  && (yyn += YYERRCODE) >= 0
                  && yyn <= YYTABLESIZE
                  && yycheck[yyn] == YYERRCODE) {
                // if (yydebug)
                // debug("state "+state_peek(0)+", error recovery shifting to state "+yytable[yyn]+"
                // ");
                yystate = yytable[yyn];
                state_push(yystate);
                val_push(yylval);
                doaction = false;
                break;
              } else {
                // if (yydebug)
                // debug("error recovery discarding state "+state_peek(0)+" ");
                if (stateptr < 0 || valptr < 0) // check for under & overflow here
                {
                  return 1;
                }
                state_pop();
                val_pop();
              }
            }
          } else // discard this token
          {
            if (yychar == 0) return 1; // yyabort
            // if (yydebug)
            // {
            // yys = null;
            // if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
            // if (yys == null) yys = "illegal-symbol";
            // debug("state "+yystate+", error recovery discards token "+yychar+" ("+yys+")");
            // }
            yychar = -1; // read another
          }
        } // end error recovery
      } // yyn=0 loop
      if (!doaction) // any reason not to proceed?
      continue; // skip action
      yym = yylen[yyn]; // get count of terminals on rhs
      // if (yydebug)
      // debug("state "+yystate+", reducing "+yym+" by rule "+yyn+" ("+yyrule[yyn]+")");
      if (yym > 0) // if count of rhs not 'nil'
      yyval = val_peek(yym - 1); // get current semantic value
      if (reduceListener == null || reduceListener.onReduce(yyrule[yyn])) // if intercepted!
      switch (yyn) {
            // ########## USER-SUPPLIED ACTIONS ##########
          case 4:
            // #line 30 "Parser.y"
            {
              createVTable(
                  val_peek(6).sVal, val_peek(3).sVal, val_peek(2).sVal, val_peek(1).entrys);
            }
            break;
          case 5:
            // #line 34 "Parser.y"
            {
              createVTable(val_peek(6).sVal, null, val_peek(2).sVal, val_peek(1).entrys);
            }
            break;
          case 6:
            // #line 40 "Parser.y"
            {
              Entry e = new Entry();
              e.name = val_peek(1).sVal;
              e.offset = -1;
              val_peek(2).entrys.add(e);
            }
            break;
          case 7:
            // #line 47 "Parser.y"
            {
              yyval.entrys = new ArrayList<Entry>();
            }
            break;
          case 10:
            // #line 57 "Parser.y"
            {
              endFunc();
            }
            break;
          case 11:
            // #line 63 "Parser.y"
            {
              enterFunc(val_peek(3).loc, val_peek(1).sVal);
            }
            break;
          case 13:
            // #line 68 "Parser.y"
            {
              enterFunc(val_peek(3).loc, val_peek(1).sVal);
            }
            break;
          case 15:
            // #line 75 "Parser.y"
            {
              addParam(val_peek(2).sVal, val_peek(0).iVal);
            }
            break;
          case 19:
            // #line 86 "Parser.y"
            {
              genAdd(val_peek(2).loc, val_peek(6).sVal, val_peek(3).sVal, val_peek(1).sVal);
            }
            break;
          case 20:
            // #line 90 "Parser.y"
            {
              genSub(val_peek(2).loc, val_peek(6).sVal, val_peek(3).sVal, val_peek(1).sVal);
            }
            break;
          case 21:
            // #line 94 "Parser.y"
            {
              genMul(val_peek(2).loc, val_peek(6).sVal, val_peek(3).sVal, val_peek(1).sVal);
            }
            break;
          case 22:
            // #line 98 "Parser.y"
            {
              genDiv(val_peek(2).loc, val_peek(6).sVal, val_peek(3).sVal, val_peek(1).sVal);
            }
            break;
          case 23:
            // #line 102 "Parser.y"
            {
              genMod(val_peek(2).loc, val_peek(6).sVal, val_peek(3).sVal, val_peek(1).sVal);
            }
            break;
          case 24:
            // #line 106 "Parser.y"
            {
              genLAnd(val_peek(2).loc, val_peek(6).sVal, val_peek(3).sVal, val_peek(1).sVal);
            }
            break;
          case 25:
            // #line 110 "Parser.y"
            {
              genLOr(val_peek(2).loc, val_peek(6).sVal, val_peek(3).sVal, val_peek(1).sVal);
            }
            break;
          case 26:
            // #line 114 "Parser.y"
            {
              genGtr(val_peek(2).loc, val_peek(6).sVal, val_peek(3).sVal, val_peek(1).sVal);
            }
            break;
          case 27:
            // #line 118 "Parser.y"
            {
              genGeq(val_peek(2).loc, val_peek(6).sVal, val_peek(3).sVal, val_peek(1).sVal);
            }
            break;
          case 28:
            // #line 122 "Parser.y"
            {
              genEqu(val_peek(2).loc, val_peek(6).sVal, val_peek(3).sVal, val_peek(1).sVal);
            }
            break;
          case 29:
            // #line 126 "Parser.y"
            {
              genNeq(val_peek(2).loc, val_peek(6).sVal, val_peek(3).sVal, val_peek(1).sVal);
            }
            break;
          case 30:
            // #line 130 "Parser.y"
            {
              genLeq(val_peek(2).loc, val_peek(6).sVal, val_peek(3).sVal, val_peek(1).sVal);
            }
            break;
          case 31:
            // #line 134 "Parser.y"
            {
              genLes(val_peek(2).loc, val_peek(6).sVal, val_peek(3).sVal, val_peek(1).sVal);
            }
            break;
          case 32:
            // #line 138 "Parser.y"
            {
              genLNot(val_peek(1).loc, val_peek(3).sVal, val_peek(0).sVal);
            }
            break;
          case 33:
            // #line 142 "Parser.y"
            {
              genNeg(val_peek(1).loc, val_peek(3).sVal, val_peek(0).sVal);
            }
            break;
          case 34:
            // #line 146 "Parser.y"
            {
              genAssign(val_peek(1).loc, val_peek(2).sVal, val_peek(0).sVal);
            }
            break;
          case 35:
            // #line 150 "Parser.y"
            {
              genLoadImm4(val_peek(1).loc, val_peek(2).sVal, val_peek(0).iVal);
            }
            break;
          case 36:
            // #line 154 "Parser.y"
            {
              genLoadStr(val_peek(1).loc, val_peek(2).sVal, val_peek(0).sVal);
            }
            break;
          case 37:
            // #line 158 "Parser.y"
            {
              genLoad(val_peek(6).loc, val_peek(7).sVal, val_peek(3).sVal, val_peek(1).iVal);
            }
            break;
          case 38:
            // #line 162 "Parser.y"
            {
              genLoad(val_peek(6).loc, val_peek(7).sVal, val_peek(3).sVal, val_peek(1).sVal);
            }
            break;
          case 39:
            // #line 166 "Parser.y"
            {
              genLoad(val_peek(6).loc, val_peek(7).sVal, val_peek(3).sVal, -val_peek(1).iVal);
            }
            break;
          case 40:
            // #line 170 "Parser.y"
            {
              genStore(val_peek(1).loc, val_peek(0).sVal, val_peek(5).sVal, val_peek(3).iVal);
            }
            break;
          case 41:
            // #line 174 "Parser.y"
            {
              genStore(val_peek(1).loc, val_peek(0).sVal, val_peek(5).sVal, val_peek(3).sVal);
            }
            break;
          case 42:
            // #line 178 "Parser.y"
            {
              genStore(val_peek(1).loc, val_peek(0).sVal, val_peek(5).sVal, -val_peek(3).iVal);
            }
            break;
          case 43:
            // #line 182 "Parser.y"
            {
              genIndirectCall(val_peek(1).loc, val_peek(3).sVal, val_peek(0).sVal);
            }
            break;
          case 44:
            // #line 186 "Parser.y"
            {
              genIndirectCall(val_peek(1).loc, null, val_peek(0).sVal);
            }
            break;
          case 45:
            // #line 190 "Parser.y"
            {
              genDirectCall(val_peek(1).loc, val_peek(3).sVal, val_peek(0).sVal);
            }
            break;
          case 46:
            // #line 194 "Parser.y"
            {
              genDirectCall(val_peek(1).loc, val_peek(3).sVal, val_peek(0).sVal);
            }
            break;
          case 47:
            // #line 198 "Parser.y"
            {
              genDirectCall(val_peek(1).loc, null, val_peek(0).sVal);
            }
            break;
          case 48:
            // #line 202 "Parser.y"
            {
              genDirectCall(val_peek(1).loc, null, val_peek(0).sVal);
            }
            break;
          case 49:
            // #line 206 "Parser.y"
            {
              genLoadVtbl(val_peek(4).loc, val_peek(5).sVal, val_peek(1).sVal);
            }
            break;
          case 50:
            // #line 210 "Parser.y"
            {
              genBranch(val_peek(1).loc, val_peek(0).sVal);
            }
            break;
          case 51:
            // #line 214 "Parser.y"
            {
              genBeqz(val_peek(7).loc, val_peek(5).sVal, val_peek(0).sVal);
            }
            break;
          case 52:
            // #line 218 "Parser.y"
            {
              genBnez(val_peek(7).loc, val_peek(5).sVal, val_peek(0).sVal);
            }
            break;
          case 53:
            // #line 222 "Parser.y"
            {
              genParm(val_peek(1).loc, val_peek(0).sVal);
            }
            break;
          case 54:
            // #line 226 "Parser.y"
            {
              genReturn(val_peek(1).loc, val_peek(0).sVal);
            }
            break;
          case 55:
            // #line 230 "Parser.y"
            {
              genReturn(val_peek(1).loc, null);
            }
            break;
          case 56:
            // #line 234 "Parser.y"
            {
              markLabel(val_peek(1).sVal);
            }
            break;
            // #line 783 "Parser.java"
            // ########## END OF USER-SUPPLIED ACTIONS ##########
        } // switch
      // #### Now let's reduce... ####
      // if (yydebug) debug("reduce");
      state_drop(yym); // we just reduced yylen states
      yystate = state_peek(0); // get new state
      val_drop(yym); // corresponding value drop
      yym = yylhs[yyn]; // select next TERMINAL(on lhs)
      if (yystate == 0 && yym == 0) // done? 'rest' state and at first TERMINAL
      {
        // if (yydebug) debug("After reduction, shifting from state 0 to state "+YYFINAL+"");
        yystate = YYFINAL; // explicitly say we're done
        state_push(YYFINAL); // and save it
        val_push(yyval); // also save the semantic value of parsing
        if (yychar < 0) // we want another character?
        {
          yychar = yylex(); // get next character
          // if (yychar<0) yychar=0;  //clean, if necessary
          // if (yydebug)
          // yylexdebug(yystate,yychar);
        }
        if (yychar == 0) // Good exit (if lex returns 0 ;-)
        break; // quit the loop--all DONE
      } // if yystate
      else // else not done yet
      { // get next state and push, for next yydefred[]
        yyn = yygindex[yym]; // find out where to go
        if ((yyn != 0) && (yyn += yystate) >= 0 && yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
          yystate = yytable[yyn]; // get new state
        else yystate = yydgoto[yym]; // else go to new defred
        // if (yydebug) debug("after reduction, shifting from state "+state_peek(0)+" to state
        // "+yystate+"");
        state_push(yystate); // going again, so push state & val...
        val_push(yyval); // for next action
      }
    } // main loop
    return 0; // yyaccept!!
  }
Ejemplo n.º 7
0
 public Chain name(String name) {
   current.name = name;
   return this;
 }