com.sun.tools.javac.code.Symbol.OperatorSymbol Java Examples

The following examples show how to use com.sun.tools.javac.code.Symbol.OperatorSymbol. 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: Symtab.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
/** Enter a unary operation into symbol table.
 *  @param name     The name of the operator.
 *  @param arg      The type of the operand.
 *  @param res      The operation's result type.
 *  @param opcode   The operation's bytecode instruction.
 */
private OperatorSymbol enterUnop(String name,
                                 Type arg,
                                 Type res,
                                 int opcode) {
    OperatorSymbol sym =
        new OperatorSymbol(names.fromString(name),
                           new MethodType(List.of(arg),
                                          res,
                                          List.<Type>nil(),
                                          methodClass),
                           opcode,
                           predefClass);
    predefClass.members().enter(sym);
    return sym;
}
 
Example #2
Source File: Symtab.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
/** Enter a unary operation into symbol table.
 *  @param name     The name of the operator.
 *  @param arg      The type of the operand.
 *  @param res      The operation's result type.
 *  @param opcode   The operation's bytecode instruction.
 */
private OperatorSymbol enterUnop(String name,
                                 Type arg,
                                 Type res,
                                 int opcode) {
    OperatorSymbol sym =
        new OperatorSymbol(names.fromString(name),
                           new MethodType(List.of(arg),
                                          res,
                                          List.<Type>nil(),
                                          methodClass),
                           opcode,
                           predefClass);
    predefClass.members().enter(sym);
    return sym;
}
 
Example #3
Source File: Operators.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
OperatorSymbol lookupBinaryOp(Predicate<OperatorSymbol> applicabilityTest) {
    return binaryOperators.values().stream()
            .flatMap(List::stream)
            .map(helper -> helper.doLookup(applicabilityTest))
            .distinct()
            .filter(sym -> sym != noOpSymbol)
            .findFirst().get();
}
 
Example #4
Source File: Symtab.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/** Enter a binary operation into symbol table.
 *  @param name     The name of the operator.
 *  @param left     The type of the left operand.
 *  @param right    The type of the left operand.
 *  @param res      The operation's result type.
 *  @param opcode   The operation's bytecode instruction.
 */
private void enterBinop(String name,
                        Type left, Type right, Type res,
                        int opcode) {
    predefClass.members().enter(
        new OperatorSymbol(
            names.fromString(name),
            new MethodType(List.of(left, right), res,
                           List.<Type>nil(), methodClass),
            opcode,
            predefClass));
}
 
Example #5
Source File: Operators.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public OperatorSymbol resolve(Type t1, Type t2) {
    ComparisonKind kind = getKind(t1, t2);
    Type t = (kind == ComparisonKind.NUMERIC_OR_BOOLEAN) ?
            binaryPromotion(t1, t2) :
            syms.objectType;
    return doLookup(t, t);
}
 
Example #6
Source File: Operators.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * This routine performs lazy instantiation of the operator symbols supported by this helper.
 * After initialization is done, the suppliers are cleared, to free up memory.
 */
private OperatorSymbol[] initOperators() {
    OperatorSymbol[] operators = operatorSuppliers.stream()
            .map(Supplier::get)
            .toArray(OperatorSymbol[]::new);
    alternatives = Optional.of(operators);
    operatorSuppliers = null; //let GC do its work
    return operators;
}
 
Example #7
Source File: Operators.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * This routine implements the main operator lookup process. Each operator is tested
 * using an applicability predicate; if the test suceeds that same operator is returned,
 * otherwise a dummy symbol is returned.
 */
final OperatorSymbol doLookup(Predicate<OperatorSymbol> applicabilityTest) {
    return Stream.of(alternatives.orElseGet(this::initOperators))
            .filter(applicabilityTest)
            .findFirst()
            .orElse(noOpSymbol);
}
 
Example #8
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 #9
Source File: Operators.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates an operator symbol.
 */
private OperatorSymbol makeOperator(Name name, List<OperatorType> formals, OperatorType res, int... opcodes) {
    MethodType opType = new MethodType(
            formals.stream()
                    .map(o -> o.asType(syms))
                    .collect(List.collector()),
            res.asType(syms), List.nil(), syms.methodClass);
    return new OperatorSymbol(name, opType, mergeOpcodes(opcodes), syms.noSymbol);
}
 
Example #10
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 #11
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 #12
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 #13
Source File: Operators.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
protected Operators(Context context) {
    context.put(operatorsKey, this);
    syms = Symtab.instance(context);
    names = Names.instance(context);
    log = Log.instance(context);
    types = Types.instance(context);
    noOpSymbol = new OperatorSymbol(names.empty, Type.noType, -1, syms.noSymbol);
    initOperatorNames();
    initUnaryOperators();
    initBinaryOperators();
}
 
Example #14
Source File: Symtab.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/** Enter a binary operation into symbol table.
 *  @param name     The name of the operator.
 *  @param left     The type of the left operand.
 *  @param right    The type of the left operand.
 *  @param res      The operation's result type.
 *  @param opcode   The operation's bytecode instruction.
 */
