From 860489475c9b1cf21a571178e31f9a8411d6cc40 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Sat, 17 Mar 2012 22:03:13 -0700 Subject: [PATCH] Cosmetics. --- .../parser/cpp/semantics/CPPSemantics.java | 508 +++++++++--------- .../dom/parser/cpp/semantics/CPPVisitor.java | 2 +- 2 files changed, 255 insertions(+), 255 deletions(-) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java index b566bd01787..65206c1d7aa 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java @@ -412,7 +412,7 @@ public class CPPSemantics { } } } - + IASTName name= data.astName; IASTNode nameParent= name.getParent(); if (nameParent instanceof ICPPASTTemplateId) { @@ -421,7 +421,7 @@ public class CPPSemantics { binding = instance.getSpecializedBinding(); name.setBinding(binding); ((ICPPASTTemplateId) nameParent).setBinding(instance); - } + } name= (ICPPASTTemplateId) nameParent; nameParent= name.getParent(); } @@ -431,7 +431,7 @@ public class CPPSemantics { nameParent= name.getParent(); } } - + // if the lookup in base-classes ran into a deferred instance, use the computed unknown binding. final ASTNodeProperty namePropertyInParent = name.getPropertyInParent(); if (binding == null && data.skippedScope != null) { @@ -445,7 +445,7 @@ public class CPPSemantics { } } } - + if (binding != null) { if (namePropertyInParent == IASTNamedTypeSpecifier.NAME) { if (!(binding instanceof IType || binding instanceof ICPPConstructor)) { @@ -461,7 +461,7 @@ public class CPPSemantics { binding = new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_INVALID_TYPE, data.getFoundBindings()); } - } + } } else if (namePropertyInParent == IASTIdExpression.ID_NAME) { if (binding instanceof IType) { final IASTNode idExpr = name.getParent(); @@ -470,7 +470,7 @@ public class CPPSemantics { // Default for template template parameter is a type. } else if (pip == IASTFunctionCallExpression.FUNCTION_NAME) { // Explicit type conversion in functional notation. - } else if (pip == IASTUnaryExpression.OPERAND + } else if (pip == IASTUnaryExpression.OPERAND && ((ICPPASTUnaryExpression) idExpr.getParent()).getOperator() == IASTUnaryExpression.op_sizeofParameterPack) { // Argument of sizeof... can be a type } else { @@ -480,13 +480,13 @@ public class CPPSemantics { } } } - + // Some declarations are found via name resolution (e.g. when using a qualified name), // add name as definition and check the declaration specifier. final IASTDeclaration declaration = data.forDeclaration(); if (declaration != null) { // Functions - if (binding instanceof IFunction) { + if (binding instanceof IFunction) { binding= checkDeclSpecifier(binding, data.astName, declaration); if (!(binding instanceof IProblemBinding)) { if (declaration instanceof ICPPASTFunctionDefinition) { @@ -495,13 +495,13 @@ public class CPPSemantics { } } // Definitions of static fields. - if (binding instanceof ICPPField && data.astName.isDefinition()) { + if (binding instanceof ICPPField && data.astName.isDefinition()) { if (declaration.getPropertyInParent() != IASTCompositeTypeSpecifier.MEMBER_DECLARATION) { ASTInternal.addDefinition(binding, data.astName); } } } - + // If we're still null... if (binding == null) { if (name instanceof ICPPASTQualifiedName && declaration != null) { @@ -521,10 +521,10 @@ public class CPPSemantics { final ASTNodeProperty propertyInParent = name.getPropertyInParent(); if (propertyInParent == CPPSemantics.STRING_LOOKUP_PROPERTY || propertyInParent == null) return false; - + if (propertyInParent == ICPPASTTemplateId.TEMPLATE_NAME) return false; - + IASTNode parent= name.getParent(); if (parent instanceof ICPPASTQualifiedName) { if (((ICPPASTQualifiedName) parent).getLastName() != name) @@ -541,7 +541,7 @@ public class CPPSemantics { if (dtor != null && dtor.getPointerOperators().length == 0) return true; } - } + } return false; } @@ -557,7 +557,7 @@ public class CPPSemantics { } mergeResults(data, friendFns.toArray(), false); } - + static IBinding checkDeclSpecifier(IBinding binding, IASTName name, IASTNode decl) { // check for empty declaration specifiers if (!isCtorOrConversionOperator(binding)) { @@ -577,7 +577,7 @@ public class CPPSemantics { private static boolean isCtorOrConversionOperator(IBinding binding) { if (binding instanceof ICPPConstructor) return true; - + if (binding instanceof ICPPMethod) { ICPPMethod m= (ICPPMethod) binding; if (m.isDestructor()) @@ -590,18 +590,18 @@ public class CPPSemantics { public static LookupData createLookupData(IASTName name) { LookupData data = new LookupData(name); IASTNode parent = name.getParent(); - + if (parent instanceof ICPPASTTemplateId) parent = parent.getParent(); if (parent instanceof ICPPASTQualifiedName) parent = parent.getParent(); - + if (parent instanceof IASTDeclarator && parent.getPropertyInParent() == IASTSimpleDeclaration.DECLARATOR) { IASTSimpleDeclaration simple = (IASTSimpleDeclaration) parent.getParent(); if (simple.getDeclSpecifier().getStorageClass() == IASTDeclSpecifier.sc_typedef) data.forceQualified = true; } - + if (parent instanceof IASTIdExpression) { IASTNode grand= parent.getParent(); while (grand instanceof IASTUnaryExpression @@ -647,14 +647,14 @@ public class CPPSemantics { data.setFunctionArguments(false, (ICPPASTInitializerList) init); } } - + return data; } private static Set getAssociatedScopes(LookupData data, Set friendFns) { if (!data.hasFunctionArguments()) return Collections.emptySet(); - + IType[] ps = data.getFunctionArgumentTypes(); Set namespaces = new HashSet(2); ObjectSet handled = new ObjectSet(2); @@ -664,7 +664,7 @@ public class CPPSemantics { } catch (DOMException e) { } } - + if (data.astName != null) { final char[] simpleID = data.astName.getSimpleID(); if (CharArrayUtils.equals(CPPVisitor.BEGIN, simpleID) || CharArrayUtils.equals(CPPVisitor.END, simpleID)) { @@ -686,7 +686,7 @@ public class CPPSemantics { return namespaces; } - // 3.4.2-2 + // 3.4.2-2 private static void getAssociatedScopes(IType t, Set namespaces, Set friendFns, ObjectSet handled, CPPASTTranslationUnit tu) throws DOMException { t = getNestedType(t, TDEF | CVTYPE | PTR | ARRAY | REF); @@ -694,7 +694,7 @@ public class CPPSemantics { if (handled.containsKey(t)) return; handled.put(t); - + IBinding owner= ((IBinding) t).getOwner(); if (owner instanceof ICPPClassType) { getAssociatedScopes((IType) owner, namespaces, friendFns, handled, tu); @@ -710,10 +710,10 @@ public class CPPSemantics { if (b instanceof IType) getAssociatedScopes((IType) b, namespaces, friendFns, handled, tu); } - // Furthermore, if T is a class template ... - // * ... types of the template arguments for template type parameters - // (excluding template template parameters); - // * ... owners of which any template template arguments are members; + // Furthermore, if T is a class template ... + // * ... types of the template arguments for template type parameters + // (excluding template template parameters); + // * ... owners of which any template template arguments are members; if (ct instanceof ICPPTemplateInstance) { for (IBinding friend : ct.getFriends()) { if (friend instanceof ICPPFunction) { @@ -740,10 +740,10 @@ public class CPPSemantics { getAssociatedScopes(pmt.getType(), namespaces, friendFns, handled, tu); } else if (t instanceof FunctionSetType) { FunctionSetType fst= (FunctionSetType) t; - for (ICPPFunction fn : fst.getFunctionSet()) { + for (ICPPFunction fn : fst.getFunctionSet()) { getAssociatedScopes(fn.getType(), namespaces, friendFns, handled, tu); } - } + } } private static ICPPNamespaceScope getContainingNamespaceScope(IBinding binding, @@ -763,7 +763,7 @@ public class CPPSemantics { public static void getAssociatedNamespaceScopes(ICPPNamespaceScope scope, Set namespaces) { if (scope == null || !namespaces.add(scope)) return; - + if (scope instanceof ICPPInternalNamespaceScope) { final ICPPInternalNamespaceScope internalScope = (ICPPInternalNamespaceScope) scope; for (ICPPNamespaceScope mem : internalScope.getEnclosingNamespaceSet()) { @@ -771,7 +771,7 @@ public class CPPSemantics { } } } - + static ICPPScope getLookupScope(IASTName name, LookupData data) throws DOMException { IASTNode parent = name.getParent(); IScope scope = null; @@ -807,7 +807,7 @@ public class CPPSemantics { data.foundItems = mergePrefixResults(oldItems, results, scoped); } } - + /** * @param dest * @param source : either Object[] or CharArrayObjectMap @@ -815,9 +815,9 @@ public class CPPSemantics { * @return */ static CharArrayObjectMap mergePrefixResults(CharArrayObjectMap dest, Object source, boolean scoped) { - if (source == null) return dest; + if (source == null) return dest; CharArrayObjectMap resultMap = (dest != null) ? dest : new CharArrayObjectMap(2); - + CharArrayObjectMap map = null; Object[] objs = null; int size; @@ -829,10 +829,10 @@ public class CPPSemantics { } else { if (source instanceof Object[]) objs = ArrayUtil.trim(Object.class, (Object[]) source); - else + else objs = new Object[]{ source }; size= objs.length; - } + } int resultInitialSize = resultMap.size(); for (int i = 0; i < size; i ++) { @@ -865,18 +865,18 @@ public class CPPSemantics { temp[0] = obj; obj = ArrayUtil.addAll(Object.class, temp, (Object[]) so); } - } + } resultMap.put(key, obj); } } return resultMap; } - + private static IIndexFileSet getIndexFileSet(LookupData data) { if (data.tu != null) { final IIndexFileSet fs= data.tu.getIndexFileSet(); - if (fs != null) + if (fs != null) return fs; } return IIndexFileSet.EMPTY; @@ -888,13 +888,13 @@ public class CPPSemantics { * @param start either a scope or a name. */ static protected void lookup(LookupData data, IScope start) throws DOMException { - if (data.astName == null) + if (data.astName == null) return; if (start == null && lookupDestructor(data, start)) { return; } - + ICPPScope nextScope= null; ICPPTemplateScope nextTmplScope= null; if (start instanceof ICPPScope) { @@ -938,21 +938,21 @@ public class CPPSemantics { final IASTNode node= ((IASTInternalScope) nextScope).getPhysicalNode(); if (node != null && nextTmplScope.getTemplateDeclaration().contains(node)) { useTemplScope= false; - } + } } } ICPPScope scope= useTemplScope ? nextTmplScope : nextScope; if (scope instanceof IIndexScope && data.tu != null) { scope= (ICPPScope) data.tu.mapToASTScope(((IIndexScope) scope)); } - + if (!data.usingDirectivesOnly && !(data.ignoreMembers && scope instanceof ICPPClassScope)) { mergeResults(data, getBindingsFromScope(scope, fileSet, data), true); // Nominate using-directives found in this block or namespace. if (scope instanceof ICPPNamespaceScope) { final ICPPNamespaceScope blockScope= (ICPPNamespaceScope) scope; - + if (data.qualified() && blockScope.getKind() != EScopeKind.eLocal) { lookupInlineNamespaces(data, fileSet, blockScope); } @@ -969,25 +969,25 @@ public class CPPSemantics { lookupInNominated(data, fileSet, (ICPPNamespaceScope) scope); } } - + if (friendInLocalClass && !(scope instanceof ICPPClassScope)) - return; + return; if (!data.contentAssist && hasReachableResult(data)) return; - + // Lookup in base classes if (!data.usingDirectivesOnly && scope instanceof ICPPClassScope && !data.ignoreMembers) { BaseClassLookup.lookupInBaseClasses(data, (ICPPClassScope) scope, fileSet); - if (!data.contentAssist && data.hasResultOrProblem()) + if (!data.contentAssist && data.hasResultOrProblem()) return; } - + if (data.qualified() && !(scope instanceof ICPPTemplateScope)) { if (data.ignoreUsingDirectives || data.usingDirectives.isEmpty()) return; data.usingDirectivesOnly = true; } - + // Compute next scopes if (useTemplScope && nextTmplScope != null) { nextTmplScope= enclosingTemplateScope(nextTmplScope.getTemplateDeclaration()); @@ -1001,7 +1001,7 @@ public class CPPSemantics { * Checks if lookup data contains result bindings reachable through includes * from the translation unit where lookup started. Any binding is considered reachable * if the lookup is not done in a context of a translation unit. - * + * * @param data the LookupData object. * @return {@code true} if the lookup data contains at least one reachable binding. */ @@ -1053,9 +1053,9 @@ public class CPPSemantics { private static boolean lookupDestructor(LookupData data, IScope start) throws DOMException { IASTName typeDtorName= data.astName; final char[] typeDtorChars= typeDtorName.getSimpleID(); - if (typeDtorChars.length == 0 || typeDtorChars[0] != '~') + if (typeDtorChars.length == 0 || typeDtorChars[0] != '~') return false; - + // Assume class C; typedef C T; // When looking up ~T the strategy is to lookup T::~C in two steps: // * First resolve 'T', then compute '~C' and resolve it. @@ -1093,29 +1093,29 @@ public class CPPSemantics { final CPPASTName classDtorName = new CPPASTName(typeDtorChars); classDtorName.setOffsetAndLength((ASTNode) typeDtorName); syntheticName.addName(classDtorName); - + IBinding type= resolveBinding(typeName); - if (!(type instanceof ITypedef)) + if (!(type instanceof ITypedef)) return false; - + IType t= SemanticUtil.getNestedType((ITypedef) type, TDEF); if (t instanceof ICPPUnknownBinding || t instanceof ISemanticProblem || !(t instanceof ICPPClassType)) { return false; } - + ICPPClassType classType= (ICPPClassType) t; final IScope scope = ((ICPPClassType) t).getCompositeScope(); if (scope == null) { return false; } - + char[] classChars= classType.getNameCharArray(); char[] classDtorChars= new char[classChars.length+1]; classDtorChars[0]= '~'; System.arraycopy(classChars, 0, classDtorChars, 1, classChars.length); classDtorName.setName(classDtorChars); - + data.astName = classDtorName; try { lookup(data, scope); @@ -1129,7 +1129,7 @@ public class CPPSemantics { * Checks whether the name directly or indirectly depends on the this pointer. */ private static boolean dependsOnTemplateFieldReference(IASTName astName) { - if (astName.getPropertyInParent() != IASTFieldReference.FIELD_NAME) + if (astName.getPropertyInParent() != IASTFieldReference.FIELD_NAME) return false; final boolean[] result= {false}; @@ -1243,7 +1243,7 @@ public class CPPSemantics { } } } - } else { + } else { // For index scopes the point of declaration is ignored. bindings= scope.getBindings(data.astName, true, data.prefixLookup, fileSet); } @@ -1253,11 +1253,11 @@ public class CPPSemantics { private static IBinding[] expandUsingDeclarationsAndRemoveObjects(final IBinding[] bindings, LookupData data) { if (bindings == null || bindings.length == 0) return IBinding.EMPTY_BINDING_ARRAY; - + for (IBinding b : bindings) { - if (b == null) + if (b == null) break; - + if (b instanceof ICPPUsingDeclaration || (data.typesOnly && isObject(b))) { List result= new ArrayList(bindings.length); expandUsingDeclarations(bindings, data, result); @@ -1332,7 +1332,7 @@ public class CPPSemantics { * In case of an unqualified lookup the transitive directives are stored, also. This is important because * the members nominated by a transitive directive can appear before those of the original directive. */ - private static void storeUsingDirective(LookupData data, ICPPNamespaceScope container, + private static void storeUsingDirective(LookupData data, ICPPNamespaceScope container, ICPPUsingDirective directive, Set handled) throws DOMException { ICPPNamespaceScope nominated= directive.getNominatedScope(); if (nominated instanceof IIndexScope && data.tu != null) { @@ -1341,7 +1341,7 @@ public class CPPSemantics { if (nominated == null || data.visited.containsKey(nominated) || (handled != null && !handled.add(nominated))) { return; } - // 7.3.4.1 names appear at end of common enclosing scope of container and nominated scope. + // 7.3.4.1 names appear at end of common enclosing scope of container and nominated scope. final IScope appearsIn= getCommonEnclosingScope(nominated, container, data.tu); if (appearsIn instanceof ICPPNamespaceScope) { // store the directive with the scope where it has to be considered @@ -1355,7 +1355,7 @@ public class CPPSemantics { } listOfNominated.add(nominated); } - + // in a non-qualified lookup the transitive directive have to be stored right away, they may overtake the // container. if (!data.qualified() || data.contentAssist) { @@ -1373,7 +1373,7 @@ public class CPPSemantics { /** * Computes the common enclosing scope of s1 and s2. */ - private static ICPPScope getCommonEnclosingScope(IScope s1, IScope s2, CPPASTTranslationUnit tu) throws DOMException { + private static ICPPScope getCommonEnclosingScope(IScope s1, IScope s2, CPPASTTranslationUnit tu) throws DOMException { ObjectSet set = new ObjectSet(2); IScope parent= s1; while (parent != null) { @@ -1390,10 +1390,10 @@ public class CPPSemantics { public static void populateCache(ICPPASTInternalScope scope) { IASTNode[] nodes = null; IASTNode parent= ASTInternal.getPhysicalNodeOfScope(scope); - + IASTName[] namespaceDefs = null; int namespaceIdx = -1; - + if (parent instanceof IASTCompoundStatement) { IASTNode p = parent.getParent(); if (p instanceof IASTFunctionDefinition) { @@ -1460,7 +1460,7 @@ public class CPPSemantics { } return; } - + int idx = -1; IASTNode item = (nodes != null ? (nodes.length > 0 ? nodes[++idx] : null) : parent); IASTNode[][] nodeStack = null; @@ -1478,7 +1478,7 @@ public class CPPSemantics { continue; } } - while (item instanceof IASTLabelStatement) + while (item instanceof IASTLabelStatement) item= ((IASTLabelStatement) item).getNestedStatement(); if (item instanceof IASTDeclarationStatement) item = ((IASTDeclarationStatement) item).getDeclaration(); @@ -1507,7 +1507,7 @@ public class CPPSemantics { } else { populateCache(scope, item); } - + if (nodes != null && ++idx < nodes.length) { item = nodes[idx]; } else { @@ -1521,17 +1521,17 @@ public class CPPSemantics { idx = 0; item = nodes[0]; break; - } + } } } else if (parent instanceof IASTCompoundStatement && nodes instanceof IASTParameterDeclaration[]) { // function body, we were looking at parameters, now check the body itself IASTCompoundStatement compound = (IASTCompoundStatement) parent; - nodes = compound.getStatements(); + nodes = compound.getStatements(); if (nodes.length > 0) { idx = 0; item = nodes[0]; break; - } + } } else if (parent instanceof ICPPASTCatchHandler) { parent = ((ICPPASTCatchHandler) parent).getCatchBody(); if (parent instanceof IASTCompoundStatement) { @@ -1540,7 +1540,7 @@ public class CPPSemantics { idx = 0; item = nodes[0]; break; - } + } } } if (item == null && nodeStack != null && nodeIdxStack != null && nodeStackPos >= 0) { @@ -1549,7 +1549,7 @@ public class CPPSemantics { idx = nodeIdxStack[nodeStackPos--]; if (++idx >= nodes.length) continue; - + item = nodes[idx]; } break; @@ -1562,7 +1562,7 @@ public class CPPSemantics { IASTDeclaration declaration = null; if (node instanceof ICPPASTTemplateDeclaration) { declaration = ((ICPPASTTemplateDeclaration) node).getDeclaration(); - } else if (node instanceof IASTDeclaration) { + } else if (node instanceof IASTDeclaration) { declaration = (IASTDeclaration) node; } else if (node instanceof IASTDeclarationStatement) { declaration = ((IASTDeclarationStatement) node).getDeclaration(); @@ -1619,7 +1619,7 @@ public class CPPSemantics { } } } - + // Declaration specifiers defining or declaring a type IASTName specName = null; final EScopeKind scopeKind = scope.getKind(); @@ -1634,14 +1634,14 @@ public class CPPSemantics { } else if (declSpec instanceof ICPPASTCompositeTypeSpecifier) { ICPPASTCompositeTypeSpecifier compSpec = (ICPPASTCompositeTypeSpecifier) declSpec; specName = compSpec.getName(); - + // Anonymous union or struct (GCC supports anonymous structs too) if (declarators.length == 0 && specName.getLookupKey().length == 0) { IASTDeclaration[] decls = compSpec.getMembers(); for (IASTDeclaration decl : decls) { populateCache(scope, decl); } - } + } } else if (declSpec instanceof ICPPASTEnumerationSpecifier) { ICPPASTEnumerationSpecifier enumeration = (ICPPASTEnumerationSpecifier) declSpec; specName = enumeration.getName(); @@ -1658,7 +1658,7 @@ public class CPPSemantics { ASTInternal.addName(scope, specName); } } - // Collect friends and elaborated type specifiers with declarators + // Collect friends and elaborated type specifiers with declarators // from nested classes if (declarators.length > 0 || declSpec instanceof ICPPASTCompositeTypeSpecifier) { switch (scopeKind) { @@ -1699,7 +1699,7 @@ public class CPPSemantics { IASTName declName = ASTQueries.findInnermostDeclarator(declarator).getName(); ASTInternal.addName(scope, declName); } - // Collect elaborated type specifiers and friends + // Collect elaborated type specifiers and friends final EScopeKind scopeKind = scope.getKind(); switch (scopeKind) { case eLocal: @@ -1721,7 +1721,7 @@ public class CPPSemantics { * lookups the method assumes that transitive directives have been stored in the lookup-data. * For qualified lookups the transitive directives are considered if the lookup of the original * directive returns empty. - * @param fileSet + * @param fileSet */ private static void lookupInNominated(LookupData data, IIndexFileSet fileSet, ICPPNamespaceScope scope) throws DOMException { @@ -1779,18 +1779,18 @@ public class CPPSemantics { } // Bug 238180 - if (candidate instanceof ICPPClassTemplatePartialSpecialization) + if (candidate instanceof ICPPClassTemplatePartialSpecialization) return null; - + // Specialization is selected during instantiation if (candidate instanceof ICPPTemplateInstance) candidate= ((ICPPTemplateInstance) candidate).getSpecializedBinding(); - + if (!(candidate instanceof ICPPFunctionTemplate)) return candidate; } } - + if (name.getPropertyInParent() != STRING_LOOKUP_PROPERTY) { LookupData data = createLookupData(name); data.foundItems = bindings; @@ -1800,7 +1800,7 @@ public class CPPSemantics { return e.getProblem(); } } - + IBinding[] result = null; for (Object binding : bindings) { if (binding instanceof IASTName) { @@ -1811,11 +1811,11 @@ public class CPPSemantics { } return new CPPCompositeBinding(result); } - + public static boolean declaredBefore(Object obj, IASTNode node, boolean indexBased) { - if (node == null) + if (node == null) return true; - + final int pointOfRef= ((ASTNode) node).getOffset(); if (node.getPropertyInParent() == STRING_LOOKUP_PROPERTY && pointOfRef <= 0) { return true; @@ -1825,11 +1825,11 @@ public class CPPSemantics { if (obj instanceof ICPPSpecialization) { obj = ((ICPPSpecialization) obj).getSpecializedBinding(); } - + int pointOfDecl= -1; if (obj instanceof ICPPInternalBinding) { ICPPInternalBinding cpp = (ICPPInternalBinding) obj; - // For bindings in global or namespace scope we don't know whether there is a + // For bindings in global or namespace scope we don't know whether there is a // previous declaration in one of the skipped header files. For bindings that // are likely to be redeclared we need to assume that there is a declaration // in one of the headers. @@ -1845,7 +1845,7 @@ public class CPPSemantics { if (nd == null || def.getOffset() < nd.getOffset()) nd = def; } - if (nd == null) + if (nd == null) return true; } else { if (indexBased && obj instanceof IASTName) { @@ -1861,7 +1861,7 @@ public class CPPSemantics { pointOfDecl= ((ICPPUsingDirective) obj).getPointOfDeclaration(); } } - + if (pointOfDecl < 0 && nd != null) { ASTNodeProperty prop = nd.getPropertyInParent(); if (prop == IASTDeclarator.DECLARATOR_NAME || nd instanceof IASTDeclarator) { @@ -1891,7 +1891,7 @@ public class CPPSemantics { } else if (prop == ICPPASTNamespaceAlias.ALIAS_NAME) { nd = (ASTNode) nd.getParent(); pointOfDecl = nd.getOffset() + nd.getLength(); - } else { + } else { pointOfDecl = nd.getOffset() + nd.getLength(); } } @@ -1918,18 +1918,18 @@ public class CPPSemantics { } return false; } - + private static IBinding resolveAmbiguities(LookupData data, IASTName name) throws DOMException { if (!data.hasResults() || data.contentAssist) return null; - - final boolean indexBased= data.tu != null && data.tu.getIndex() != null; + + final boolean indexBased= data.tu != null && data.tu.getIndex() != null; @SuppressWarnings("unchecked") ObjectSet fns= ObjectSet.EMPTY_SET; IBinding type = null; IBinding obj = null; IBinding temp = null; - + Object[] items = (Object[]) data.foundItems; for (int i = 0; i < items.length && items[i] != null; i++) { Object o = items[i]; @@ -1987,7 +1987,7 @@ public class CPPSemantics { fns.put((ICPPFunction) temp); } else if (temp instanceof IType) { // Specializations are selected during instantiation - if (temp instanceof ICPPClassTemplatePartialSpecialization) + if (temp instanceof ICPPClassTemplatePartialSpecialization) continue; if (temp instanceof ICPPTemplateInstance) { temp= ((ICPPTemplateInstance) temp).getSpecializedBinding(); @@ -2039,7 +2039,7 @@ public class CPPSemantics { if (cmp == 0) { return new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.getFoundBindings()); - } + } } } @@ -2053,7 +2053,7 @@ public class CPPSemantics { } bindings = ArrayUtil.trim(IBinding.class, bindings); ICPPUsingDeclaration composite = new CPPUsingDeclaration(data.astName, bindings); - return composite; + return composite; } if (obj != null && type != null) { @@ -2077,8 +2077,8 @@ public class CPPSemantics { final ICPPFunction[] fnArray = fns.keyArray(ICPPFunction.class); if (type != null && overrulesByRelevance(data, type, fnArray)) { return type; - } - + } + if (obj != null) { int cmp= compareByRelevance(data, obj, fnArray); if (cmp == 0) { @@ -2091,7 +2091,7 @@ public class CPPSemantics { } return resolveFunction(data, fnArray, true); } - + if (obj != null) { return obj; } @@ -2130,7 +2130,7 @@ public class CPPSemantics { /** * Compares two bindings for relevance in the context of an AST. Type bindings are - * considered to overrule object bindings when the former is reachable but the + * considered to overrule object bindings when the former is reachable but the * latter is not. */ static boolean overrulesByRelevance(LookupData data, IBinding type, IBinding b2) { @@ -2141,31 +2141,31 @@ public class CPPSemantics { } /** - * Compares a binding with a list of function candidates for relevance in the - * context of an AST. Types are considered to overrule object bindings when + * Compares a binding with a list of function candidates for relevance in the + * context of an AST. Types are considered to overrule object bindings when * the former is reachable but none of the functions are. */ static boolean overrulesByRelevance(LookupData data, IBinding type, IFunction[] fns) { if (data == null || data.tu == null) { return false; } - + for (int i = 0; i < fns.length; i++) { if (!isFromIndex(fns[i])) { return false; // function from ast } } - + if (!isReachableFromAst(data.tu, type)) { return false; } - + for (IFunction fn : fns) { if (isReachableFromAst(data.tu, fn)) { return false; // function from ast } } - return true; + return true; } @@ -2218,7 +2218,7 @@ public class CPPSemantics { // Everything is from the index if (!isReachableFromAst(data.tu, obj)) { return -1; // obj not reachable - } + } for (IFunction fn : fns) { if (isReachableFromAst(data.tu, fn)) { @@ -2226,8 +2226,8 @@ public class CPPSemantics { } } return 1; // no function is reachable - } - + } + // obj is not from the index for (int i = 0; i < fns.length; i++) { if (!isFromIndex(fns[i])) { @@ -2246,7 +2246,7 @@ public class CPPSemantics { } return false; } - + /** * Checks if a binding is an AST binding, or is reachable from the AST through includes. * The binding is assumed to belong to the AST, if it is not an IIndexBinding and not @@ -2310,8 +2310,8 @@ public class CPPSemantics { if (fn != null && !(fn instanceof IProblemBinding)) { if (fn instanceof ICPPUnknownBinding) { return new ICPPFunction[] {fn}; - } - + } + // The index is optimized to provide the function type, try not to use the parameters // as long as possible. final ICPPFunctionType ft = fn.getType(); @@ -2350,16 +2350,16 @@ public class CPPSemantics { } return result; } - + public static IBinding resolveFunction(LookupData data, ICPPFunction[] fns, boolean allowUDC) throws DOMException { fns= ArrayUtil.trim(ICPPFunction.class, fns); if (fns == null || fns.length == 0) return null; - + sortAstBeforeIndex(fns); - - if (data.forUsingDeclaration()) - return new CPPUsingDeclaration(data.astName, fns); + + if (data.forUsingDeclaration()) + return new CPPUsingDeclaration(data.astName, fns); if (data.astName instanceof ICPPASTConversionName) { return resolveUserDefinedConversion(data, fns); @@ -2368,7 +2368,7 @@ public class CPPSemantics { if (data.forDeclaration() != null) { return resolveFunctionDeclaration(data, fns); } - + // No arguments to resolve function if (!data.hasFunctionArguments()) { return createFunctionSet(data.astName, fns); @@ -2377,10 +2377,10 @@ public class CPPSemantics { // Reduce our set of candidate functions to only those who have the right number of parameters final IType[] argTypes = data.getFunctionArgumentTypes(); ICPPFunction[] tmp= selectByArgumentCount(data, fns); - tmp= CPPTemplates.instantiateForFunctionCall(data.astName, tmp, - Arrays.asList(argTypes), + tmp= CPPTemplates.instantiateForFunctionCall(data.astName, tmp, + Arrays.asList(argTypes), Arrays.asList(data.getFunctionArgumentValueCategories()), data.argsContainImpliedObject); - if (tmp.length == 0 || tmp[0] == null) + if (tmp.length == 0 || tmp[0] == null) return new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_NAME_NOT_FOUND, fns); int viableCount= 0; @@ -2389,22 +2389,22 @@ public class CPPSemantics { setTargetedFunctionsToUnknown(argTypes); return f; } - if (f == null) + if (f == null) break; ++viableCount; } - if (viableCount == 0) + if (viableCount == 0) return new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_NAME_NOT_FOUND, fns); // Check for dependent arguments fns= tmp; if (CPPTemplates.containsDependentType(argTypes)) { - if (viableCount == 1) + if (viableCount == 1) return fns[0]; setTargetedFunctionsToUnknown(argTypes); return CPPUnknownFunction.createForSample(fns[0]); } - + IFunction[] ambiguousFunctions= null; // ambiguity, 2 functions are equally good FunctionCost bestFnCost = null; // the cost of the best function @@ -2412,20 +2412,20 @@ public class CPPSemantics { List potentialCosts= null; IFunction unknownFunction= null; for (ICPPFunction fn : fns) { - if (fn == null) + if (fn == null) continue; - + final FunctionCost fnCost= costForFunctionCall(fn, allowUDC, data); if (fnCost == null) continue; - + if (fnCost == CONTAINS_DEPENDENT_TYPES) { - if (viableCount == 1) + if (viableCount == 1) return fn; unknownFunction = fn; continue; } - + if (fnCost.hasDeferredUDC()) { if (potentialCosts == null) { potentialCosts= new ArrayList(); @@ -2441,7 +2441,7 @@ public class CPPSemantics { ambiguousFunctions= ArrayUtil.append(IFunction.class, ambiguousFunctions, fn); } } - + if (potentialCosts != null) { for (FunctionCost fnCost : potentialCosts) { if (!fnCost.mustBeWorse(bestFnCost) && fnCost.performUDC()) { @@ -2457,13 +2457,13 @@ public class CPPSemantics { } if (bestFnCost == null) { - if (unknownFunction == null) + if (unknownFunction == null) return null; - + setTargetedFunctionsToUnknown(argTypes); return CPPUnknownFunction.createForSample(unknownFunction); } - + if (ambiguousFunctions != null) { ambiguousFunctions= ArrayUtil.append(IFunction.class, ambiguousFunctions, bestFnCost.getFunction()); return new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, @@ -2473,7 +2473,7 @@ public class CPPSemantics { return new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.getFoundBindings()); } - + for (int i = 0; i < argTypes.length; i++) { IType iType = argTypes[i]; if (iType instanceof FunctionSetType) { @@ -2484,7 +2484,7 @@ public class CPPSemantics { if (bestFnCost.isDirectInitWithCopyCtor()) { Cost c0= bestFnCost.getCost(0); IFunction firstConversion= c0.getUserDefinedConversion(); - if (firstConversion instanceof ICPPConstructor) + if (firstConversion instanceof ICPPConstructor) return firstConversion; } return result; @@ -2507,12 +2507,12 @@ public class CPPSemantics { for (ICPPFunction f : fns) { // Use the ast binding final boolean fromIndex = isFromIndex(f); - if (haveASTResult && fromIndex) + if (haveASTResult && fromIndex) break; - + if (f instanceof ICPPFunctionTemplate) { // Works only if there are template arguments - if (!haveTemplateArgs || result != null) + if (!haveTemplateArgs || result != null) return null; result= f; haveASTResult= !fromIndex; @@ -2523,10 +2523,10 @@ public class CPPSemantics { haveASTResult= !fromIndex; } } - - if (result instanceof ICPPFunctionTemplate) + + if (result instanceof ICPPFunctionTemplate) return CPPTemplates.instantiateForAddressOfFunction((ICPPFunctionTemplate) result, null, name); - + return result; } @@ -2539,22 +2539,22 @@ public class CPPSemantics { } /** - * Called for declarations with qualified name or template-id. Also for explicit function + * Called for declarations with qualified name or template-id. Also for explicit function * specializations or instantiations. */ private static IBinding resolveFunctionDeclaration(LookupData data, ICPPFunction[] fns) throws DOMException { final IASTDeclarator dtor= ASTQueries.findTypeRelevantDeclarator(data.getDeclarator()); final IType t = CPPVisitor.createType(dtor); - if (!(t instanceof ICPPFunctionType)) + if (!(t instanceof ICPPFunctionType)) return null; - + final ICPPFunctionType ft= (ICPPFunctionType) t; IASTName templateID= data.astName; if (templateID.getPropertyInParent() == ICPPASTTemplateId.TEMPLATE_NAME) { templateID= (ICPPASTTemplateId) templateID.getParent(); - } - + } + // 14.5.4 Friends with template ids require instantiation boolean isFriend= CPPVisitor.isFriendDeclaration(data.forDeclaration()); if (!data.forExplicitFunctionSpecialization() @@ -2568,12 +2568,12 @@ public class CPPSemantics { } } // 14.5.4 Friends with qualified ids allow for instantiation - if (!data.forExplicitFunctionInstantiation() + if (!data.forExplicitFunctionInstantiation() && !(isFriend && templateID.getParent() instanceof ICPPASTQualifiedName)) { return null; } } - + // Try to instantiate a template IASTTranslationUnit tu= data.tu; ICPPTemplateArgument[] tmplArgs= ICPPTemplateArgument.EMPTY_ARGUMENTS; @@ -2585,13 +2585,13 @@ public class CPPSemantics { ICPPFunction bestInst= null; boolean isAmbiguous= false; for (ICPPFunction fn : fns) { - if (fn instanceof ICPPFunctionTemplate + if (fn instanceof ICPPFunctionTemplate && !(fn instanceof IProblemBinding) && !(fn instanceof ICPPUnknownBinding)) { ICPPFunctionTemplate template= (ICPPFunctionTemplate) fn; ICPPFunction inst= CPPTemplates.instantiateForFunctionDeclaration(template, tmplArgs, ft); if (inst != null) { int cmp= CPPTemplates.orderFunctionTemplates(bestTemplate, template, TypeSelection.PARAMETERS_AND_RETURN_TYPE); - if (cmp == 0) + if (cmp == 0) cmp= compareByRelevance(tu, bestTemplate, template); if (cmp == 0) @@ -2653,12 +2653,12 @@ public class CPPSemantics { result= new FunctionCost(fn, sourceLen); } else { result= new FunctionCost(fn, sourceLen + 1); - + ValueCategory sourceIsLValue= LVALUE; if (impliedObjectType == null) { impliedObjectType= data.getImpliedObjectType(); } - if (fn instanceof ICPPMethod && + if (fn instanceof ICPPMethod && (((ICPPMethod) fn).isDestructor() || ASTInternal.isStatic(fn, false))) { // 13.3.1-4 for static member functions, the implicit object parameter always matches, no cost cost = new Cost(impliedObjectType, implicitParameterType, Rank.IDENTITY); @@ -2678,14 +2678,14 @@ public class CPPSemantics { IType t= getNestedType(implicitParameterType, TDEF|REF|CVTYPE); if (SemanticUtil.calculateInheritanceDepth(s, t) >= 0) return null; - + return CONTAINS_DEPENDENT_TYPES; } } } if (!cost.converts()) return null; - + result.setCost(k++, cost, sourceIsLValue); } @@ -2706,8 +2706,8 @@ public class CPPSemantics { cost = new Cost(argType, null, Rank.ELLIPSIS_CONVERSION); result.setCost(k++, cost, sourceIsLValue); continue; - } - + } + if (argType instanceof FunctionSetType) { cost= ((FunctionSetType) argType).costForTarget(paramType); } else if (argType.isSameType(paramType)) { @@ -2715,7 +2715,7 @@ public class CPPSemantics { } else { if (CPPTemplates.isDependentType(paramType)) return CONTAINS_DEPENDENT_TYPES; - + Context ctx= Context.ORDINARY; if (j == 0 && sourceLen == 1 && fn instanceof ICPPConstructor) { if (paramType instanceof ICPPReferenceType) { @@ -2732,7 +2732,7 @@ public class CPPSemantics { } if (!cost.converts()) return null; - + result.setCost(k++, cost, sourceIsLValue); } return result; @@ -2755,7 +2755,7 @@ public class CPPSemantics { if (t instanceof ISemanticProblem) { return new ProblemBinding(astName, IProblemBinding.SEMANTIC_INVALID_TYPE, data.getFoundBindings()); } - if (data.forDeclaration() == null || + if (data.forDeclaration() == null || data.forExplicitFunctionSpecialization() || data.forExplicitFunctionInstantiation()) { fns= CPPTemplates.instantiateConversionTemplates(fns, t); } @@ -2782,12 +2782,12 @@ public class CPPSemantics { static IBinding resolveTargetedFunction(IASTName name, ICPPFunction[] fns) { boolean addressOf= false; IASTNode node= name.getParent(); - while (node instanceof IASTName) + while (node instanceof IASTName) node= node.getParent(); - - if (!(node instanceof IASTIdExpression)) + + if (!(node instanceof IASTIdExpression)) return new ProblemBinding(name, IProblemBinding.SEMANTIC_INVALID_OVERLOAD); - + ASTNodeProperty prop= node.getPropertyInParent(); IASTNode parent = node.getParent(); while (parent instanceof IASTUnaryExpression) { @@ -2802,7 +2802,7 @@ public class CPPSemantics { prop= node.getPropertyInParent(); parent= node.getParent(); } - + IType targetType= null; if (prop == IASTDeclarator.INITIALIZER) { // Target is an object or reference being initialized @@ -2857,7 +2857,7 @@ public class CPPSemantics { IASTBinaryExpression binaryExp = (IASTBinaryExpression) parent; if (binaryExp.getOperator() == IASTBinaryExpression.op_assign) { targetType= binaryExp.getOperand1().getExpressionType(); - } + } } else if (prop == IASTFunctionCallExpression.ARGUMENT) { // Target is a parameter of a function, need to resolve the function call IASTFunctionCallExpression fnCall = (IASTFunctionCallExpression) parent; @@ -2914,20 +2914,20 @@ public class CPPSemantics { } } } - if (targetType == null && parent instanceof IASTExpression + if (targetType == null && parent instanceof IASTExpression && parent instanceof IASTImplicitNameOwner) { // Trigger resolution of overloaded operator, which may resolve the // function set. - ((IASTImplicitNameOwner) parent).getImplicitNames(); + ((IASTImplicitNameOwner) parent).getImplicitNames(); final IBinding newBinding = name.getPreBinding(); - if (!(newBinding instanceof CPPFunctionSet)) + if (!(newBinding instanceof CPPFunctionSet)) return newBinding; - } + } ICPPFunction function = resolveTargetedFunction(targetType, name, fns); if (function == null) return new ProblemBinding(name, IProblemBinding.SEMANTIC_INVALID_OVERLOAD); - + return function; } @@ -2943,7 +2943,7 @@ public class CPPSemantics { return fn; } } - + // Second pass, consider templates ICPPFunction result= null; ICPPFunctionTemplate resultTemplate= null; @@ -2956,12 +2956,12 @@ public class CPPSemantics { ICPPFunction inst= CPPTemplates.instantiateForAddressOfFunction(template, (ICPPFunctionType) targetType, name); if (inst != null) { int cmp= CPPTemplates.orderFunctionTemplates(resultTemplate, template, TypeSelection.PARAMETERS_AND_RETURN_TYPE); - if (cmp == 0) + if (cmp == 0) cmp= compareByRelevance(tu, resultTemplate, template); if (cmp == 0) isAmbiguous= true; - + if (cmp < 0) { isAmbiguous= false; resultTemplate= template; @@ -2974,10 +2974,10 @@ public class CPPSemantics { } if (isAmbiguous) return null; - + return result; } - + public static ICPPFunction findOverloadedOperator(IASTArraySubscriptExpression exp) { final IASTExpression arrayExpression = exp.getArrayExpression(); IASTInitializerClause[] args = {arrayExpression, exp.getArgument()}; @@ -2994,20 +2994,20 @@ public class CPPSemantics { argsToPass.add(e); } args = argsToPass.toArray(new IASTInitializerClause[argsToPass.size()]); - + return findOverloadedOperator(exp, args, type, OverloadableOperator.PAREN, LookupMode.NO_GLOBALS); } - + public static ICPPFunction findOverloadedOperator(ICPPASTNewExpression expr) { OverloadableOperator op = OverloadableOperator.fromNewExpression(expr); IType type = getTypeOfPointer(expr.getExpressionType()); if (type == null) return null; - + IASTTypeId typeId = expr.getTypeId().copy(); IASTExpression sizeExpression = new CPPASTTypeIdExpression(IASTTypeIdExpression.op_sizeof, typeId); sizeExpression.setParent(expr); - + IASTInitializerClause[] placement = expr.getPlacementArguments(); List args = new ArrayList(); args.add(createArgForType(expr, type)); @@ -3015,8 +3015,8 @@ public class CPPSemantics { if (placement != null) { for (IASTInitializerClause p : placement) { args.add(p); - } - } + } + } IASTInitializerClause[] argArray = args.toArray(new IASTInitializerClause[args.size()]); return findOverloadedOperator(expr, argArray, type, op, LookupMode.GLOBALS_IF_NO_MEMBERS); } @@ -3030,7 +3030,7 @@ public class CPPSemantics { IASTExpression[] args = {createArgForType(expr, type), expr.getOperand()}; return findOverloadedOperator(expr, args, type, op, LookupMode.GLOBALS_IF_NO_MEMBERS); } - + private static IType getTypeOfPointer(IType type) { type = SemanticUtil.getNestedType(type, SemanticUtil.TDEF | SemanticUtil.REF | SemanticUtil.CVTYPE); if (type instanceof IPointerType) { @@ -3087,7 +3087,7 @@ public class CPPSemantics { return null; if (type instanceof ICPPClassTemplate || type instanceof ICPPUnknownClassType || type instanceof ISemanticProblem) return null; - + final ICPPClassType classType = (ICPPClassType) type; if (initializer instanceof IASTEqualsInitializer) { // Copy initialization @@ -3160,7 +3160,7 @@ public class CPPSemantics { IType t = getTypeOfPointer(expr.getOperand().getExpressionType()); if (!(t instanceof ICPPClassType)) return null; - + ICPPClassType cls = (ICPPClassType) t; IScope scope = cls.getCompositeScope(); if (scope == null) @@ -3192,7 +3192,7 @@ public class CPPSemantics { @Override public IType getType() { return type; } - }); + }); final CPPASTIdExpression idExpression = new CPPASTIdExpression(x); idExpression.setParent(node); return idExpression; @@ -3209,16 +3209,16 @@ public class CPPSemantics { IType type = typeOrFunctionSet(operand); type = SemanticUtil.getNestedType(type, TDEF | REF | CVTYPE); - if (!isUserDefined(type)) + if (!isUserDefined(type)) return null; IASTExpression[] args; int operator = exp.getOperator(); - if (operator == IASTUnaryExpression.op_postFixDecr || operator == IASTUnaryExpression.op_postFixIncr) { + if (operator == IASTUnaryExpression.op_postFixDecr || operator == IASTUnaryExpression.op_postFixIncr) { args = new IASTExpression[] { operand, CPPASTLiteralExpression.INT_ZERO }; } else { args = new IASTExpression[] { operand }; - } + } return findOverloadedOperator(exp, args, type, op, LookupMode.LIMITED_GLOBALS); } @@ -3226,7 +3226,7 @@ public class CPPSemantics { OverloadableOperator op = OverloadableOperator.fromBinaryExpression(exp); if (op == null) return null; - + final IASTExpression op1 = exp.getOperand1(); final IASTExpression op2 = exp.getOperand2(); if(op2==null){ @@ -3236,7 +3236,7 @@ public class CPPSemantics { IType op2type = getNestedType(typeOrFunctionSet(op2), TDEF | REF | CVTYPE); if (!isUserDefined(op1type) && !isUserDefined(op2type)) return null; - + final IASTExpression[] args = new IASTExpression[] { op1, op2 }; final LookupMode lookupNonMember; if (exp.getOperator() == IASTBinaryExpression.op_assign) { @@ -3246,19 +3246,19 @@ public class CPPSemantics { } return findOverloadedOperator(exp, args, op1type, op, lookupNonMember); } - + /** - * For simplicity returns an operator of form RT (T, T) rather than RT (boolean, T, T) + * For simplicity returns an operator of form RT (T, T) rather than RT (boolean, T, T) */ public static ICPPFunction findOverloadedConditionalOperator(IASTExpression positive, IASTExpression negative) { final IASTExpression parent = (IASTExpression) positive.getParent(); final IASTExpression[] args = new IASTExpression[] {positive, negative}; - return findOverloadedOperator(parent, args, null, + return findOverloadedOperator(parent, args, null, OverloadableOperator.CONDITIONAL_OPERATOR, LookupMode.NO_GLOBALS); } /** - * Returns the operator,() function that would apply to the two given arguments. + * Returns the operator,() function that would apply to the two given arguments. * The lookup type of the class where the operator,() might be found must also be provided. */ public static ICPPFunction findOverloadedOperatorComma(IASTExpression first, final IType lookupType, final ValueCategory valueCat, IASTExpression second) { @@ -3272,13 +3272,13 @@ public class CPPSemantics { @Override public ValueCategory getValueCategory() { return valueCat; } }; dummy.setParent(first); - + IASTExpression[] args = new IASTExpression[] { dummy , second }; return findOverloadedOperator(dummy, args, op1type, OverloadableOperator.COMMA, LookupMode.LIMITED_GLOBALS); } /** - * Returns the operator->() function + * Returns the operator->() function */ public static ICPPFunction findOverloadedOperator(ICPPASTFieldReference fieldRef, IType cvQualifiedType, ICPPClassType classType) { IASTExpression arg = CPPSemantics.createArgForType(fieldRef, cvQualifiedType); @@ -3286,7 +3286,7 @@ public class CPPSemantics { } private static enum LookupMode {NO_GLOBALS, GLOBALS_IF_NO_MEMBERS, LIMITED_GLOBALS, ALL_GLOBALS} - private static ICPPFunction findOverloadedOperator(IASTExpression parent, IASTInitializerClause[] args, IType methodLookupType, + private static ICPPFunction findOverloadedOperator(IASTExpression parent, IASTInitializerClause[] args, IType methodLookupType, OverloadableOperator operator, LookupMode mode) { ICPPClassType callToObjectOfClassType= null; IType type2= null; @@ -3294,13 +3294,13 @@ public class CPPSemantics { type2 = typeOrFunctionSet((IASTExpression) args[1]); type2= getNestedType(type2, TDEF | REF | CVTYPE); } - + if (methodLookupType instanceof ICPPUnknownType || type2 instanceof ICPPUnknownType) { - if (methodLookupType instanceof FunctionSetType) + if (methodLookupType instanceof FunctionSetType) ((FunctionSetType) methodLookupType).setToUnknown(); - if (type2 instanceof FunctionSetType) + if (type2 instanceof FunctionSetType) ((FunctionSetType) type2).setToUnknown(); - + return new CPPUnknownFunction(null, operator.toCharArray()); } @@ -3318,13 +3318,13 @@ public class CPPSemantics { methodData = new LookupData(methodName); methodData.setFunctionArguments(true, args); methodData.forceQualified = true; // (13.3.1.2.3) - + try { IScope scope = classType.getCompositeScope(); if (scope == null) return null; lookup(methodData, scope); - + if (parent instanceof IASTFunctionCallExpression) { callToObjectOfClassType= classType; } @@ -3332,13 +3332,13 @@ public class CPPSemantics { return null; } } - + // Find a function CPPASTName funcName = new CPPASTName(operator.toCharArray()); funcName.setParent(parent); funcName.setPropertyInParent(STRING_LOOKUP_PROPERTY); LookupData funcData = new LookupData(funcName); - + // Global new and delete operators do not take an argument for the this pointer. switch (operator) { case DELETE: case DELETE_ARRAY: @@ -3384,22 +3384,22 @@ public class CPPSemantics { } catch (DOMException e) { return null; } - + if (operator == OverloadableOperator.NEW || operator == OverloadableOperator.DELETE || operator == OverloadableOperator.NEW_ARRAY || operator == OverloadableOperator.DELETE_ARRAY) { - + // Those operators replace the built-in operator Object[] items= (Object[]) funcData.foundItems; int j= 0; for (Object object : items) { if (object instanceof ICPPFunction) { ICPPFunction func= (ICPPFunction) object; - if (!(func instanceof CPPImplicitFunction)) + if (!(func instanceof CPPImplicitFunction)) items[j++]= func; } } if (j>0) { - while (j < items.length) + while (j < items.length) items[j++]= null; } } @@ -3431,11 +3431,11 @@ public class CPPSemantics { while (j < items.length) { items[j++]= null; } - } + } } - } - - if (callToObjectOfClassType != null) { + } + + if (callToObjectOfClassType != null) { try { // 13.3.1.1.2 call to object of class type ICPPMethod[] ops = SemanticUtil.getConversionOperators(callToObjectOfClassType); @@ -3459,12 +3459,12 @@ public class CPPSemantics { return null; } } - + if (methodLookupType instanceof ICPPClassType || type2 instanceof ICPPClassType) { ICPPFunction[] builtins= BuiltinOperators.create(operator, args, parent.getTranslationUnit(), (Object[]) funcData.foundItems); mergeResults(funcData, builtins, false); } - + try { IBinding binding = null; if (methodData != null && funcData.hasResults()) { @@ -3476,15 +3476,15 @@ public class CPPSemantics { } else if (methodData != null) { binding = resolveAmbiguities(methodData, methodName); } - + if (binding instanceof ICPPFunction) return (ICPPFunction) binding; } catch (DOMException e) { } - + return null; } - + private static IBinding createSurrogateCallFunction(IScope scope, IType returnType, IType rt, IType[] parameterTypes) { IType[] parms = new IType[parameterTypes.length + 1]; ICPPParameter[] theParms = new ICPPParameter[parms.length]; @@ -3503,10 +3503,10 @@ public class CPPSemantics { private static boolean isUserDefined(IType type) { if (type instanceof ISemanticProblem) return false; - + return type instanceof ICPPClassType || type instanceof IEnumeration || type instanceof ICPPUnknownType; } - + public static IBinding[] findBindings(IScope scope, String name, boolean qualified) { return findBindings(scope, name.toCharArray(), qualified, null); } @@ -3523,12 +3523,12 @@ public class CPPSemantics { if (beforeNode instanceof ASTNode) { astName.setOffsetAndLength((ASTNode) beforeNode); } - + LookupData data = new LookupData(astName); data.forceQualified = qualified; return standardLookup(data, scope); } - + public static IBinding[] findBindingsForContentAssist(IASTName name, boolean prefixLookup, String[] additionalNamespaces) { LookupData data = createLookupData(name); @@ -3579,18 +3579,18 @@ public class CPPSemantics { return null; } } - + // Name did not specify a namespace, e.g. "::" if (nsScope == tu.getScope()) return null; - + return nsScope; } - private static IBinding[] contentAssistLookup(LookupData data, List additionalNamespaces) { + private static IBinding[] contentAssistLookup(LookupData data, List additionalNamespaces) { try { lookup(data, null); - + if (additionalNamespaces != null) { data.ignoreUsingDirectives = true; data.forceQualified = true; @@ -3607,7 +3607,7 @@ public class CPPSemantics { IBinding[] result = IBinding.EMPTY_BINDING_ARRAY; if (!map.isEmpty()) { char[] key = null; - int size = map.size(); + int size = map.size(); for (int i = 0; i < size; i++) { key = map.keyAt(i); result = addContentAssistBinding(result, map.get(key)); @@ -3627,7 +3627,7 @@ public class CPPSemantics { if (obj instanceof IASTName) { return addContentAssistBinding(result, ((IASTName) obj).resolveBinding()); } - + if (obj instanceof IBinding && !(obj instanceof IProblemBinding)) { final IBinding binding = (IBinding) obj; if (binding instanceof ICPPFunction) { @@ -3638,7 +3638,7 @@ public class CPPSemantics { } return ArrayUtil.append(result, binding); } - + return result; } @@ -3648,7 +3648,7 @@ public class CPPSemantics { } catch (DOMException e) { return new IBinding[] { e.getProblem() }; } - + Object[] items = (Object[]) data.foundItems; if (items == null) return new IBinding[0]; @@ -3674,16 +3674,16 @@ public class CPPSemantics { } } } - + return set.keyArray(IBinding.class); } - + public static boolean isSameFunction(ICPPFunction function, IASTDeclarator declarator) { final ICPPASTDeclarator innerDtor = (ICPPASTDeclarator) ASTQueries.findInnermostDeclarator(declarator); IASTName name = innerDtor.getName(); ICPPASTTemplateDeclaration templateDecl = CPPTemplates.getTemplateDeclaration(name); if (templateDecl != null) { - + if (templateDecl instanceof ICPPASTTemplateSpecialization) { if (!(function instanceof ICPPTemplateInstance)) return false; @@ -3701,7 +3701,7 @@ public class CPPSemantics { } } else if (function instanceof ICPPTemplateDefinition) { return false; - } + } declarator= ASTQueries.findTypeRelevantDeclarator(declarator); if (declarator instanceof ICPPASTFunctionDeclarator) { @@ -3710,13 +3710,13 @@ public class CPPSemantics { } return false; } - + private static boolean isSameTemplateParameterList(ICPPTemplateParameter[] tplist, ICPPASTTemplateParameter[] tps) { if (tplist.length != tps.length) return false; - + for (int i = 0; i < tps.length; i++) { - if (!isSameTemplateParameter(tplist[i], tps[i])) + if (!isSameTemplateParameter(tplist[i], tps[i])) return false; } return true; @@ -3725,7 +3725,7 @@ public class CPPSemantics { static boolean isSameTemplateParameter(ICPPTemplateParameter tp1, ICPPASTTemplateParameter tp2) { if (tp1.isParameterPack() != tp2.isParameterPack()) return false; - + if (tp1 instanceof ICPPTemplateNonTypeParameter) { if (tp2 instanceof ICPPASTParameterDeclaration) { IType t1= ((ICPPTemplateNonTypeParameter) tp1).getType(); @@ -3748,26 +3748,26 @@ public class CPPSemantics { } return false; } - + return false; } - static protected IBinding resolveUnknownName(IScope scope, ICPPUnknownBinding unknown) { + protected static IBinding resolveUnknownName(IScope scope, ICPPUnknownBinding unknown) { final IASTName unknownName = unknown.getUnknownName(); LookupData data = new LookupData(unknownName); data.checkPointOfDecl= false; data.typesOnly= unknown instanceof IType; - + try { // 2: lookup lookup(data, scope); } catch (DOMException e) { data.problem = (ProblemBinding) e.getProblem(); } - + if (data.problem != null) return data.problem; - + // 3: resolve ambiguities IBinding binding; try { @@ -3778,7 +3778,7 @@ public class CPPSemantics { // 4: Normal post processing is not possible, because the name is not rooted in AST if (binding == null) binding = new ProblemBinding(unknownName, IProblemBinding.SEMANTIC_NAME_NOT_FOUND); - + return binding; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java index 1975cd67965..68aee31d1ff 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java @@ -2529,7 +2529,7 @@ public class CPPVisitor extends ASTQueries { * Traverses a chain of nested homogeneous left-to-right-associative binary expressions and * returns a list of their operands in left-to-right order. For example, for the expression * a + b * c + d, it will return a list containing expressions: a, b * c, and d. - * + * * @param binaryExpression the top-level binary expression * @return a list of expression operands from left to right */