resolve.java
来自「是一款用JAVA 编写的编译器 具有很强的编译功能」· Java 代码 · 共 1,519 行 · 第 1/5 页
JAVA
1,519 行
sym = findMethod(env, site, name, argtypes, typeargtypes, true, false, false); if (sym.kind >= WRONG_MTHS) sym = findMethod(env, site, name, argtypes, typeargtypes, true, env.info.varArgs=true, false); } if (sym.kind >= AMBIGUOUS) { sym = access(sym, pos, site, name, true, argtypes, typeargtypes); } return sym; } /** Resolve a qualified method identifier, throw a fatal error if not * found. * @param pos The position to use for error reporting. * @param env The environment current at the method invocation. * @param site The type of the qualifying expression, in which * identifier is searched. * @param name The identifier's name. * @param argtypes The types of the invocation's value arguments. * @param typeargtypes The types of the invocation's type arguments. */ public MethodSymbol resolveInternalMethod(DiagnosticPosition pos, Env<AttrContext> env, Type site, Name name, List<Type> argtypes, List<Type> typeargtypes) { Symbol sym = resolveQualifiedMethod( pos, env, site, name, argtypes, typeargtypes); if (sym.kind == MTH) return (MethodSymbol)sym; else throw new FatalError( JCDiagnostic.fragment("fatal.err.cant.locate.meth", name)); } /** Resolve constructor. * @param pos The position to use for error reporting. * @param env The environment current at the constructor invocation. * @param site The type of class for which a constructor is searched. * @param argtypes The types of the constructor invocation's value * arguments. * @param typeargtypes The types of the constructor invocation's type * arguments. */ Symbol resolveConstructor(DiagnosticPosition pos, Env<AttrContext> env, Type site, List<Type> argtypes, List<Type> typeargtypes) { Symbol sym = resolveConstructor(pos, env, site, argtypes, typeargtypes, false, env.info.varArgs=false); if (varargsEnabled && sym.kind >= WRONG_MTHS) { sym = resolveConstructor(pos, env, site, argtypes, typeargtypes, true, false); if (sym.kind >= WRONG_MTHS) sym = resolveConstructor(pos, env, site, argtypes, typeargtypes, true, env.info.varArgs=true); } if (sym.kind >= AMBIGUOUS) { sym = access(sym, pos, site, names.init, true, argtypes, typeargtypes); } return sym; } /** Resolve constructor. * @param pos The position to use for error reporting. * @param env The environment current at the constructor invocation. * @param site The type of class for which a constructor is searched. * @param argtypes The types of the constructor invocation's value * arguments. * @param typeargtypes The types of the constructor invocation's type * arguments. * @param allowBoxing Allow boxing and varargs conversions. * @param useVarargs Box trailing arguments into an array for varargs. */ Symbol resolveConstructor(DiagnosticPosition pos, Env<AttrContext> env, Type site, List<Type> argtypes, List<Type> typeargtypes, boolean allowBoxing, boolean useVarargs) { Symbol sym = findMethod(env, site, names.init, argtypes, typeargtypes, allowBoxing, useVarargs, false); if ((sym.flags() & DEPRECATED) != 0 && (env.info.scope.owner.flags() & DEPRECATED) == 0 && env.info.scope.owner.outermostClass() != sym.outermostClass()) chk.warnDeprecated(pos, sym); return sym; } /** Resolve a constructor, throw a fatal error if not found. * @param pos The position to use for error reporting. * @param env The environment current at the method invocation. * @param site The type to be constructed. * @param argtypes The types of the invocation's value arguments. * @param typeargtypes The types of the invocation's type arguments. */ public MethodSymbol resolveInternalConstructor(DiagnosticPosition pos, Env<AttrContext> env, Type site, List<Type> argtypes, List<Type> typeargtypes) { Symbol sym = resolveConstructor( pos, env, site, argtypes, typeargtypes); if (sym.kind == MTH) return (MethodSymbol)sym; else throw new FatalError( JCDiagnostic.fragment("fatal.err.cant.locate.ctor", site)); } /** Resolve operator. * @param pos The position to use for error reporting. * @param optag The tag of the operation tree. * @param env The environment current at the operation. * @param argtypes The types of the operands. */ Symbol resolveOperator(DiagnosticPosition pos, int optag, Env<AttrContext> env, List<Type> argtypes) { Name name = treeinfo.operatorName(optag); Symbol sym = findMethod(env, syms.predefClass.type, name, argtypes, null, false, false, true); if (boxingEnabled && sym.kind >= WRONG_MTHS) sym = findMethod(env, syms.predefClass.type, name, argtypes, null, true, false, true); return access(sym, pos, env.enclClass.sym.type, name, false, argtypes, null); } /** Resolve operator. * @param pos The position to use for error reporting. * @param optag The tag of the operation tree. * @param env The environment current at the operation. * @param arg The type of the operand. */ Symbol resolveUnaryOperator(DiagnosticPosition pos, int optag, Env<AttrContext> env, Type arg) { return resolveOperator(pos, optag, env, List.of(arg)); } /** Resolve binary operator. * @param pos The position to use for error reporting. * @param optag The tag of the operation tree. * @param env The environment current at the operation. * @param left The types of the left operand. * @param right The types of the right operand. */ Symbol resolveBinaryOperator(DiagnosticPosition pos, int optag, Env<AttrContext> env, Type left, Type right) { return resolveOperator(pos, optag, env, List.of(left, right)); } /** * Resolve `c.name' where name == this or name == super. * @param pos The position to use for error reporting. * @param env The environment current at the expression. * @param c The qualifier. * @param name The identifier's name. */ Symbol resolveSelf(DiagnosticPosition pos, Env<AttrContext> env, TypeSymbol c, Name name) { Env<AttrContext> env1 = env; boolean staticOnly = false; while (env1.outer != null) { if (isStatic(env1)) staticOnly = true; if (env1.enclClass.sym == c) { Symbol sym = env1.info.scope.lookup(name).sym; if (sym != null) { if (staticOnly) sym = new StaticError(sym); return access(sym, pos, env.enclClass.sym.type, name, true); } } if ((env1.enclClass.sym.flags() & STATIC) != 0) staticOnly = true; env1 = env1.outer; } log.error(pos, "not.encl.class", c); return syms.errSymbol; } /** * Resolve `c.this' for an enclosing class c that contains the * named member. * @param pos The position to use for error reporting. * @param env The environment current at the expression. * @param member The member that must be contained in the result. */ Symbol resolveSelfContaining(DiagnosticPosition pos, Env<AttrContext> env, Symbol member) { Name name = names._this; Env<AttrContext> env1 = env; boolean staticOnly = false; while (env1.outer != null) { if (isStatic(env1)) staticOnly = true; if (env1.enclClass.sym.isSubClass(member.owner, types) && isAccessible(env, env1.enclClass.sym.type, member)) { Symbol sym = env1.info.scope.lookup(name).sym; if (sym != null) { if (staticOnly) sym = new StaticError(sym); return access(sym, pos, env.enclClass.sym.type, name, true); } } if ((env1.enclClass.sym.flags() & STATIC) != 0) staticOnly = true; env1 = env1.outer; } log.error(pos, "encl.class.required", member); return syms.errSymbol; } /** * Resolve an appropriate implicit this instance for t's container. * JLS2 8.8.5.1 and 15.9.2 */ Type resolveImplicitThis(DiagnosticPosition pos, Env<AttrContext> env, Type t) { Type thisType = (((t.tsym.owner.kind & (MTH|VAR)) != 0) ? resolveSelf(pos, env, t.getEnclosingType().tsym, names._this) : resolveSelfContaining(pos, env, t.tsym)).type; if (env.info.isSelfCall && thisType.tsym == env.enclClass.sym) log.error(pos, "cant.ref.before.ctor.called", "this"); return thisType; }/* *************************************************************************** * Methods related to kinds ****************************************************************************/ /** A localized string describing a given kind. */ static JCDiagnostic kindName(int kind) { switch (kind) { case PCK: return JCDiagnostic.fragment("kindname.package"); case TYP: return JCDiagnostic.fragment("kindname.class"); case VAR: return JCDiagnostic.fragment("kindname.variable"); case VAL: return JCDiagnostic.fragment("kindname.value"); case MTH: return JCDiagnostic.fragment("kindname.method"); default : return JCDiagnostic.fragment("kindname", Integer.toString(kind)); //debug } } static JCDiagnostic kindName(Symbol sym) { switch (sym.getKind()) { case PACKAGE: return JCDiagnostic.fragment("kindname.package"); case ENUM: case ANNOTATION_TYPE: case INTERFACE: case CLASS: return JCDiagnostic.fragment("kindname.class"); case TYPE_PARAMETER: return JCDiagnostic.fragment("kindname.type.variable"); case ENUM_CONSTANT: case FIELD: case PARAMETER: case LOCAL_VARIABLE: case EXCEPTION_PARAMETER: return JCDiagnostic.fragment("kindname.variable"); case METHOD: case CONSTRUCTOR: case STATIC_INIT: case INSTANCE_INIT: return JCDiagnostic.fragment("kindname.method"); default: if (sym.kind == VAL) // I don't think this can happen but it can't harm // playing it safe --ahe return JCDiagnostic.fragment("kindname.value"); else return JCDiagnostic.fragment("kindname", sym.getKind()); // debug } } /** A localized string describing a given set of kinds. */ static JCDiagnostic kindNames(int kind) { StringBuffer key = new StringBuffer(); key.append("kindname"); if ((kind & VAL) != 0) key.append(((kind & VAL) == VAR) ? ".variable" : ".value"); if ((kind & MTH) != 0) key.append(".method"); if ((kind & TYP) != 0) key.append(".class"); if ((kind & PCK) != 0) key.append(".package"); return JCDiagnostic.fragment(key.toString(), kind); } /** A localized string describing the kind -- either class or interface -- * of a given type. */ static JCDiagnostic typeKindName(Type t) { if (t.tag == TYPEVAR || t.tag == CLASS && (t.tsym.flags() & COMPOUND) != 0) return JCDiagnostic.fragment("kindname.type.variable.bound"); else if (t.tag == PACKAGE) return JCDiagnostic.fragment("kindname.package"); else if ((t.tsym.flags_field & ANNOTATION) != 0) return JCDiagnostic.fragment("kindname.annotation"); else
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?