Example #1
1
 public final java_cup.runtime.Symbol do_action(
     int CUP$parser$act_num,
     java_cup.runtime.lr_parser CUP$parser$parser,
     java.util.Stack CUP$parser$stack,
     int CUP$parser$top,
     parser parser)
     throws java.lang.Exception {
   java_cup.runtime.Symbol CUP$parser$result;
   // c_pointer ::= P_STAR c_pointer
   {
     Pointer RESULT = null;
     Token rl =
         (Token) ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top - 1)).value;
     Pointer p = (Pointer) ((java_cup.runtime.Symbol) CUP$parser$stack.peek()).value;
     RESULT = new Pointer(null, p);
     RESULT.setLeft(rl.getLeft());
     CUP$parser$result =
         parser
             .getSymbolFactory()
             .newSymbol(
                 "c_pointer",
                 105,
                 ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top - 1)),
                 ((java_cup.runtime.Symbol) CUP$parser$stack.peek()),
                 RESULT);
   }
   return CUP$parser$result;
 }
  /**
   * Start at the given nesting level - read lines until you get to line with equal to or greater
   * than the current one.
   */
  public static String[] getArtifactLines(Pointer startingIndex, String... lines) {
    List<String> lineList = new ArrayList<>();
    int index = startingIndex.getIndex();
    String topLine = lines[index];

    lineList.add(
        topLine); // add the line which defines this object - all others, if they exist, are
                  // children.

    int nestingLevel = parseNestingLevel(topLine);

    for (int i = index + 1; i < lines.length; i++) {
      String line = lines[i];

      // we return if the nesting level of the line in question is the same as the "parent" level
      int childNestingLevel = parseNestingLevel(line);

      if (childNestingLevel == nestingLevel) {
        startingIndex.increment(lineList.size());

        // return new array of startIndex to i
        return lineList.toArray(new String[lineList.size()]);
      } else {
        lineList.add(line);
      }
    }

    startingIndex.increment(lineList.size());

    return lineList.toArray(new String[lineList.size()]);
  }
 private static Set<Long> findAdverbAntonyms(Dictionary dic) throws SMatchException {
   log.info("Creating adverb antonyms array...");
   try {
     Set<Long> keys = new HashSet<>();
     int count = 0;
     Iterator<Synset> it = dic.getSynsetIterator(POS.ADVERB);
     while (it.hasNext()) {
       count++;
       if (0 == count % 1000) {
         log.debug("adverb antonyms: " + count);
       }
       Synset source = it.next();
       long sourceOffset = source.getOffset();
       List<Pointer> pointers = source.getPointers(PointerType.ANTONYM);
       for (Pointer ptr : pointers) {
         long targetOffset = ptr.getTargetOffset();
         long key;
         if (targetOffset > sourceOffset) {
           key = (targetOffset << 32) + sourceOffset;
         } else {
           key = (sourceOffset << 32) + targetOffset;
         }
         keys.add(key);
       }
     }
     log.info("Adverbs antonyms: " + keys.size());
     return keys;
   } catch (JWNLException e) {
     throw new SMatchException(e.getClass().getSimpleName() + ": " + e.getMessage(), e);
   }
 }
 private static Set<Long> findNominalizations(Dictionary dic) throws SMatchException {
   log.info("Creating nominalizations array...");
   try {
     Set<Long> keys = new HashSet<>();
     int count = 0;
     Iterator<Synset> it = dic.getSynsetIterator(POS.VERB);
     while (it.hasNext()) {
       count++;
       if (0 == count % 1000) {
         log.debug("nominalizations: " + count);
       }
       Synset source = it.next();
       List<Pointer> pointers = source.getPointers(PointerType.DERIVATION);
       for (Pointer pointer : pointers) {
         if (POS.NOUN.equals(pointer.getTargetPOS())) {
           long targetOffset = pointer.getTargetOffset();
           long key = (source.getOffset() << 32) + targetOffset;
           keys.add(key);
         }
       }
     }
     log.info("Nominalizations: " + keys.size());
     return keys;
   } catch (JWNLException e) {
     throw new SMatchException(e.getClass().getSimpleName() + ": " + e.getMessage(), e);
   }
 }
Example #5
0
 public hostent gethostbyname(String arg0) {
   Pointer var0 = Pointer.createStringBuffer(arg0);
   int result0 = gethostbynamePtr.call1(var0);
   hostent result = (hostent) Function.returnStruct(hostent.class, result0);
   var0.free();
   return result;
 }
