示例#1
0
 private Code readBinaryOp(
     int opcode,
     boolean wideBase,
     boolean wideRest,
     int offset,
     HashMap<Integer, Code.Label> labels)
     throws IOException {
   int leftOperand = readBase(wideBase);
   int rightOperand = readBase(wideBase);
   int typeIdx = readRest(wideRest);
   Type type = typePool[typeIdx];
   switch (opcode) {
     case Code.OPCODE_asserteq:
     case Code.OPCODE_assertne:
     case Code.OPCODE_assertlt:
     case Code.OPCODE_assertle:
     case Code.OPCODE_assertgt:
     case Code.OPCODE_assertge:
     case Code.OPCODE_assertel:
     case Code.OPCODE_assertss:
     case Code.OPCODE_assertse:
       {
         int msgIdx = readRest(wideRest);
         String msg = stringPool[msgIdx];
         Code.Comparator cop = Code.Comparator.values()[opcode - Code.OPCODE_asserteq];
         return Code.Assert(type, leftOperand, rightOperand, cop, msg);
       }
     case Code.OPCODE_assumeeq:
     case Code.OPCODE_assumene:
     case Code.OPCODE_assumelt:
     case Code.OPCODE_assumele:
     case Code.OPCODE_assumegt:
     case Code.OPCODE_assumege:
     case Code.OPCODE_assumeel:
     case Code.OPCODE_assumess:
     case Code.OPCODE_assumese:
       {
         int msgIdx = readRest(wideRest);
         String msg = stringPool[msgIdx];
         Code.Comparator cop = Code.Comparator.values()[opcode - Code.OPCODE_assumeeq];
         return Code.Assume(type, leftOperand, rightOperand, cop, msg);
       }
     case Code.OPCODE_ifeq:
     case Code.OPCODE_ifne:
     case Code.OPCODE_iflt:
     case Code.OPCODE_ifle:
     case Code.OPCODE_ifgt:
     case Code.OPCODE_ifge:
     case Code.OPCODE_ifel:
     case Code.OPCODE_ifss:
     case Code.OPCODE_ifse:
       {
         int target = readTarget(wideRest, offset);
         Code.Label l = findLabel(target, labels);
         Code.Comparator cop = Code.Comparator.values()[opcode - Code.OPCODE_ifeq];
         return Code.If(type, leftOperand, rightOperand, cop, l.label);
       }
   }
   throw new RuntimeException("unknown opcode encountered (" + opcode + ")");
 }
示例#2
0
  @Before
  public void init() {

    Nonterminal X = Nonterminal.withName("X");

    Nonterminal A = Nonterminal.withName("A");
    Nonterminal B = Nonterminal.withName("B");
    Nonterminal C = Nonterminal.withName("C");

    Rule r1 =
        Rule.withHead(X)
            .addSymbol(Nonterminal.builder(A).setLabel("a").build())
            .addSymbol(
                Star.builder(
                        Sequence.builder(
                                Code.code(
                                    Nonterminal.builder(B)
                                        .addPreCondition(predicate(equal(rExt("a"), lExt("b"))))
                                        .build(),
                                    stat(println(lExt("b")))),
                                Code.code(
                                    Nonterminal.builder(C).setLabel("b").build(),
                                    stat(println(var("b")))))
                            .build())
                    .setLabel("b")
                    .build())
            .build();

    Rule r2 = Rule.withHead(A).addSymbol(Terminal.from(Character.from('a'))).build();
    Rule r3 = Rule.withHead(B).addSymbol(Terminal.from(Character.from('b'))).build();
    Rule r4 = Rule.withHead(C).addSymbol(Terminal.from(Character.from('c'))).build();

    grammar = Grammar.builder().addRules(r1, r2, r3, r4).build();
  }
示例#3
0
 /**
  * Prints an entire subpopulation in a form readable by humans but also parseable by the computer
  * using readSubpopulation(EvolutionState, LineNumberReader).
  */
 public void printSubpopulation(final EvolutionState state, final PrintWriter writer) {
   writer.println(NUM_INDIVIDUALS_PREAMBLE + Code.encode(individuals.length));
   for (int i = 0; i < individuals.length; i++) {
     writer.println(INDIVIDUAL_INDEX_PREAMBLE + Code.encode(i));
     individuals[i].printIndividual(state, writer);
   }
 }
