com.sun.tools.javac.tree.JCTree.Tag Java Examples

The following examples show how to use com.sun.tools.javac.tree.JCTree.Tag. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JavacBinder.java    From manifold with Apache License 2.0 6 votes vote down vote up
@Override
protected Symbol.MethodSymbol findBinderMethod( Node<JCExpression, Tag> left, Node<JCExpression, Tag> right )
{
  Type lhs = left._expr.type;
  Type rhs = right._expr.type;
  Pair<Type, Type> pair = Pair.make( lhs, rhs );
  if( right._operatorLeft == null && _mapReactions.containsKey( pair ) )
  {
    return _mapReactions.get( pair );
  }
  Symbol.MethodSymbol reaction = getReaction( lhs, rhs, right._operatorLeft );
  if( right._operatorLeft == null )
  {
    _mapReactions.put( pair, reaction );
  }
  return reaction;
}
 
Example #2
Source File: ManAttr.java    From manifold with Apache License 2.0 6 votes vote down vote up
default boolean handleNegationOverloading( JCTree.JCUnary tree )
{
  if( tree.getTag() != Tag.NEG )
  {
    return false;
  }

  // Attribute arguments
  ReflectUtil.LiveMethodRef checkNonVoid = ReflectUtil.method( chk(), "checkNonVoid", JCDiagnostic.DiagnosticPosition.class, Type.class );
  ReflectUtil.LiveMethodRef attribExpr = ReflectUtil.method( this, "attribExpr", JCTree.class, Env.class );
  Type expr = (Type)checkNonVoid.invoke( tree.arg.pos(), attribExpr.invoke( tree.arg, getEnv() ) );

  // Handle operator overloading
  Symbol.MethodSymbol overloadOperator = ManAttr.resolveNegationMethod( types(), tree.getTag(), expr );
  if( overloadOperator != null )
  {
    overloadOperator = new OverloadOperatorSymbol( overloadOperator, false );
    IDynamicJdk.instance().setOperator( tree, (Symbol.OperatorSymbol)overloadOperator );
    Type owntype = overloadOperator.type.isErroneous()
                   ? overloadOperator.type
                   : types().memberType( expr, overloadOperator ).getReturnType();
    setResult( tree, owntype );
    return true;
  }
  return false;
}
 
Example #3
Source File: JavacBinder.java    From manifold with Apache License 2.0 6 votes vote down vote up
private Symbol.MethodSymbol getReaction( Type lhs, Type rhs, Tag operator )
{
  if( operator != null )
  {
    return resolveOperatorMethod( lhs, rhs, operator );
  }
  else
  {
    Symbol.MethodSymbol binder = resolveBinderMethod( "prefixBind", lhs, rhs );
    if( binder == null )
    {
      binder = resolveBinderMethod( "postfixBind", rhs, lhs );
    }
    return binder;
  }
}
 
Example #4
Source File: Lower.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/** Lower a tree of the form e++ or e-- where e is an object type */
JCExpression lowerBoxedPostop(final JCUnary tree) {
    // translate to tmp1=lval(e); tmp2=tmp1; tmp1 OP 1; tmp2
    // or
    // translate to tmp1=lval(e); tmp2=tmp1; (typeof tree)tmp1 OP 1; tmp2
    // where OP is += or -=
    final boolean cast = TreeInfo.skipParens(tree.arg).hasTag(TYPECAST);
    return abstractLval(tree.arg, tmp1 -> abstractRval(tmp1, tree.arg.type, tmp2 -> {
        Tag opcode = (tree.hasTag(POSTINC))
            ? PLUS_ASG : MINUS_ASG;
        //"tmp1" and "tmp2" may refer to the same instance
        //(for e.g. <Class>.super.<ident>). But further processing may
        //change the components of the tree in place (see visitSelect),
        //so cloning the tree to avoid interference between the two uses:
        JCExpression lhs = (JCExpression)tmp1.clone();
        lhs = cast
            ? make.TypeCast(tree.arg.type, lhs)
            : lhs;
        JCExpression update = makeAssignop(opcode,
                                     lhs,
                                     make.Literal(1));
        return makeComma(update, tmp2);
    }));
}
 