Example #6
0
 private void checkPointers() {
   if (null != dictionary && dictionary.getCheckAlienPointers() && !checkingPointers) {
     synchronized (this) {
       checkingPointers = true;
       if (null != dictionary && dictionary.isEditable()) {
         List<Pointer> toDelete = null;
         for (int i = 0; i < super.size(); i++) {
           Pointer pointer = super.get(i);
           if (dictionary != pointer.getSource().getDictionary()
               || null == pointer.getTarget()
               || dictionary != pointer.getTarget().getDictionary()) {
             if (null == toDelete) {
               toDelete = new ArrayList<Pointer>();
             }
             toDelete.add(pointer);
           }
         }
         if (null != toDelete) {
           if (log.isWarnEnabled() && 0 < toDelete.size()) {
             log.warn(JWNL.resolveMessage("DICTIONARY_WARN_002", Synset.this.getOffset()));
           }
           for (Pointer pointer : toDelete) {
             remove(pointer);
           }
         }
       }
       checkingPointers = false;
     }
   }
 }
  private static final void releasePointerList(Pointer pointer) {
    if (pointer != null) {
      synchronized (sPool) {
        int count = sRecycledPointerCount;
        if (count >= POINTER_POOL_CAPACITY) {
          return;
        }

        Pointer tail = pointer;
        for (; ; ) {
          count += 1;
          if (count >= POINTER_POOL_CAPACITY) {
            break;
          }

          Pointer next = tail.next;
          if (next == null) {
            break;
          }
          tail = next;
        }

        tail.next = sRecycledPointerListHead;
        sRecycledPointerCount = count;
        sRecycledPointerListHead = pointer;
      }
    }
  }
Example #8
0
 @Test
 public void testPassFloats() {
   Pointer<Byte> out = allocateBytes(8);
   for (int value : intValues) {
     passVarArgs(out, false, (float) value);
     assertEquals(value, out.getDouble(), 0);
   }
 }
Example #9
0
 @Test
 public void testPassBytes() {
   Pointer<Byte> out = allocateBytes(8);
   for (int value : intValues) {
     passVarArgs(out, true, (byte) value);
     assertEquals(value, out.getSizeT());
   }
 }
Example #10
0
 @Test
 public void testSPrintf() {
   Pointer<Byte> dest = allocateBytes(100);
   String fmtString = "Hello %d !";
   int value = 10;
   sprintf(dest, pointerToCString(fmtString), value);
   assertEquals(String.format(fmtString, value), dest.getCString());
 }
Example #11
0
 public Branch execute(Processor cpu) {
   cpu.flagOp1 = op1.get32(cpu);
   cpu.flagResult = (-cpu.flagOp1);
   op1.set32(cpu, cpu.flagResult);
   cpu.flagIns = UCodes.NEG32;
   cpu.flagStatus = OSZAPC;
   return Branch.None;
 }
Example #12
0
 @Test
 public void testPassBools() {
   Pointer<Byte> out = allocateBytes(8);
   for (boolean value : new boolean[] {true, false}) {
     passVarArgs(out, true, value);
     assertEquals(value, out.getSizeT() != 0);
   }
 }
Example #13
0
  // TODO: This should play all pointers, not just the first one.
  public void playback(MouseRecord Record) {
    Pointer o = _pointers.get(0);

    o.current = Record.button;
    wheel = Record.wheel;
    o.screenPosition.x = Record.x;
    o.screenPosition.y = Record.y;
    updateCursor();
  }
Example #14
0
 public Branch execute(Processor cpu) {
   cpu.flagOp1 = (short) op1.get16(cpu);
   cpu.flagOp2 = (short) immw;
   cpu.flagResult = (short) (cpu.flagOp1 - cpu.flagOp2);
   op1.set16(cpu, (short) cpu.flagResult);
   cpu.flagIns = UCodes.SUB16;
   cpu.flagStatus = OSZAPC;
   return Branch.None;
 }
Example #15
0
  /**
   * Event handler so FlxGame can update the pointer.
   *
   * @param Event A <code>TouchEvent</code> object.
   */
  public void handleMouseUp(TouchEvent Event) {
    if (Event.touchPointID >= _pointers.size) _pointers.add(new Pointer());

    Pointer o = _pointers.get(Event.touchPointID);

    if (o.current > 0) o.current = -1;
    else o.current = 0;

    activePointers--;
  }