示例#4
0
 private Code readEmpty(
     int opcode,
     boolean wideBase,
     boolean wideRest,
     int offset,
     HashMap<Integer, Code.Label> labels)
     throws IOException {
   switch (opcode) {
     case Code.OPCODE_const:
       {
         int target = readBase(wideBase);
         int idx = readRest(wideRest);
         Constant c = constantPool[idx];
         return Code.Const(target, c);
       }
     case Code.OPCODE_goto:
       {
         int target = readTarget(wideRest, offset);
         Code.Label lab = findLabel(target, labels);
         return Code.Goto(lab.label);
       }
     case Code.OPCODE_nop:
       return Code.Nop;
     case Code.OPCODE_returnv:
       return Code.Return();
   }
   throw new RuntimeException("unknown opcode encountered (" + opcode + ")");
 }
示例#5
0
 /**
  * Prints an entire subpopulation in a form readable by humans but also parseable by the computer
  * using readSubpopulation(EvolutionState, LineNumberReader) with a verbosity of
  * Output.V_NO_GENERAL.
  */
 public void printSubpopulation(final EvolutionState state, final int log) {
   state.output.println(NUM_INDIVIDUALS_PREAMBLE + Code.encode(individuals.length), log);
   for (int i = 0; i < individuals.length; i++) {
     state.output.println(INDIVIDUAL_INDEX_PREAMBLE + Code.encode(i), log);
     individuals[i].printIndividual(state, log);
   }
 }
 /**
  * Display only the CRS name that contains the specified keywords. The {@code keywords} argument
  * is a space-separated list, usually provided by the user after he pressed the "Search" button.
  *
  * @param keywords space-separated list of keywords to look for.
  */
 private void filter(String keywords) {
   ListModel model = codeList;
   if (keywords != null) {
     final Locale locale = Locale.getDefault();
     keywords = keywords.toLowerCase(locale).trim();
     final String[] tokens = keywords.split("\\s+");
     if (tokens.length != 0) {
       final DefaultListModel filtered;
       model = filtered = new DefaultListModel();
       final int size = codeList.getSize();
       scan:
       for (int i = 0; i < size; i++) {
         final Code code = (Code) codeList.getElementAt(i);
         final String name = code.toString().toLowerCase(locale);
         for (int j = 0; j < tokens.length; j++) {
           if (name.indexOf(tokens[j]) < 0) {
             continue scan;
           }
         }
         filtered.addElement(code);
       }
     }
   }
   liste.setModel(model);
 }
示例#7
0
 public DocumentReference copy() {
   DocumentReference dst = new DocumentReference();
   dst.masterIdentifier = masterIdentifier == null ? null : masterIdentifier.copy();
   dst.identifier = new ArrayList<Identifier>();
   for (Identifier i : identifier) dst.identifier.add(i.copy());
   dst.subject = subject == null ? null : subject.copy();
   dst.type = type == null ? null : type.copy();
   dst.subtype = subtype == null ? null : subtype.copy();
   dst.author = new ArrayList<ResourceReference>();
   for (ResourceReference i : author) dst.author.add(i.copy());
   dst.custodian = custodian == null ? null : custodian.copy();
   dst.authenticator = authenticator == null ? null : authenticator.copy();
   dst.created = created == null ? null : created.copy();
   dst.indexed = indexed == null ? null : indexed.copy();
   dst.status = status == null ? null : status.copy();
   dst.docStatus = docStatus == null ? null : docStatus.copy();
   dst.supercedes = supercedes == null ? null : supercedes.copy();
   dst.description = description == null ? null : description.copy();
   dst.confidentiality = confidentiality == null ? null : confidentiality.copy();
   dst.primaryLanguage = primaryLanguage == null ? null : primaryLanguage.copy();
   dst.mimeType = mimeType == null ? null : mimeType.copy();
   dst.format = format == null ? null : format.copy();
   dst.size = size == null ? null : size.copy();
   dst.hash = hash == null ? null : hash.copy();
   dst.location = location == null ? null : location.copy();
   dst.service = service == null ? null : service.copy(dst);
   dst.context = context == null ? null : context.copy(dst);
   return dst;
 }
  @Override
  public void transform(Object object) {
    Code code = (Code) object;
    if (code != null) {

      if (deepSerialize) {
        try {
          code = (Code) xStream.fromXML(xStream.toXML(code));
        } catch (Exception ex) {
          deepSerialize = false;
        }
      }
      if (code != null) {
        CodeTransModel codeModel = new CodeTransModel();
        codeModel.setCode(code.getCode());
        codeModel.setCodeId(code.getCodeId());
        codeModel.setCodeType(code.getCodeType());
        codeModel.setLabel(code.getLabel());

        getContext().transform(codeModel);
      } else {
        LOGGER.error("Serialization failed for user group transformer");
        getContext().write(null);
      }
    }
  }
