Пример #1
0
 /** Prepend given list of elements to front of list, forming and returning a new list. */
 public List<A> prependList(List<A> xs) {
   if (this.isEmpty()) return xs;
   if (xs.isEmpty()) return this;
   if (xs.tail.isEmpty()) return prepend(xs.head);
   // return this.prependList(xs.tail).prepend(xs.head);
   List<A> result = this;
   List<A> rev = xs.reverse();
   Assert.check(rev != xs);
   // since xs.reverse() returned a new list, we can reuse the
   // individual List objects, instead of allocating new ones.
   while (rev.nonEmpty()) {
     List<A> h = rev;
     rev = rev.tail;
     h.setTail(result);
     result = h;
   }
   return result;
 }
Пример #2
0
 /**
  * Count trailing zero bits in an int. Algorithm from "Hacker's Delight" by Henry S. Warren Jr.
  * (figure 5-13)
  */
 private static int trailingZeroBits(int x) {
   Assert.check(wordlen == 32);
   if (x == 0) return 32;
   int n = 1;
   if ((x & 0xffff) == 0) {
     n += 16;
     x >>>= 16;
   }
   if ((x & 0x00ff) == 0) {
     n += 8;
     x >>>= 8;
   }
   if ((x & 0x000f) == 0) {
     n += 4;
     x >>>= 4;
   }
   if ((x & 0x0003) == 0) {
     n += 2;
     x >>>= 2;
   }
   return n - (x & 1);
 }
        @Override
        public Void visitTypeVar(TypeVar t, Void ignored) {
          if (indexOf(t, WhereClauseKind.TYPEVAR) == -1) {
            // access the bound type and skip error types
            Type bound = t.bound;
            while ((bound instanceof ErrorType)) bound = ((ErrorType) bound).getOriginalType();
            // retrieve the bound list - if the type variable
            // has not been attributed the bound is not set
            List<Type> bounds =
                (bound != null && bound.tsym != null) ? types.getBounds(t) : List.<Type>nil();

            nameSimplifier.addUsage(t.tsym);

            boolean boundErroneous =
                bounds.head == null || bounds.head.tag == NONE || bounds.head.tag == ERROR;

            if ((t.tsym.flags() & SYNTHETIC) == 0) {
              // this is a true typevar
              JCDiagnostic d =
                  diags.fragment(
                      "where.typevar" + (boundErroneous ? ".1" : ""),
                      t,
                      bounds,
                      Kinds.kindName(t.tsym.location()),
                      t.tsym.location());
              whereClauses.get(WhereClauseKind.TYPEVAR).put(t, d);
              symbolPreprocessor.visit(t.tsym.location(), null);
              visit(bounds);
            } else {
              Assert.check(!boundErroneous);
              // this is a fresh (synthetic) tvar
              JCDiagnostic d = diags.fragment("where.fresh.typevar", t, bounds);
              whereClauses.get(WhereClauseKind.TYPEVAR).put(t, d);
              visit(bounds);
            }
          }
          return null;
        }
Пример #4
0
 /** Include x in this set. */
 public void incl(int x) {
   Assert.check(x >= 0);
   sizeTo((x >>> wordshift) + 1);
   bits[x >>> wordshift] = bits[x >>> wordshift] | (1 << (x & wordmask));
 }
Пример #5
0
 /**
  * Replace the specified diagnostic handler with the handler that was current at the time this
  * handler was created. The given handler must be the currently installed handler; it must be
  * specified explicitly for clarity and consistency checking.
  */
 public void popDiagnosticHandler(DiagnosticHandler h) {
   Assert.check(diagnosticHandler == h);
   diagnosticHandler = h.prev;
 }
 public String formatPosition(JCDiagnostic d, PositionKind pk, Locale l) {
   Assert.check(d.getPosition() != Position.NOPOS);
   return String.valueOf(getPosition(d, pk));
 }