Example #5
Source File: JavacBinder.java    From manifold with Apache License 2.0 6 votes vote down vote up
@Override
protected Node<JCExpression, Tag> makeBinaryExpression( Node<JCExpression, Tag> left,
                                                        Node<JCExpression, Tag> right,
                                                        Symbol.MethodSymbol binderMethod )
{
  JCBinary binary = _make.Binary( right._operatorLeft == null
                                  ? Tag.MUL
                                  : right._operatorLeft, left._expr, right._expr );
  binary.pos = left._expr.pos;
  boolean rightToLeft =
    binderMethod instanceof OverloadOperatorSymbol && ((OverloadOperatorSymbol)binderMethod).isSwapped() ||
    binderMethod.name.toString().equals( "postfixBind" );
  IDynamicJdk.instance().setOperator( binary, new OverloadOperatorSymbol( binderMethod, rightToLeft ) );
  binary.type = rightToLeft
                ? memberType( right._expr.type, left._expr.type, binderMethod )
                : memberType( left._expr.type, right._expr.type, binderMethod );
  return new Node<>( binary, left._operatorLeft );
}
 
Example #6
Source File: Symbol.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
static int from(Tag tag, int opcode) {
    /** Map bytecode of binary operation to access code of corresponding
    *  assignment operation. This is always an even number.
    */
    switch (tag) {
        case PREINC:
            return AccessCode.PREINC.code;
        case PREDEC:
            return AccessCode.PREDEC.code;
        case POSTINC:
            return AccessCode.POSTINC.code;
        case POSTDEC:
            return AccessCode.POSTDEC.code;
    }
    if (iadd <= opcode && opcode <= lxor) {
        return (opcode - iadd) * 2 + FIRSTASGOP.code;
    } else if (opcode == string_add) {
        return (lxor + 1 - iadd) * 2 + FIRSTASGOP.code;
    } else if (ishll <= opcode && opcode <= lushrl) {
        return (opcode - ishll + lxor + 2 - iadd) * 2 + FIRSTASGOP.code;
    }
    return -1;
}
 
Example #7
Source File: TransTypes.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void visitTypeCast(JCTypeCast tree) {
    tree.clazz = translate(tree.clazz, null);
    Type originalTarget = tree.type;
    tree.type = erasure(tree.type);
    JCExpression newExpression = translate(tree.expr, tree.type);
    if (newExpression != tree.expr) {
        JCTypeCast typeCast = newExpression.hasTag(Tag.TYPECAST)
            ? (JCTypeCast) newExpression
            : null;
        tree.expr = typeCast != null && types.isSameType(typeCast.type, originalTarget, true)
            ? typeCast.expr
            : newExpression;
    }
    if (originalTarget.isIntersection()) {
        Type.IntersectionClassType ict = (Type.IntersectionClassType)originalTarget;
        for (Type c : ict.getExplicitComponents()) {
            Type ec = erasure(c);
            if (!types.isSameType(ec, tree.type)) {
                tree.expr = coerce(tree.expr, ec);
            }
        }
    }
    result = tree;
}
 
Example #8
Source File: JavacBinder.java    From manifold with Apache License 2.0 6 votes vote down vote up
private Symbol.MethodSymbol resolveOperatorMethod( Type left, Type right, Tag operator )
{
  // Handle operator overloading

  boolean swapped = false;
  Symbol.MethodSymbol overloadOperator = ManAttr.resolveOperatorMethod( _types, operator, left, right );
  if( overloadOperator == null && ManAttr.isCommutative( operator ) )
  {
    overloadOperator = ManAttr.resolveOperatorMethod( _types, operator, right, left );
    swapped = true;
  }
  if( overloadOperator != null )
  {
    return new OverloadOperatorSymbol( overloadOperator, swapped );
  }

  return null;
}
 