示例#9
0
 EncodedMethod toEncodedMethod(DexOptions dexOptions) {
   RopMethod ropMethod = new RopMethod(code.toBasicBlocks(), 0);
   LocalVariableInfo locals = null;
   DalvCode dalvCode =
       RopTranslator.translate(
           ropMethod, PositionList.NONE, locals, code.paramSize(), dexOptions);
   return new EncodedMethod(method.constant, flags, dalvCode, StdTypeList.EMPTY);
 }
示例#10
0
 Item invoke() {
   MethodType mtype = (MethodType) member.erasure(types);
   int argsize = Code.width(mtype.argtypes);
   int rescode = Code.typecode(mtype.restype);
   int sdiff = Code.width(rescode) - argsize;
   code.emitInvokestatic(pool.put(member), mtype);
   return stackItem[rescode];
 }
示例#11
0
 private static Code emit(Code lc, Expression le, Code rc, Expression re) {
   if (lc.isNull()) {
     return emit(rc, re, "is", lc, le);
   } else if (rc.isNull()) {
     return emit(lc, le, "is", rc, re);
   } else {
     return emit(lc, le, "=", rc, re);
   }
 }
示例#12
0
  public void visitCode(Code code) {
    code.accept(visitor);

    CodeException[] table = code.getExceptionTable();
    for (int i = 0; i < table.length; i++) table[i].accept(this);

    Attribute[] attributes = code.getAttributes();
    for (int i = 0; i < attributes.length; i++) attributes[i].accept(this);
  }
示例#13
0
 /**
  * The onKeyPress method handles all keys that were held down and then lifted up, after the
  * KeyDown and KeyUp events are triggered
  */
 @Override
 public void onKeyPress(KeyPressEvent event) {
   code = new Code(event);
   if (code.getCharCode() > 31 && code.getCharCode() < 127) {
     processCode(code);
     event.getNativeEvent().stopPropagation();
     event.getNativeEvent().preventDefault();
   }
 }
示例#14
0
 public void testTranslateACommand() {
   Code code = new Code();
   try {
     assertEquals("0000000000000000", code.translate(new ACommand("@0")));
     assertEquals("0000000000000001", code.translate(new ACommand("@1")));
     assertEquals("0111111111111111", code.translate(new ACommand("@32767")));
   } catch (IllegalCommandException ex) {
     fail("No exception should have been thrown.");
   }
   try {
     code.translate(new ACommand("@32768"));
     fail("This should fail, address too large.");
   } catch (IllegalCommandException ex) {
     assertTrue(true);
   }
   try {
     code.translate(new ACommand("@-1"));
     fail("This should fail, invalid address.");
   } catch (IllegalCommandException ex) {
     assertTrue(true);
   }
   // Examples from the book.
   try {
     assertEquals("0000000000010000", code.translate(new ACommand("@16")));
     assertEquals("0000000000010001", code.translate(new ACommand("@17")));
     assertEquals("0000000001100100", code.translate(new ACommand("@100")));
     assertEquals("0000000000010010", code.translate(new ACommand("@18")));
     assertEquals("0000000000000100", code.translate(new ACommand("@4")));
   } catch (IllegalCommandException ex) {
     fail("No exception should have been thrown.");
   }
 }
示例#15
0
 /**
  * The onKeyDown method handles all keys that are held down, before KeyUp and KeyPress events are
  * triggered.
  */
 @Override
 public void onKeyDown(KeyDownEvent event) {
   code = new Code(event);
   if (!code.isControlKey()) {
     if (code.isFunctionKey() || code.isCtrlDown() || code.isAltDown()) {
       processCode(code);
       event.getNativeEvent().stopPropagation();
       event.getNativeEvent().preventDefault();
     }
   }
 }
示例#16
0
 static {
   TreeMap<Integer, Status> canonicalizer = new TreeMap<Integer, Status>();
   for (Code code : Code.values()) {
     Status replaced = canonicalizer.put(code.value(), new Status(code));
     if (replaced != null) {
       throw new IllegalStateException(
           "Code value duplication between " + replaced.getCode().name() + " & " + code.name());
     }
   }
   STATUS_LIST = new ArrayList<Status>(canonicalizer.values());
 }