Example #16
0
 public Branch execute(Processor cpu) {
   Reg op1 = cpu.regs[op1Index];
   if (op2.get16(cpu) == 0) {
     cpu.zf(true);
   } else {
     cpu.zf(false);
     op1.set16(31 - StaticOpcodes.numberOfLeadingZeros(0xFFFF & op2.get16(cpu)));
   }
   return Branch.None;
 }
Example #17
0
  public void testLookupGlobalVariable() {
    NativeLibrary lib = NativeLibrary.getInstance("testlib");
    Pointer global = lib.getGlobalVariableAddress("test_global");
    assertNotNull("Test variable not found", global);
    final int MAGIC = 0x12345678;
    assertEquals("Wrong value for library global variable", MAGIC, global.getInt(0));

    global.setInt(0, MAGIC + 1);
    assertEquals("Library global variable not updated", MAGIC + 1, global.getInt(0));
  }
 /**
  * Returns the block of size equal or greater than current size for reallocation which is marked
  * as free.
  *
  * @param capacity
  * @return null when it fails to search a valid sized block
  */
 private Pointer firstMatch(int capacity) {
   synchronized (pointers) {
     for (Pointer ptr : pointers) {
       // Find a frame with right size. Comapaction problems to be dealt.
       if (ptr.isFree() && (ptr.getEnd() - ptr.getStart()) > capacity) {
         return ptr;
       }
     }
   }
   return null;
 }
Example #19
0
 public Branch execute(Processor cpu) {
   Reg op2 = cpu.regs[op2Index];
   int add = (cpu.cf() ? 1 : 0);
   cpu.flagOp1 = op1.get8(cpu);
   cpu.flagOp2 = op2.get8();
   cpu.flagResult = (byte) (cpu.flagOp1 - (cpu.flagOp2 + add));
   op1.set8(cpu, (byte) cpu.flagResult);
   cpu.flagIns = UCodes.SBB8;
   cpu.flagStatus = OSZAPC;
   return Branch.None;
 }
Example #20
0
 /**
  * Call the native function being represented by this object
  *
  * @param callFlags calling convention to be used
  * @param args Arguments to pass to the native function
  * @param wide whether the native string uses <code>wchar_t</code>; if false, <code>char</code> is
  *     assumed
  * @return The value returned by the target native function, as a String
  */
 private String invokeString(int callFlags, Object[] args, boolean wide) {
   Pointer ptr = invokePointer(callFlags, args);
   String s = null;
   if (ptr != null) {
     if (wide) {
       s = ptr.getWideString(0);
     } else {
       s = ptr.getString(0, encoding);
     }
   }
   return s;
 }
 private static final Pointer obtainPointer() {
   synchronized (sPool) {
     if (sRecycledPointerCount != 0) {
       Pointer element = sRecycledPointerListHead;
       sRecycledPointerCount -= 1;
       sRecycledPointerListHead = element.next;
       element.next = null;
       return element;
     }
   }
   return new Pointer();
 }
Example #22
0
  // TODO: This should record all pointers, not just the first one.
  public MouseRecord record() {
    Pointer o = _pointers.get(0);

    if ((o.lastX == o.screenPosition.x)
        && (o.lastY == o.screenPosition.y)
        && (o.current == 0)
        && (_lastWheel == wheel)) return null;
    o.lastX = (int) o.screenPosition.x;
    o.lastY = (int) o.screenPosition.y;
    _lastWheel = wheel;
    return new MouseRecord(o.lastX, o.lastY, o.current, _lastWheel);
  }
Example #23
0
 public Branch execute(Processor cpu) {
   int shift = 1 & 0x1f;
   shift %= 16 + 1;
   long val = 0xFFFF & op1.get16(cpu);
   val |= cpu.cf() ? 1L << 16 : 0;
   val = (val << shift) | (val >>> (16 + 1 - shift));
   op1.set16(cpu, (short) (int) val);
   boolean bit31 = (val & (1L << (16 - 1))) != 0;
   boolean bit32 = (val & (1L << (16))) != 0;
   cpu.cf(bit32);
   if (shift == 1) cpu.of(bit31 ^ bit32);
   return Branch.None;
 }
 /*
  * (non-Javadoc)
  *
  * @see com.prashant.memory.MemoryBuffer#update(com.prashant.memory.Pointer, byte[], int)
  */
 public void update(Pointer pointer, byte[] payload, int offset)
     throws DMFrameLimitExcededException {
   if (pointer.getStart() + offset + payload.length - 1 <= pointer.getEnd()) {
     ByteBuffer buf;
     synchronized (buffer) {
       buf = buffer.duplicate();
     }
     buf.position(pointer.getStart() + offset);
     buf.put(payload);
     return;
   }
   throw new DMFrameLimitExcededException(
       "Trying to write to a position out of bounds for this pointer.", null);
 }