Example #9
Source File: JavacProcessingEnvironment.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void visitClassDef(JCClassDecl node) {
    super.visitClassDef(node);
    // remove generated constructor that may have been added during attribution:
    List<JCTree> beforeConstructor = List.nil();
    List<JCTree> defs = node.defs;
    while (defs.nonEmpty() && !defs.head.hasTag(Tag.METHODDEF)) {
        beforeConstructor = beforeConstructor.prepend(defs.head);
        defs = defs.tail;
    }
    if (defs.nonEmpty() &&
        (((JCMethodDecl) defs.head).mods.flags & Flags.GENERATEDCONSTR) != 0) {
        defs = defs.tail;
        while (beforeConstructor.nonEmpty()) {
            defs = defs.prepend(beforeConstructor.head);
            beforeConstructor = beforeConstructor.tail;
        }
        node.defs = defs;
    }
    if (node.sym != null) {
        node.sym.completer = new ImplicitCompleter(topLevel);
    }
    node.sym = null;
}
 
Example #10
Source File: TypeAnnotations.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private int methodParamIndex(List<JCTree> path, JCTree param) {
    List<JCTree> curr = path;
    while (curr.head.getTag() != Tag.METHODDEF &&
            curr.head.getTag() != Tag.LAMBDA) {
        curr = curr.tail;
    }
    if (curr.head.getTag() == Tag.METHODDEF) {
        JCMethodDecl method = (JCMethodDecl)curr.head;
        return method.params.indexOf(param);
    } else if (curr.head.getTag() == Tag.LAMBDA) {
        JCLambda lambda = (JCLambda)curr.head;
        return lambda.params.indexOf(param);
    } else {
        Assert.error("methodParamIndex expected to find method or lambda for param: " + param);
        return -1;
    }
}
 
Example #11
Source File: Symbol.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
static int from(Tag tag, int opcode) {
    /** Map bytecode of binary operation to access code of corresponding
    *  assignment operation. This is always an even number.
    */
    switch (tag) {
        case PREINC:
            return AccessCode.PREINC.code;
        case PREDEC:
            return AccessCode.PREDEC.code;
        case POSTINC:
            return AccessCode.POSTINC.code;
        case POSTDEC:
            return AccessCode.POSTDEC.code;
    }
    if (iadd <= opcode && opcode <= lxor) {
        return (opcode - iadd) * 2 + FIRSTASGOP.code;
    } else if (opcode == string_add) {
        return (lxor + 1 - iadd) * 2 + FIRSTASGOP.code;
    } else if (ishll <= opcode && opcode <= lushrl) {
        return (opcode - ishll + lxor + 2 - iadd) * 2 + FIRSTASGOP.code;
    }
    return -1;
}
 
Example #12
Source File: Operators.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Initialize operator name array.
 */
private void initOperatorNames() {
    setOperatorName(Tag.POS, "+");
    setOperatorName(Tag.NEG, "-");
    setOperatorName(Tag.NOT, "!");
    setOperatorName(Tag.COMPL, "~");
    setOperatorName(Tag.PREINC, "++");
    setOperatorName(Tag.PREDEC, "--");
    setOperatorName(Tag.POSTINC, "++");
    setOperatorName(Tag.POSTDEC, "--");
    setOperatorName(Tag.NULLCHK, "<*nullchk*>");
    setOperatorName(Tag.OR, "||");
    setOperatorName(Tag.AND, "&&");
    setOperatorName(Tag.EQ, "==");
    setOperatorName(Tag.NE, "!=");
    setOperatorName(Tag.LT, "<");
    setOperatorName(Tag.GT, ">");
    setOperatorName(Tag.LE, "<=");
    setOperatorName(Tag.GE, ">=");
    setOperatorName(Tag.BITOR, "|");
    setOperatorName(Tag.BITXOR, "^");
    setOperatorName(Tag.BITAND, "&");
    setOperatorName(Tag.SL, "<<");
    setOperatorName(Tag.SR, ">>");
    setOperatorName(Tag.USR, ">>>");
    setOperatorName(Tag.PLUS, "+");
    setOperatorName(Tag.MINUS, names.hyphen);
    setOperatorName(Tag.MUL, names.asterisk);
    setOperatorName(Tag.DIV, names.slash);
    setOperatorName(Tag.MOD, "%");
}
 
Example #13
Source File: Lower.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/** Make an attributed assignop expression.
 *  @param optag    The operators tree tag.
 *  @param lhs      The operator's left argument.
 *  @param rhs      The operator's right argument.
 */