示例#17
0
 @Override
 public Code toCode() {
   StringBuilder b = new StringBuilder();
   b.append(lObjectName.inlineCode()).append("=");
   b.append(rObjectName.inlineCode());
   if (rMemberName != null) {
     b.append(".").append(rMemberName.inlineCode());
   }
   Code c = new Code();
   c.add(b.toString());
   return c;
 }
示例#18
0
 private static Code.LoopEnd findLoopLabel(int target, HashMap<Integer, Code.Label> labels) {
   Code.Label label = labels.get(target);
   if (label == null) {
     Code.LoopEnd end = Code.LoopEnd("label" + labelCount++);
     labels.put(target, end);
     return end;
   } else {
     Code.LoopEnd end = Code.LoopEnd(label.label);
     labels.put(target, end);
     return end;
   }
 }
示例#19
0
  public void step() {
    try {
      int opPart = code.getOpPart(cpu.pc);
      int arg = code.getArg(cpu.pc);

      Instruction.checkParity(opPart);
      INSTRUCTIONS[opPart / 8].execute(arg, opPart % 8);
    } catch (Exception e) {
      halt();
      throw e;
    }
  }
示例#20
0
文件: DoReturn.java 项目: godrin/pvm
  @Override
  public Code toCode() {
    Code c = new Code();
    String cmd = "lreturn";
    if (type == Type.FAR) {
      cmd = "freturn";
    } else if (type == Type.EXCEPTION) {
      cmd = "ereturn";
    }

    c.add(cmd + " " + name.inlineCode());
    return c;
  }
示例#21
0
 public void testSymbols() {
   Code code = new Code();
   try {
     assertEquals("0000000000010000", code.translate(new ACommand("@a")));
     assertEquals("0000000000010001", code.translate(new ACommand("@b")));
     assertEquals("0000000000010000", code.translate(new ACommand("@a")));
     assertEquals("0000000000010010", code.translate(new ACommand("@c")));
     assertEquals("0000000000010011", code.translate(new ACommand("@d")));
     assertEquals("0000000000010001", code.translate(new ACommand("@b")));
     assertEquals("0000000000010000", code.translate(new ACommand("@a")));
   } catch (IllegalCommandException ex) {
     fail("No exception should have been thrown.");
   }
 }
示例#22
0
 private boolean match(Attributes item, Code[] codes) {
   Sequence seq = item.getSequence(tag);
   if (seq != null)
     for (Attributes codeItem : seq) {
       try {
         Code val = new Code(codeItem);
         for (Code code : codes) {
           if (code.equals(val)) return !not;
         }
       } catch (NullPointerException npe) {
       }
     }
   return not;
 }
示例#23
0
  public New(int opcode, long start_byte, Code code) {
    super(opcode, start_byte, code);

    int _newindex = (params[0] << 8) | params[1];
    CONSTANT_Class cl_new_info = (CONSTANT_Class) code.getClazz().getConstant_pool()[_newindex];
    clazzName = cl_new_info.getFullyQualifiedName();
  }
示例#24
0
 Item coerce(int targetcode) {
   if (typecode == targetcode) {
     return this;
   } else {
     switch (targetcode) {
       case INTcode:
         if (Code.truncate(typecode) == INTcode) return this;
         else return new ImmediateItem(syms.intType, ((Number) value).intValue());
       case LONGcode:
         return new ImmediateItem(syms.longType, ((Number) value).longValue());
       case FLOATcode:
         return new ImmediateItem(syms.floatType, ((Number) value).floatValue());
       case DOUBLEcode:
         return new ImmediateItem(syms.doubleType, ((Number) value).doubleValue());
       case BYTEcode:
         return new ImmediateItem(syms.byteType, (int) (byte) ((Number) value).intValue());
       case CHARcode:
         return new ImmediateItem(syms.charType, (int) (char) ((Number) value).intValue());
       case SHORTcode:
         return new ImmediateItem(syms.shortType, (int) (short) ((Number) value).intValue());
       default:
         return super.coerce(targetcode);
     }
   }
 }