Example #25
0
 public Branch execute(Processor cpu) {
   int shift = cpu.r_cl.get8() & (16 - 1);
   int reg0 = 0xFFFF & op1.get16(cpu);
   int res = (reg0 << shift) | (reg0 >>> (16 - shift));
   op1.set16(cpu, (short) res);
   boolean bit0 = (res & 1) != 0;
   boolean bit31 = (res & (1 << (16 - 1))) != 0;
   if ((0x1F & cpu.r_cl.get8()) > 0) {
     cpu.cf = bit0;
     cpu.of = bit0 ^ bit31;
     cpu.flagStatus &= NOFCF;
   }
   return Branch.None;
 }
Example #26
0
 @Override
 public boolean retainAll(Collection<?> c) {
   if (null != dictionary && dictionary.isEditable()) {
     List<Pointer> copy = new ArrayList<Pointer>(this);
     boolean result = super.retainAll(c);
     for (Object object : c) {
       if (object instanceof Pointer) {
         Pointer pointer = (Pointer) object;
         if (!copy.contains(pointer)) {
           // delete symmetric pointer from the target
           if (null != pointer.getType().getSymmetricType()
               && dictionary.getManageSymmetricPointers()) {
             for (Pointer p : pointer.getTargetSynset().getPointers()) {
               if (offset == p.getTargetOffset()
                   && pointer.getType().getSymmetricType().equals(p.getType())) {
                 pointer.getTargetSynset().getPointers().remove(p);
                 break;
               }
             }
           }
         }
       }
     }
     return result;
   } else {
     return super.retainAll(c);
   }
 }
Example #27
0
 public boolean isValid() {
   Pointer<Integer> pCount = allocateInt();
   int err;
   try {
     err = clIcdGetPlatformIDsKHR(0, null, pCount);
   } catch (Throwable th) {
     try {
       err = clGetPlatformIDs(0, null, pCount);
     } catch (Throwable th2) {
       return false;
     }
   }
   return err == OpenCLLibrary.CL_SUCCESS && pCount.get() > 0;
 }
Example #28
0
 public Branch execute(Processor cpu) {
   int shift = immb & (32 - 1);
   int reg0 = op1.get32(cpu);
   int res = (reg0 >>> shift) | (reg0 << (32 - shift));
   op1.set32(cpu, res);
   boolean bit30 = (res & (1 << (32 - 2))) != 0;
   boolean bit31 = (res & (1 << (32 - 1))) != 0;
   if (shift > 0) {
     cpu.cf = bit31;
     cpu.of = bit30 ^ bit31;
     cpu.flagStatus &= NOFCF;
   }
   return Branch.None;
 }
 /*
  * (non-Javadoc)
  *
  * @see com.prashant.memory.MemoryBuffer#retrieve(com.prashant.memory.Pointer, int, int)
  */
 public byte[] retrieve(Pointer pointer, int offset, int len) throws DMFrameLimitExcededException {
   int checkLength = pointer.getStart() + offset + len;
   ByteBuffer buf = null;
   if (checkLength <= pointer.getEnd()) {
     synchronized (buffer) {
       buf = buffer.duplicate();
     }
     buf.position(pointer.getStart() + offset);
     final byte[] swp = new byte[len];
     buf.get(swp);
     return swp;
   }
   throw new DMFrameLimitExcededException(
       "Trying to read to a position out of bounds for this pointer.", null);
 }
Example #30
0
 public Branch execute(Processor cpu) {
   cpu.flagOp1 = (byte) op1.get8(cpu);
   cpu.flagOp2 = (byte) immb;
   cpu.flagResult = (byte) (cpu.flagOp1 - cpu.flagOp2);
   cpu.flagIns = UCodes.SUB8;
   cpu.flagStatus = OSZAPC;
   return Branch.None;
 }