JCAssignOp makeAssignop(JCTree.Tag optag, JCTree lhs, JCTree rhs) {
    JCAssignOp tree = make.Assignop(optag, lhs, rhs);
    tree.operator = operators.resolveBinary(tree, tree.getTag().noAssignOp(), lhs.type, rhs.type);
    tree.type = lhs.type;
    return tree;
}
 
Example #14
Source File: Lower.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/** Make an attributed binary expression.
 *  @param optag    The operators tree tag.
 *  @param lhs      The operator's left argument.
 *  @param rhs      The operator's right argument.
 */
JCBinary makeBinary(JCTree.Tag optag, JCExpression lhs, JCExpression rhs) {
    JCBinary tree = make.Binary(optag, lhs, rhs);
    tree.operator = operators.resolveBinary(tree, optag, lhs.type, rhs.type);
    tree.type = tree.operator.type.getReturnType();
    return tree;
}
 
Example #15
Source File: Lower.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/** Return tree tag for assignment operation corresponding
 *  to given binary operator.
 */
private static JCTree.Tag treeTag(OperatorSymbol operator) {
    switch (operator.opcode) {
    case ByteCodes.ior: case ByteCodes.lor:
        return BITOR_ASG;
    case ByteCodes.ixor: case ByteCodes.lxor:
        return BITXOR_ASG;
    case ByteCodes.iand: case ByteCodes.land:
        return BITAND_ASG;
    case ByteCodes.ishl: case ByteCodes.lshl:
    case ByteCodes.ishll: case ByteCodes.lshll:
        return SL_ASG;
    case ByteCodes.ishr: case ByteCodes.lshr:
    case ByteCodes.ishrl: case ByteCodes.lshrl:
        return SR_ASG;
    case ByteCodes.iushr: case ByteCodes.lushr:
    case ByteCodes.iushrl: case ByteCodes.lushrl:
        return USR_ASG;
    case ByteCodes.iadd: case ByteCodes.ladd:
    case ByteCodes.fadd: case ByteCodes.dadd:
    case ByteCodes.string_add:
        return PLUS_ASG;
    case ByteCodes.isub: case ByteCodes.lsub:
    case ByteCodes.fsub: case ByteCodes.dsub:
        return MINUS_ASG;
    case ByteCodes.imul: case ByteCodes.lmul:
    case ByteCodes.fmul: case ByteCodes.dmul:
        return MUL_ASG;
    case ByteCodes.idiv: case ByteCodes.ldiv:
    case ByteCodes.fdiv: case ByteCodes.ddiv:
        return DIV_ASG;
    case ByteCodes.imod: case ByteCodes.lmod:
    case ByteCodes.fmod: case ByteCodes.dmod:
        return MOD_ASG;
    default:
        throw new AssertionError();
    }
}
 
Example #16
Source File: Operators.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Main operator lookup routine; lookup an operator (either unary or binary) in its corresponding
 * map. If there's a matching operator, its resolve routine is called and the result is returned;
 * otherwise the result of a fallback function is returned.
 */
private <O> OperatorSymbol resolve(Tag tag, Map<Name, List<O>> opMap, Predicate<O> opTestFunc,
                   Function<O, OperatorSymbol> resolveFunc, Supplier<OperatorSymbol> noResultFunc) {
    return StreamSupport.stream(opMap.get(operatorName(tag)))
            .filter(opTestFunc)
            .map(resolveFunc)
            .findFirst()
            .orElseGet(noResultFunc);
}
 
Example #17
Source File: Operators.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Report an operator lookup error.
 */
private OperatorSymbol reportErrorIfNeeded(DiagnosticPosition pos, Tag tag, Type... args) {
    if (Stream.of(args).noneMatch(Type::isErroneous)) {
        Name opName = operatorName(tag);
        JCDiagnostic.Error opError = (args.length) == 1 ?
                Errors.OperatorCantBeApplied(opName, args[0]) :
                Errors.OperatorCantBeApplied1(opName, args[0], args[1]);
        log.error(pos, opError);
    }
    return noOpSymbol;
}
 