示例#25
0
/*     */     void sendReply(int paramInt, boolean paramBoolean, String paramString)
/*     */     {
/*     */       try
/*     */       {
/* 685 */         StringBuilder localStringBuilder = new StringBuilder(512);
/* 686 */         localStringBuilder.append("HTTP/1.1 ").append(paramInt).append(Code.msg(paramInt)).append("\r\n");
/*     */ 
/* 689 */         if ((paramString != null) && (paramString.length() != 0)) {
/* 690 */           localStringBuilder.append("Content-Length: ").append(paramString.length()).append("\r\n").append("Content-Type: text/html\r\n");
/*     */         }
/*     */         else
/*     */         {
/* 694 */           localStringBuilder.append("Content-Length: 0\r\n");
/* 695 */           paramString = "";
/*     */         }
/* 697 */         if (paramBoolean) {
/* 698 */           localStringBuilder.append("Connection: close\r\n");
/*     */         }
/* 700 */         localStringBuilder.append("\r\n").append(paramString);
/* 701 */         String str = localStringBuilder.toString();
/* 702 */         byte[] arrayOfByte = str.getBytes("ISO8859_1");
/* 703 */         this.rawout.write(arrayOfByte);
/* 704 */         this.rawout.flush();
/* 705 */         if (paramBoolean)
/* 706 */           ServerImpl.this.closeConnection(this.connection);
/*     */       }
/*     */       catch (IOException localIOException) {
/* 709 */         ServerImpl.this.logger.log(Level.FINER, "ServerImpl.sendReply", localIOException);
/* 710 */         ServerImpl.this.closeConnection(this.connection);
/*     */       }
/*     */     }
示例#26
0
 /**
  * Generate code to coerce item to given type code.
  *
  * @param targetcode The type code to coerce to.
  */
 Item coerce(int targetcode) {
   if (typecode == targetcode) return this;
   else {
     load();
     int typecode1 = Code.truncate(typecode);
     int targetcode1 = Code.truncate(targetcode);
     if (typecode1 != targetcode1) {
       int offset = targetcode1 > typecode1 ? targetcode1 - 1 : targetcode1;
       code.emitop0(i2l + typecode1 * 3 + offset);
     }
     if (targetcode != targetcode1) {
       code.emitop0(int2byte + targetcode - BYTEcode);
     }
     return stackItem[targetcode];
   }
 }
示例#27
0
 public SpecimenSourceComponent copy(Specimen e) {
   SpecimenSourceComponent dst = e.new SpecimenSourceComponent();
   dst.relationship = relationship == null ? null : relationship.copy();
   dst.target = new ArrayList<ResourceReference>();
   for (ResourceReference i : target) dst.target.add(i.copy());
   return dst;
 }
示例#28
0
 public void addChild(Code code) {
   if (code instanceof BlockCode) {
     lines.addAll(((BlockCode) code).lines);
   } else {
     lines.add(code.getSource());
   }
 }
  /**
   * Dumps the contents of the specified class to the specified directory. The file is named
   * dump_dir/[class].bcel. It contains a synopsis of the fields and methods followed by the jvm
   * code for each method.
   *
   * @param jc javaclass to dump
   * @param dump_dir directory in which to write the file
   */
  public static void dump(JavaClass jc, File dump_dir) {

    try {
      dump_dir.mkdir();
      File path = new File(dump_dir, jc.getClassName() + ".bcel");
      PrintStream p = new PrintStream(path);

      // Print the class, super class and interfaces
      p.printf("class %s extends %s\n", jc.getClassName(), jc.getSuperclassName());
      String[] inames = jc.getInterfaceNames();
      if ((inames != null) && (inames.length > 0)) {
        p.printf("   ");
        for (String iname : inames) p.printf("implements %s ", iname);
        p.printf("\n");
      }

      // Print each field
      p.printf("\nFields\n");
      for (Field f : jc.getFields()) p.printf("  %s\n", f);

      // Print the signature of each method
      p.printf("\nMethods\n");
      for (Method m : jc.getMethods()) p.printf("  %s\n", m);

      // If this is not an interface, print the code for each method
      if (!jc.isInterface()) {
        for (Method m : jc.getMethods()) {
          p.printf("\nMethod %s\n", m);
          Code code = m.getCode();
          if (code != null) p.printf("  %s\n", code.toString().replace("\n", "\n  "));
        }
      }

      // Print the details of the constant pool.
      p.printf("Constant Pool:\n");
      ConstantPool cp = jc.getConstantPool();
      Constant[] constants = cp.getConstantPool();
      for (int ii = 0; ii < constants.length; ii++) {
        p.printf("  %d %s\n", ii, constants[ii]);
      }

      p.close();

    } catch (Exception e) {
      throw new Error("Unexpected error dumping javaclass", e);
    }
  }
示例#30
0
 private static Code.Label findLabel(int target, HashMap<Integer, Code.Label> labels) {
   Code.Label label = labels.get(target);
   if (label == null) {
     label = Code.Label("label" + labelCount++);
     labels.put(target, label);
   }
   return label;
 }