private void enterBinop(String name,
                        Type left, Type right, Type res,
                        int opcode) {
    predefClass.members().enter(
        new OperatorSymbol(
            names.fromString(name),
            new MethodType(List.of(left, right), res,
                           List.<Type>nil(), methodClass),
            opcode,
            predefClass));
}
 
Example #15
Source File: Operators.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
OperatorSymbol lookupBinaryOp(Predicate<OperatorSymbol> applicabilityTest) {
    return StreamSupport.stream(binaryOperators.values())
            .flatMap(StreamSupport::stream)
            .map(helper -> helper.doLookup(applicabilityTest))
            .distinct()
            .filter(sym -> sym != noOpSymbol)
            .findFirst().get();
}
 
Example #16
Source File: Operators.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public OperatorSymbol resolve(Type t1, Type t2) {
    ComparisonKind kind = getKind(t1, t2);
    Type t = (kind == ComparisonKind.NUMERIC_OR_BOOLEAN) ?
            binaryPromotion(t1, t2) :
            syms.objectType;
    return doLookup(t, t);
}
 
Example #17
Source File: Check.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 *  Check for division by integer constant zero
 *  @param pos           Position for error reporting.
 *  @param operator      The operator for the expression
 *  @param operand       The right hand operand for the expression
 */
void checkDivZero(final DiagnosticPosition pos, Symbol operator, Type operand) {
    if (operand.constValue() != null
        && operand.getTag().isSubRangeOf(LONG)
        && ((Number) (operand.constValue())).longValue() == 0) {
        int opc = ((OperatorSymbol)operator).opcode;
        if (opc == ByteCodes.idiv || opc == ByteCodes.imod
            || opc == ByteCodes.ldiv || opc == ByteCodes.lmod) {
            deferredLintHandler.report(() -> warnDivZero(pos));
        }
    }
}
 
Example #18
Source File: Operators.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 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 #19
Source File: Operators.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 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 #20
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 #21
Source File: Operators.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Creates an operator symbol.
 */
private OperatorSymbol makeOperator(Name name, List<OperatorType> formals, OperatorType res, int... opcodes) {
    MethodType opType = new MethodType(
            StreamSupport.stream(formals)
                    .map(o -> o.asType(syms))
                    .collect(List.collector()),
            res.asType(syms), List.nil(), syms.methodClass);
    return new OperatorSymbol(name, opType, mergeOpcodes(opcodes), syms.noSymbol);
}
 
Example #22
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 #23
Source File: Operators.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected Operators(Context context) {
    context.put(operatorsKey, this);
    syms = Symtab.instance(context);
    names = Names.instance(context);
    log = Log.instance(context);
    types = Types.instance(context);
    noOpSymbol = new OperatorSymbol(names.empty, Type.noType, -1, syms.noSymbol);
    initOperatorNames();
    initUnaryOperators();
    initBinaryOperators();
}
 
Example #24
Source File: Operators.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * This routine implements the main operator lookup process. Each operator is tested
 * using an applicability predicate; if the test suceeds that same operator is returned,
 * otherwise a dummy symbol is returned.
 */
final OperatorSymbol doLookup(Predicate<OperatorSymbol> applicabilityTest) {
    return Stream.of(alternatives.orElseGet(this::initOperators))
            .filter(applicabilityTest)
            .findFirst()
            .orElse(noOpSymbol);
}
 
Example #25
Source File: Operators.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * This routine performs lazy instantiation of the operator symbols supported by this helper.
 * After initialization is done, the suppliers are cleared, to free up memory.
 */
private OperatorSymbol[] initOperators() {
    OperatorSymbol[] operators = StreamSupport.stream(operatorSuppliers)
            .map(Supplier::get)
            .toArray(OperatorSymbol[]::new);
    alternatives = Optional.of(operators);
    operatorSuppliers = null; //let GC do its work
    return operators;
}
 
Example #26
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 #27
Source File: Operators.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Binary operator applicability test - are the input types the same as the expected operand types?
 */
boolean isBinaryOperatorApplicable(OperatorSymbol op, Type t1, Type t2) {
    List<Type> formals = op.type.getParameterTypes();
    return types.isSameType(formals.head, t1) &&
            types.isSameType(formals.tail.head, t2);
}
 
Example #28
Source File: Operators.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Unary operator applicability test - is the input type the same as the expected operand type?
 */
boolean isUnaryOperatorApplicable(OperatorSymbol op, Type t) {
    return types.isSameType(op.type.getParameterTypes().head, t);
}
 
Example #29
Source File: Lower.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/** Return binary operator that corresponds to given access code.
 */
private OperatorSymbol binaryAccessOperator(int acode, Tag tag) {
    return operators.lookupBinaryOp(op -> op.getAccessCode(tag) == acode);
}
 
Example #30
Source File: Operators.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public OperatorSymbol resolve(Type arg) {
    return doLookup(syms.objectType);
}