Example #18
Source File: JavacProcessingEnvironment.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private List<ModuleSymbol> getModuleInfoFiles(List<? extends JCCompilationUnit> units) {
    List<ModuleSymbol> modules = List.nil();
    for (JCCompilationUnit unit : units) {
        if (isModuleInfo(unit.sourcefile, JavaFileObject.Kind.SOURCE) &&
            unit.defs.nonEmpty() &&
            unit.defs.head.hasTag(Tag.MODULEDEF)) {
            modules = modules.prepend(unit.modle);
        }
    }
    return modules.reverse();
}
 
Example #19
Source File: Operators.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Initialize all unary operators.
 */
private void initUnaryOperators() {
    initOperators(unaryOperators,
            new UnaryNumericOperator(Tag.POS)
                    .addUnaryOperator(DOUBLE, DOUBLE, nop)
                    .addUnaryOperator(FLOAT, FLOAT, nop)
                    .addUnaryOperator(LONG, LONG, nop)
                    .addUnaryOperator(INT, INT, nop),
            new UnaryNumericOperator(Tag.NEG)
                    .addUnaryOperator(DOUBLE, DOUBLE, dneg)
                    .addUnaryOperator(FLOAT, FLOAT, fneg)
                    .addUnaryOperator(LONG, LONG, lneg)
                    .addUnaryOperator(INT, INT, ineg),
            new UnaryNumericOperator(Tag.COMPL, Type::isIntegral)
                    .addUnaryOperator(LONG, LONG, lxor)
                    .addUnaryOperator(INT, INT, ixor),
            new UnaryPrefixPostfixOperator(Tag.POSTINC)
                    .addUnaryOperator(DOUBLE, DOUBLE, dadd)
                    .addUnaryOperator(FLOAT, FLOAT, fadd)
                    .addUnaryOperator(LONG, LONG, ladd)
                    .addUnaryOperator(INT, INT, iadd)
                    .addUnaryOperator(CHAR, CHAR, iadd)
                    .addUnaryOperator(SHORT, SHORT, iadd)
                    .addUnaryOperator(BYTE, BYTE, iadd),
            new UnaryPrefixPostfixOperator(Tag.POSTDEC)
                    .addUnaryOperator(DOUBLE, DOUBLE, dsub)
                    .addUnaryOperator(FLOAT, FLOAT, fsub)
                    .addUnaryOperator(LONG, LONG, lsub)
                    .addUnaryOperator(INT, INT, isub)
                    .addUnaryOperator(CHAR, CHAR, isub)
                    .addUnaryOperator(SHORT, SHORT, isub)
                    .addUnaryOperator(BYTE, BYTE, isub),
            new UnaryBooleanOperator(Tag.NOT)
                    .addUnaryOperator(BOOLEAN, BOOLEAN, bool_not),
            new UnaryReferenceOperator(Tag.NULLCHK)
                    .addUnaryOperator(OBJECT, OBJECT, nullchk));
}
 
Example #20
Source File: Operators.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Initialize operator name array.
 */
private void initOperatorNames() {
    setOperatorName(Tag.POS, "+");
    setOperatorName(Tag.NEG, "-");
    setOperatorName(Tag.NOT, "!");
    setOperatorName(Tag.COMPL, "~");
    setOperatorName(Tag.PREINC, "++");
    setOperatorName(Tag.PREDEC, "--");
    setOperatorName(Tag.POSTINC, "++");
    setOperatorName(Tag.POSTDEC, "--");
    setOperatorName(Tag.NULLCHK, "<*nullchk*>");
    setOperatorName(Tag.OR, "||");
    setOperatorName(Tag.AND, "&&");
    setOperatorName(Tag.EQ, "==");
    setOperatorName(Tag.NE, "!=");
    setOperatorName(Tag.LT, "<");
    setOperatorName(Tag.GT, ">");
    setOperatorName(Tag.LE, "<=");
    setOperatorName(Tag.GE, ">=");
    setOperatorName(Tag.BITOR, "|");
    setOperatorName(Tag.BITXOR, "^");
    setOperatorName(Tag.BITAND, "&");
    setOperatorName(Tag.SL, "<<");
    setOperatorName(Tag.SR, ">>");
    setOperatorName(Tag.USR, ">>>");
    setOperatorName(Tag.PLUS, "+");
    setOperatorName(Tag.MINUS, names.hyphen);
    setOperatorName(Tag.MUL, names.asterisk);
    setOperatorName(Tag.DIV, names.slash);
    setOperatorName(Tag.MOD, "%");
}
 
