system/src/sc/binf/ParseInStream.java
public Object readChild(Parser parser, Parselet parselet, RestoreCtx rctx) {
      int pnType = readUInt();
      NestedParselet nestedParselet = null;
      Parselet nextChildParselet = null;
      switch (pnType) {
         case ParseOutStream.NullPN:
            return null;
         case ParseOutStream.ParentPNType:
            nestedParselet = (NestedParselet) getNextParselet(parser, rctx);
            // Fall through...
         case ParseOutStream.ParentPN:
            int sz = readUInt();
            if (nestedParselet == null)
               nestedParselet = (NestedParselet) parselet;
            int startIndex = parser.getCurrentIndex();
            if (nestedParselet == null)
               System.out.println("*** Error no parselet for parentPN");
            ParentParseNode ppn = nestedParselet.newParseNode(startIndex);
            for (int i = 0; i < sz; i++) {
               Parselet childParselet = nestedParselet.getChildParseletForIndex(i);
               if (childParselet == null) {
                  childParselet = getNextParselet(parser, rctx);
               }
               Object childPN = readChild(parser, childParselet, rctx);
               // Need this to set the semantic value for qualifiedIdentifier
               //ppn.add(childPN, childParselet, -1, nestedParselet.getParseletSlotIx(childParselet), false, parser);
               ppn.addGeneratedNode(childPN);
            }
            if (parser.getCurrentIndex() != startIndex + ppn.length())
               System.err.println("*** readChild - current index not updated properly during restore of parent");
            return ppn;
         case ParseOutStream.SinglePNType:
            nestedParselet = (NestedParselet) getNextParselet(parser, rctx);
            nextChildParselet = getNextParselet(parser, rctx);
            // Fall through...
         case ParseOutStream.SinglePN:
            if (nestedParselet == null) {
               if (!(parselet instanceof NestedParselet))
                  throw new IllegalArgumentException("*** Not a nested parselet in restore!");
               nestedParselet = (NestedParselet) parselet;
            }
            if (nextChildParselet == null)
               nextChildParselet = nestedParselet;
            // Can't rely on parselet.newParseNode because of a weird case - <statement> an indexedChoice which returns ParentParseNode most of the time but ParseNode for a dangling ";" which has no semantic value presently
            ParseNode spnNode = new ParseNode();
            spnNode.setParselet(nestedParselet);
            spnNode.setStartIndex(parser.getCurrentIndex());
            spnNode.value = readChild(parser, nextChildParselet, rctx);
            return spnNode;
         case ParseOutStream.StringToken:
            // TODO: is this the best way to create a StringToken?  How will this work with the 'buffer' in Parser... will it ever be incremental?  seems like we should have the file as a byte array and point directly do that here to avoid pulling in extra stuff
            startIndex = readUInt();
            if (startIndex != parser.getCurrentIndex())
               throw new IllegalArgumentException("*** String token restored to wrong location!");
            int len = readUInt();
            StringToken st = new StringToken(parser, startIndex, len);
            parser.changeCurrentIndex(startIndex + len);
            return st;
         case ParseOutStream.String:
            try {
               String res = in.readUTF();
               parser.changeCurrentIndex(parser.getCurrentIndex() + res.length());
               return res;
            }
            catch (IOException exc) {
               throw new UncheckedIOException(exc);
            }
         default:
            throw new IllegalArgumentException("*** Unrecognized value in readChild");
      }
   }
/** Corresponds to a saveChild call in ParseOutStream */
Corresponds to a saveChild call in ParseOutStream
Corresponds to a saveChild call in ParseOutStream
public Object readChild(Parser parser, Parselet parselet, RestoreCtx rctx) {
      int pnType = readUInt();
      NestedParselet nestedParselet = null;
      Parselet nextChildParselet = null;
      switch (pnType) {
         case ParseOutStream.NullPN:
            return null;
         case ParseOutStream.ParentPNType:
            nestedParselet = (NestedParselet) getNextParselet(parser, rctx);
         case ParseOutStream.ParentPN:
            int sz = readUInt();
            if (nestedParselet == null)
               nestedParselet = (NestedParselet) parselet;
            int startIndex = parser.getCurrentIndex();
            if (nestedParselet == null)
               System.out.println("*** Error no parselet for parentPN");
            ParentParseNode ppn = nestedParselet.newParseNode(startIndex);
            for (int i = 0; i < sz; i++) {
               Parselet childParselet = nestedParselet.getChildParseletForIndex(i);
               if (childParselet == null) {
                  childParselet = getNextParselet(parser, rctx);
               }
               Object childPN = readChild(parser, childParselet, rctx);
               ppn.addGeneratedNode(childPN);
            }
            if (parser.getCurrentIndex() != startIndex + ppn.length())
               System.err.println("*** readChild - current index not updated properly during restore of parent");
            return ppn;
         case ParseOutStream.SinglePNType:
            nestedParselet = (NestedParselet) getNextParselet(parser, rctx);
            nextChildParselet = getNextParselet(parser, rctx);
         case ParseOutStream.SinglePN:
            if (nestedParselet == null) {
               if (!(parselet instanceof NestedParselet))
                  throw new IllegalArgumentException("*** Not a nested parselet in restore!");
               nestedParselet = (NestedParselet) parselet;
            }
            if (nextChildParselet == null)
               nextChildParselet = nestedParselet;
            ParseNode spnNode = new ParseNode();
            spnNode.setParselet(nestedParselet);
            spnNode.setStartIndex(parser.getCurrentIndex());
            spnNode.value = readChild(parser, nextChildParselet, rctx);
            return spnNode;
         case ParseOutStream.StringToken:
            startIndex = readUInt();
            if (startIndex != parser.getCurrentIndex())
               throw new IllegalArgumentException("*** String token restored to wrong location!");
            int len = readUInt();
            StringToken st = new StringToken(parser, startIndex, len);
            parser.changeCurrentIndex(startIndex + len);
            return st;
         case ParseOutStream.String:
            try {
               String res = in.readUTF();
               parser.changeCurrentIndex(parser.getCurrentIndex() + res.length());
               return res;
            }
            catch (IOException exc) {
               throw new UncheckedIOException(exc);
            }
         default:
            throw new IllegalArgumentException("*** Unrecognized value in readChild");
      }
   }
