1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-07 17:56:01 +02:00

Cosmetics.

This commit is contained in:
Sergey Prigogin 2014-04-03 12:04:06 -07:00
parent 5a6ebce09c
commit ed4784c133
5 changed files with 41 additions and 38 deletions

View file

@ -33,8 +33,9 @@ public class ObjectSet<T> extends ObjectTable<T> {
public static <T> ObjectSet<T> emptySet() { public static <T> ObjectSet<T> emptySet() {
return EMPTY_SET; return EMPTY_SET;
} }
/** /**
* Construct an empty ObjectSet, allocating an initial storage for the specified * Constructs an empty ObjectSet, allocating an initial storage for the specified
* number of elements * number of elements
* @param initialSize * @param initialSize
*/ */
@ -43,7 +44,7 @@ public class ObjectSet<T> extends ObjectTable<T> {
} }
/** /**
* Construct an ObjectSet populated with the specified items, or an empty ObjectSet * Constructs an ObjectSet populated with the specified items, or an empty ObjectSet
* if the parameter is null * if the parameter is null
* @param items * @param items
*/ */

View file

@ -592,7 +592,7 @@ public class CPPSemantics {
// don't ascend into enclosing scopes. // don't ascend into enclosing scopes.
boolean originalQualified = data.qualified; boolean originalQualified = data.qualified;
data.qualified = true; data.qualified = true;
Set<ICPPFunction> friendFns = new HashSet<ICPPFunction>(2); Set<ICPPFunction> friendFns = new HashSet<>(2);
Set<ICPPNamespaceScope> associated = getAssociatedScopes(data, friendFns); Set<ICPPNamespaceScope> associated = getAssociatedScopes(data, friendFns);
for (ICPPNamespaceScope scope : associated) { for (ICPPNamespaceScope scope : associated) {
if (!data.visited.containsKey(scope)) { if (!data.visited.containsKey(scope)) {
@ -717,8 +717,8 @@ public class CPPSemantics {
return Collections.emptySet(); return Collections.emptySet();
IType[] ps = data.getFunctionArgumentTypes(); IType[] ps = data.getFunctionArgumentTypes();
Set<ICPPNamespaceScope> namespaces = new HashSet<ICPPNamespaceScope>(2); Set<ICPPNamespaceScope> namespaces = new HashSet<>(2);
ObjectSet<IType> handled = new ObjectSet<IType>(2); ObjectSet<IType> handled = new ObjectSet<>(2);
for (IType p : ps) { for (IType p : ps) {
try { try {
getAssociatedScopes(p, namespaces, friendFns, handled, data.getTranslationUnit()); getAssociatedScopes(p, namespaces, friendFns, handled, data.getTranslationUnit());
@ -882,7 +882,7 @@ public class CPPSemantics {
*/ */
static CharArrayObjectMap<Object> mergePrefixResults(CharArrayObjectMap<Object> dest, Object source, boolean scoped) { static CharArrayObjectMap<Object> mergePrefixResults(CharArrayObjectMap<Object> dest, Object source, boolean scoped) {
if (source == null) return dest; if (source == null) return dest;
CharArrayObjectMap<Object> resultMap = (dest != null) ? dest : new CharArrayObjectMap<Object>(2); CharArrayObjectMap<Object> resultMap = (dest != null) ? dest : new CharArrayObjectMap<>(2);
CharArrayObjectMap<Object> map = null; CharArrayObjectMap<Object> map = null;
Object[] objs = null; Object[] objs = null;
@ -1101,7 +1101,7 @@ public class CPPSemantics {
} }
ICPPUsingDirective[] uds= blockScope.getUsingDirectives(); ICPPUsingDirective[] uds= blockScope.getUsingDirectives();
if (uds != null && uds.length > 0) { if (uds != null && uds.length > 0) {
HashSet<ICPPNamespaceScope> handled= new HashSet<ICPPNamespaceScope>(); HashSet<ICPPNamespaceScope> handled= new HashSet<>();
for (final ICPPUsingDirective ud : uds) { for (final ICPPUsingDirective ud : uds) {
if (data.isIgnorePointOfDeclaration() || declaredBefore(ud, data.getLookupPoint(), false)) { if (data.isIgnorePointOfDeclaration() || declaredBefore(ud, data.getLookupPoint(), false)) {
storeUsingDirective(data, blockScope, ud, handled); storeUsingDirective(data, blockScope, ud, handled);
@ -1127,7 +1127,7 @@ public class CPPSemantics {
if (dqname.getLastName() != typeDtorName) if (dqname.getLastName() != typeDtorName)
return false; return false;
} }
char[] tchars= new char[typeDtorChars.length-1]; char[] tchars= new char[typeDtorChars.length - 1];
System.arraycopy(typeDtorChars, 1, tchars, 0, tchars.length); System.arraycopy(typeDtorChars, 1, tchars, 0, tchars.length);
LookupData ld2= new LookupData(tchars, data.fTemplateArguments, data.getLookupPoint()); LookupData ld2= new LookupData(tchars, data.fTemplateArguments, data.getLookupPoint());
@ -1154,7 +1154,7 @@ public class CPPSemantics {
} }
char[] classChars= classType.getNameCharArray(); char[] classChars= classType.getNameCharArray();
char[] classDtorChars= new char[classChars.length+1]; char[] classDtorChars= new char[classChars.length + 1];
classDtorChars[0]= '~'; classDtorChars[0]= '~';
System.arraycopy(classChars, 0, classDtorChars, 1, classChars.length); System.arraycopy(classChars, 0, classDtorChars, 1, classChars.length);
data.setLookupKey(classDtorChars); data.setLookupKey(classDtorChars);
@ -1303,7 +1303,7 @@ public class CPPSemantics {
break; break;
if (b instanceof ICPPUsingDeclaration || (data.typesOnly && isObject(b))) { if (b instanceof ICPPUsingDeclaration || (data.typesOnly && isObject(b))) {
List<IBinding> result= new ArrayList<IBinding>(bindings.length); List<IBinding> result= new ArrayList<>(bindings.length);
expandUsingDeclarations(bindings, data, result); expandUsingDeclarations(bindings, data, result);
return result.toArray(new IBinding[result.size()]); return result.toArray(new IBinding[result.size()]);
} }
@ -1393,7 +1393,7 @@ public class CPPSemantics {
// store the directive with the scope where it has to be considered // store the directive with the scope where it has to be considered
List<ICPPNamespaceScope> listOfNominated= data.usingDirectives.get(appearsIn); List<ICPPNamespaceScope> listOfNominated= data.usingDirectives.get(appearsIn);
if (listOfNominated == null) { if (listOfNominated == null) {
listOfNominated= new ArrayList<ICPPNamespaceScope>(1); listOfNominated= new ArrayList<>(1);
if (data.usingDirectives.isEmpty()) { if (data.usingDirectives.isEmpty()) {
data.usingDirectives= new HashMap<ICPPNamespaceScope, List<ICPPNamespaceScope>>(); data.usingDirectives= new HashMap<ICPPNamespaceScope, List<ICPPNamespaceScope>>();
} }
@ -1421,7 +1421,7 @@ public class CPPSemantics {
*/ */
private static ICPPScope getCommonEnclosingScope(IScope s1, IScope s2, ICPPASTTranslationUnit tu) private static ICPPScope getCommonEnclosingScope(IScope s1, IScope s2, ICPPASTTranslationUnit tu)
throws DOMException { throws DOMException {
ObjectSet<IScope> set = new ObjectSet<IScope>(2); ObjectSet<IScope> set = new ObjectSet<>(2);
IScope parent= s1; IScope parent= s1;
while (parent != null) { while (parent != null) {
set.put(parent); set.put(parent);
@ -1969,10 +1969,9 @@ public class CPPSemantics {
IASTNode lookupPoint = data.getLookupPoint(); IASTNode lookupPoint = data.getLookupPoint();
final boolean indexBased= data.getIndex() != null; final boolean indexBased= data.getIndex() != null;
final boolean checkWholeClass= lookupName == null || LookupData.checkWholeClassScope(lookupName); final boolean checkWholeClass= lookupName == null || LookupData.checkWholeClassScope(lookupName);
@SuppressWarnings("unchecked") ObjectSet<ICPPFunction> fns= ObjectSet.emptySet();
ObjectSet<ICPPFunction> fns= ObjectSet.EMPTY_SET;
IBinding type = null; IBinding type = null;
IBinding obj = null; IBinding obj = null;
IBinding temp = null; IBinding temp = null;
final CPPASTTranslationUnit tu = data.getTranslationUnit(); final CPPASTTranslationUnit tu = data.getTranslationUnit();
@ -2029,7 +2028,7 @@ public class CPPSemantics {
continue; continue;
} }
if (fns == ObjectSet.EMPTY_SET) if (fns == ObjectSet.EMPTY_SET)
fns = new ObjectSet<ICPPFunction>(2); fns = new ObjectSet<>(2);
fns.put((ICPPFunction) temp); fns.put((ICPPFunction) temp);
} else if (temp instanceof IType) { } else if (temp instanceof IType) {
// Specializations are selected during instantiation // Specializations are selected during instantiation
@ -2433,13 +2432,14 @@ public class CPPSemantics {
// Reduce our set of candidate functions to only those who have the right number of parameters // Reduce our set of candidate functions to only those who have the right number of parameters
final IType[] argTypes = data.getFunctionArgumentTypes(); final IType[] argTypes = data.getFunctionArgumentTypes();
ICPPFunction[] tmp= selectByArgumentCount(data, fns); ICPPFunction[] tmp= selectByArgumentCount(data, fns);
if (tmp.length == 0 || tmp[0] == null)
return new ProblemBinding(lookupName, lookupPoint, IProblemBinding.SEMANTIC_NAME_NOT_FOUND, fns);
tmp= CPPTemplates.instantiateForFunctionCall(tmp, data.fTemplateArguments, tmp= CPPTemplates.instantiateForFunctionCall(tmp, data.fTemplateArguments,
Arrays.asList(argTypes), Arrays.asList(argTypes),
Arrays.asList(data.getFunctionArgumentValueCategories()), Arrays.asList(data.getFunctionArgumentValueCategories()),
data.argsContainImpliedObject, lookupPoint); data.argsContainImpliedObject, lookupPoint);
if (tmp.length == 0 || tmp[0] == null) { if (tmp.length == 0 || tmp[0] == null)
return new ProblemBinding(lookupName, lookupPoint, IProblemBinding.SEMANTIC_NAME_NOT_FOUND, fns); return new ProblemBinding(lookupName, lookupPoint, IProblemBinding.SEMANTIC_NAME_NOT_FOUND, fns);
}
int viableCount= 0; int viableCount= 0;
for (IFunction f : tmp) { for (IFunction f : tmp) {
@ -2487,7 +2487,7 @@ public class CPPSemantics {
if (fnCost.hasDeferredUDC()) { if (fnCost.hasDeferredUDC()) {
if (potentialCosts == null) { if (potentialCosts == null) {
potentialCosts= new ArrayList<FunctionCost>(); potentialCosts= new ArrayList<>();
} }
potentialCosts.add(fnCost); potentialCosts.add(fnCost);
continue; continue;
@ -3592,10 +3592,10 @@ public class CPPSemantics {
LookupData data = createLookupData(name); LookupData data = createLookupData(name);
data.contentAssist = true; data.contentAssist = true;
data.setPrefixLookup(prefixLookup); data.setPrefixLookup(prefixLookup);
data.foundItems = new CharArrayObjectMap<Object>(2); data.foundItems = new CharArrayObjectMap<>(2);
// Convert namespaces to scopes. // Convert namespaces to scopes.
List<ICPPScope> nsScopes= new ArrayList<ICPPScope>(); List<ICPPScope> nsScopes= new ArrayList<>();
IASTTranslationUnit tu = name.getTranslationUnit(); IASTTranslationUnit tu = name.getTranslationUnit();
if (additionalNamespaces != null && tu instanceof CPPASTTranslationUnit) { if (additionalNamespaces != null && tu instanceof CPPASTTranslationUnit) {
for (String nsName : additionalNamespaces) { for (String nsName : additionalNamespaces) {
@ -3678,7 +3678,7 @@ public class CPPSemantics {
scope = global; scope = global;
} }
Set<IBinding> bindings = new HashSet<IBinding>(); Set<IBinding> bindings = new HashSet<>();
// Look for the name in the given scope. // Look for the name in the given scope.
findBindingsForQualifiedName(scope, qualifiedName, bindings); findBindingsForQualifiedName(scope, qualifiedName, bindings);
@ -3814,9 +3814,9 @@ public class CPPSemantics {
Object[] items = (Object[]) data.foundItems; Object[] items = (Object[]) data.foundItems;
if (items == null) if (items == null)
return new IBinding[0]; return IBinding.EMPTY_BINDING_ARRAY;
ObjectSet<IBinding> set = new ObjectSet<IBinding>(items.length); ObjectSet<IBinding> set = new ObjectSet<>(items.length);
IBinding binding = null; IBinding binding = null;
for (Object item : items) { for (Object item : items) {
if (item instanceof IASTName) { if (item instanceof IASTName) {

View file

@ -167,7 +167,6 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.Conversions.Context; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.Conversions.Context;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.Conversions.UDCMode; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.Conversions.UDCMode;
/** /**
* Collection of static methods to perform template instantiation, member specialization and * Collection of static methods to perform template instantiation, member specialization and
* type instantiation. * type instantiation.
@ -780,7 +779,9 @@ public class CPPTemplates {
IType instantiatedType = instantiateType(aliasedType, parameterMap, -1, within, id); IType instantiatedType = instantiateType(aliasedType, parameterMap, -1, within, id);
StringBuilder buf= new StringBuilder(); StringBuilder buf= new StringBuilder();
buf.append(id.getSimpleID()).append(ASTTypeUtil.getArgumentListString(args, false)); buf.append(id.getSimpleID()).append(ASTTypeUtil.getArgumentListString(args, false));
return new CPPAliasTemplateInstance(buf.toString().toCharArray(), aliasTemplate, instantiatedType); char[] name = new char[buf.length()];
buf.getChars(0, buf.length(), name, 0);
return new CPPAliasTemplateInstance(name, aliasTemplate, instantiatedType);
} }
static boolean isClassTemplate(ICPPASTTemplateId id) { static boolean isClassTemplate(ICPPASTTemplateId id) {
@ -1963,12 +1964,13 @@ public class CPPTemplates {
if (!haveTemplate && !requireTemplate) if (!haveTemplate && !requireTemplate)
return fns; return fns;
final List<ICPPFunction> result= new ArrayList<ICPPFunction>(fns.length); final List<ICPPFunction> result= new ArrayList<>(fns.length);
for (ICPPFunction fn : fns) { for (ICPPFunction fn : fns) {
if (fn != null) { if (fn != null) {
if (fn instanceof ICPPFunctionTemplate) { if (fn instanceof ICPPFunctionTemplate) {
ICPPFunctionTemplate fnTmpl= (ICPPFunctionTemplate) fn; ICPPFunctionTemplate fnTmpl= (ICPPFunctionTemplate) fn;
ICPPFunction inst = instantiateForFunctionCall(fnTmpl, tmplArgs, fnArgs, argCats, withImpliedObjectArg, point); ICPPFunction inst = instantiateForFunctionCall(fnTmpl, tmplArgs, fnArgs, argCats,
withImpliedObjectArg, point);
if (inst != null) if (inst != null)
result.add(inst); result.add(inst);
} else if (!requireTemplate || fn instanceof ICPPUnknownBinding) { } else if (!requireTemplate || fn instanceof ICPPUnknownBinding) {

View file

@ -6,9 +6,9 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Bryan Wilkinson (QNX) - Initial API and implementation * Bryan Wilkinson (QNX) - Initial API and implementation
* Andrew Ferguson (Symbian) * Andrew Ferguson (Symbian)
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom.cpp; package org.eclipse.cdt.internal.core.pdom.dom.cpp;
@ -45,10 +45,10 @@ class PDOMCPPFunctionInstance extends PDOMCPPFunctionSpecialization implements I
final ICPPTemplateInstance asInstance= (ICPPTemplateInstance) function; final ICPPTemplateInstance asInstance= (ICPPTemplateInstance) function;
final long argListRec= PDOMCPPArgumentList.putArguments(this, asInstance.getTemplateArguments()); final long argListRec= PDOMCPPArgumentList.putArguments(this, asInstance.getTemplateArguments());
final Database db = getDB(); final Database db = getDB();
db.putRecPtr(record+ARGUMENTS, argListRec); db.putRecPtr(record + ARGUMENTS, argListRec);
long exceptSpecRec = PDOMCPPTypeList.putTypes(this, function.getExceptionSpecification()); long exceptSpecRec = PDOMCPPTypeList.putTypes(this, function.getExceptionSpecification());
db.putRecPtr(record+EXCEPTION_SPEC, exceptSpecRec); db.putRecPtr(record + EXCEPTION_SPEC, exceptSpecRec);
} }
public PDOMCPPFunctionInstance(PDOMLinkage linkage, long bindingRecord) { public PDOMCPPFunctionInstance(PDOMLinkage linkage, long bindingRecord) {
@ -82,7 +82,7 @@ class PDOMCPPFunctionInstance extends PDOMCPPFunctionSpecialization implements I
@Override @Override
public ICPPTemplateArgument[] getTemplateArguments() { public ICPPTemplateArgument[] getTemplateArguments() {
try { try {
final long rec= getPDOM().getDB().getRecPtr(record+ARGUMENTS); final long rec= getPDOM().getDB().getRecPtr(record + ARGUMENTS);
return PDOMCPPArgumentList.getArguments(this, rec); return PDOMCPPArgumentList.getArguments(this, rec);
} catch (CoreException e) { } catch (CoreException e) {
CCorePlugin.log(e); CCorePlugin.log(e);
@ -93,7 +93,7 @@ class PDOMCPPFunctionInstance extends PDOMCPPFunctionSpecialization implements I
@Override @Override
public IType[] getExceptionSpecification() { public IType[] getExceptionSpecification() {
try { try {
final long rec = getPDOM().getDB().getRecPtr(record+EXCEPTION_SPEC); final long rec = getPDOM().getDB().getRecPtr(record + EXCEPTION_SPEC);
return PDOMCPPTypeList.getTypes(this, rec); return PDOMCPPTypeList.getTypes(this, rec);
} catch (CoreException e) { } catch (CoreException e) {
CCorePlugin.log(e); CCorePlugin.log(e);

View file

@ -51,7 +51,7 @@ public class PDOMInstanceCache {
private ICPPDeferredClassInstance fDeferredInstance; private ICPPDeferredClassInstance fDeferredInstance;
public PDOMInstanceCache() { public PDOMInstanceCache() {
fMap= new HashMap<String, ICPPTemplateInstance>(); fMap= new HashMap<>();
} }
synchronized public final void addInstance(ICPPTemplateArgument[] arguments, ICPPTemplateInstance instance) { synchronized public final void addInstance(ICPPTemplateArgument[] arguments, ICPPTemplateInstance instance) {
@ -102,7 +102,7 @@ public class PDOMInstanceCache {
return fDeferredInstance; return fDeferredInstance;
} }
public void putDeferredInstance(ICPPDeferredClassInstance dci) { public void putDeferredInstance(ICPPDeferredClassInstance deferredInstance) {
fDeferredInstance= dci; fDeferredInstance= deferredInstance;
} }
} }