Example #21
Source File: VanillaCompileWorker.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Check if a class is a duplicate, has cyclic dependencies,
 * or has another critical issue.
 */
private boolean isErroneousClass(JCTree tree) {
    if (!tree.hasTag(Tag.CLASSDEF)) {
        return false;
    }
    return isErroneousClass(((JCClassDecl) tree).sym);
}
 
Example #22
Source File: CompilationUnitBuilder.java    From j2cl with Apache License 2.0 5 votes vote down vote up
private VariableDeclarationExpression toResource(JCTree resourceTree) {
  if (resourceTree.getTag() == Tag.VARDEF) {
    return createVariableDeclarationExpression((JCVariableDecl) resourceTree);
  }
  checkArgument(resourceTree.getTag() == Tag.IDENT);
  return toResource((JCIdent) resourceTree);
}
 
Example #23
Source File: JavacTaskImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
void run(Queue<Env<AttrContext>> list, Iterable<? extends Element> elements) {
    Set<Element> set = new HashSet<>();
    for (Element item: elements) {
        set.add(item);
    }

    ListBuffer<Env<AttrContext>> defer = new ListBuffer<>();
    while (list.peek() != null) {
        Env<AttrContext> env = list.remove();
        Symbol test = null;

        if (env.tree.hasTag(Tag.MODULEDEF)) {
            test = ((JCModuleDecl) env.tree).sym;
        } else if (env.tree.hasTag(Tag.PACKAGEDEF)) {
            test = env.toplevel.packge;
        } else {
            ClassSymbol csym = env.enclClass.sym;
            if (csym != null)
                test = csym.outermostClass();
        }
        if (test != null && set.contains(test))
            process(env);
        else
            defer = defer.append(env);
    }

    list.addAll(defer);
}
 
Example #24
Source File: Operators.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Initialize all unary operators.
 */
private void initUnaryOperators() {
    initOperators(unaryOperators,
            new UnaryNumericOperator(Tag.POS)
                    .addUnaryOperator(DOUBLE, DOUBLE, nop)
                    .addUnaryOperator(FLOAT, FLOAT, nop)
                    .addUnaryOperator(LONG, LONG, nop)
                    .addUnaryOperator(INT, INT, nop),
            new UnaryNumericOperator(Tag.NEG)
                    .addUnaryOperator(DOUBLE, DOUBLE, dneg)
                    .addUnaryOperator(FLOAT, FLOAT, fneg)
                    .addUnaryOperator(LONG, LONG, lneg)
                    .addUnaryOperator(INT, INT, ineg),
            new UnaryNumericOperator(Tag.COMPL, Type::isIntegral)
                    .addUnaryOperator(LONG, LONG, lxor)
                    .addUnaryOperator(INT, INT, ixor),
            new UnaryPrefixPostfixOperator(Tag.POSTINC)
                    .addUnaryOperator(DOUBLE, DOUBLE, dadd)
                    .addUnaryOperator(FLOAT, FLOAT, fadd)
                    .addUnaryOperator(LONG, LONG, ladd)
                    .addUnaryOperator(INT, INT, iadd)
                    .addUnaryOperator(CHAR, CHAR, iadd)
                    .addUnaryOperator(SHORT, SHORT, iadd)
                    .addUnaryOperator(BYTE, BYTE, iadd),
            new UnaryPrefixPostfixOperator(Tag.POSTDEC)
                    .addUnaryOperator(DOUBLE, DOUBLE, dsub)
                    .addUnaryOperator(FLOAT, FLOAT, fsub)
                    .addUnaryOperator(LONG, LONG, lsub)
                    .addUnaryOperator(INT, INT, isub)
                    .addUnaryOperator(CHAR, CHAR, isub)
                    .addUnaryOperator(SHORT, SHORT, isub)
                    .addUnaryOperator(BYTE, BYTE, isub),
            new UnaryBooleanOperator(Tag.NOT)
                    .addUnaryOperator(BOOLEAN, BOOLEAN, bool_not),
            new UnaryReferenceOperator(Tag.NULLCHK)
                    .addUnaryOperator(OBJECT, OBJECT, nullchk));
}
 