public Object readChild ( Parser parser , Parselet parselet , RestoreCtx rctx ) { int pnType = readUInt ( ) ; NestedParselet nestedParselet = null ; Parselet nextChildParselet = null ; switch ( pnType ) { case ParseOutStream . NullPN : return null ; case ParseOutStream . ParentPNType : nestedParselet = ( NestedParselet ) getNextParselet ( parser , rctx ) ; case ParseOutStream . ParentPN : int sz = readUInt ( ) ; if ( nestedParselet == null ) nestedParselet = ( NestedParselet ) parselet ; int startIndex = parser . getCurrentIndex ( ) ; if ( nestedParselet == null ) System . out . println ( "*** Error no parselet for parentPN" ) ; ParentParseNode ppn = nestedParselet . newParseNode ( startIndex ) ; for ( int i = 0 ; i < sz ; i ++ ) { Parselet childParselet = nestedParselet . getChildParseletForIndex ( i ) ; if ( childParselet == null ) { childParselet = getNextParselet ( parser , rctx ) ; } Object childPN = readChild ( parser , childParselet , rctx ) ; ppn . addGeneratedNode ( childPN ) ; } if ( parser . getCurrentIndex ( ) != startIndex + ppn . length ( ) ) System . err . println ( "*** readChild - current index not updated properly during restore of parent" ) ; return ppn ; case ParseOutStream . SinglePNType : nestedParselet = ( NestedParselet ) getNextParselet ( parser , rctx ) ; nextChildParselet = getNextParselet ( parser , rctx ) ; case ParseOutStream . SinglePN : if ( nestedParselet == null ) { if ( ! ( parselet instanceof NestedParselet ) ) throw new IllegalArgumentException ( "*** Not a nested parselet in restore!" ) ; nestedParselet = ( NestedParselet ) parselet ; } if ( nextChildParselet == null ) nextChildParselet = nestedParselet ; ParseNode spnNode = new ParseNode ( ) ; spnNode . setParselet ( nestedParselet ) ; spnNode . setStartIndex ( parser . getCurrentIndex ( ) ) ; spnNode . value = readChild ( parser , nextChildParselet , rctx ) ; return spnNode ; case ParseOutStream . StringToken : startIndex = readUInt ( ) ; if ( startIndex != parser . getCurrentIndex ( ) ) throw new IllegalArgumentException ( "*** String token restored to wrong location!" ) ; int len = readUInt ( ) ; StringToken st = new StringToken ( parser , startIndex , len ) ; parser . changeCurrentIndex ( startIndex + len ) ; return st ; case ParseOutStream . String : try { String res = in . readUTF ( ) ; parser . changeCurrentIndex ( parser . getCurrentIndex ( ) + res . length ( ) ) ; return res ; } catch ( IOException exc ) { throw new UncheckedIOException ( exc ) ; } default : throw new IllegalArgumentException ( "*** Unrecognized value in readChild" ) ; } }
Corresponds to a saveChild call in ParseOutStream
Corresponds to a saveChild call in ParseOutStream
// Fall through... // Need this to set the semantic value for qualifiedIdentifier //ppn.add(childPN, childParselet, -1, nestedParselet.getParseletSlotIx(childParselet), false, parser); // Fall through... // Can't rely on parselet.newParseNode because of a weird case - <statement> an indexedChoice which returns ParentParseNode most of the time but ParseNode for a dangling ";" which has no semantic value presently // TODO: is this the best way to create a StringToken?  How will this work with the 'buffer' in Parser... will it ever be incremental?  seems like we should have the file as a byte array and point directly do that here to avoid pulling in extra stuff