Example #25
Source File: Modules.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void checkCyclicDependencies(JCModuleDecl mod) {
    for (JCDirective d : mod.directives) {
        JCRequires rd;
        if (!d.hasTag(Tag.REQUIRES) || (rd = (JCRequires) d).directive == null)
            continue;
        Set<ModuleSymbol> nonSyntheticDeps = new HashSet<>();
        List<ModuleSymbol> queue = List.of(rd.directive.module);
        while (queue.nonEmpty()) {
            ModuleSymbol current = queue.head;
            queue = queue.tail;
            if (!nonSyntheticDeps.add(current))
                continue;
            current.complete();
            if ((current.flags() & Flags.ACYCLIC) != 0)
                continue;
            Assert.checkNonNull(current.requires, current::toString);
            for (RequiresDirective dep : current.requires) {
                if (!dep.flags.contains(RequiresFlag.EXTRA))
                    queue = queue.prepend(dep.module);
            }
        }
        if (nonSyntheticDeps.contains(mod.sym)) {
            log.error(rd.moduleName.pos(), Errors.CyclicRequires(rd.directive.module));
        }
        mod.sym.flags_field |= Flags.ACYCLIC;
    }
}
 
Example #26
Source File: Operators.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Entry point for resolving a unary operator given an operator tag and an argument type.
 */
OperatorSymbol resolveUnary(DiagnosticPosition pos, JCTree.Tag tag, Type op) {
    return resolve(tag,
            unaryOperators,
            unop -> unop.test(op),
            unop -> unop.resolve(op),
            () -> reportErrorIfNeeded(pos, tag, op));
}
 
Example #27
Source File: Operators.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Entry point for resolving a binary operator given an operator tag and a pair of argument types.
 */
OperatorSymbol resolveBinary(DiagnosticPosition pos, JCTree.Tag tag, Type op1, Type op2) {
    return resolve(tag,
            binaryOperators,
            binop -> binop.test(op1, op2),
            binop -> binop.resolve(op1, op2),
            () -> reportErrorIfNeeded(pos, tag, op1, op2));
}
 
Example #28
Source File: Operators.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Main operator lookup routine; lookup an operator (either unary or binary) in its corresponding
 * map. If there's a matching operator, its resolve routine is called and the result is returned;
 * otherwise the result of a fallback function is returned.
 */
private <O> OperatorSymbol resolve(Tag tag, Map<Name, List<O>> opMap, Predicate<O> opTestFunc,
                   Function<O, OperatorSymbol> resolveFunc, Supplier<OperatorSymbol> noResultFunc) {
    return opMap.get(operatorName(tag)).stream()
            .filter(opTestFunc)
            .map(resolveFunc)
            .findFirst()
            .orElseGet(noResultFunc);
}
 
Example #29
Source File: Operators.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Report an operator lookup error.
 */
private OperatorSymbol reportErrorIfNeeded(DiagnosticPosition pos, Tag tag, Type... args) {
    if (Stream.of(args).noneMatch(Type::isErroneous)) {
        Name opName = operatorName(tag);
        JCDiagnostic.Error opError = (args.length) == 1 ?
                Errors.OperatorCantBeApplied(opName, args[0]) :
                Errors.OperatorCantBeApplied1(opName, args[0], args[1]);
        log.error(pos, opError);
    }
    return noOpSymbol;
}
 
Example #30
Source File: ManAttr.java    From manifold with Apache License 2.0 5 votes vote down vote up
static boolean isComparableOperator( Tag tag )
{
  return tag == Tag.EQ ||
         tag == Tag.NE ||
         tag == Tag.LT ||
         tag == Tag.LE ||
         tag == Tag.GT ||
         tag == Tag.GE;
}