1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-23 17:05:26 +02:00

Cosmetics.

This commit is contained in:
Sergey Prigogin 2014-10-28 12:21:20 -07:00
parent 1a87fa7fe3
commit c28c3c5aab
7 changed files with 55 additions and 92 deletions

View file

@ -495,8 +495,8 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
@Override
public void setUp() throws Exception {
cproject = cpp ?
CProjectHelper.createCCProject(getName()+System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER) :
CProjectHelper.createCProject(getName()+System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER);
CProjectHelper.createCCProject(getName() + System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER) :
CProjectHelper.createCProject(getName() + System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER);
Bundle b = CTestPlugin.getDefault().getBundle();
testData = TestSourceReader.getContentsForTest(b, "parser", IndexBindingResolutionTestBase.this.getClass(), getName(), 2);

View file

@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Markus Schorn - initial API and implementation
* Markus Schorn - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.dom.ast.cpp;
@ -16,7 +16,7 @@ import org.eclipse.cdt.core.dom.ast.IASTImplicitName;
import org.eclipse.cdt.core.dom.ast.IASTImplicitNameOwner;
/**
* Lambda expression, introduced in C++0x.
* Lambda expression, introduced in C++11.
*
* @since 5.3
* @noextend This interface is not intended to be extended by clients.
@ -64,8 +64,7 @@ public interface ICPPASTLambdaExpression extends ICPPASTExpression, IASTImplicit
* when creating AST for content assist.
*/
IASTCompoundStatement getBody();
/**
* Not allowed on frozen AST.
* @see #getCaptureDefault()

View file

@ -12,121 +12,79 @@
package org.eclipse.cdt.core.dom.parser.cpp;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.cdt.core.dom.parser.IBuiltinBindingsProvider;
import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.parser.IToken.ContextSensitiveTokenType;
import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.internal.core.dom.parser.GCCBuiltinSymbolProvider;
/**
* Abstract C++ parser extension configuration to help model C++ dialects.
*
* @since 4.0
*/
public abstract class AbstractCPPParserExtensionConfiguration implements ICPPParserExtensionConfiguration {
/*
* @see org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration#allowRestrictPointerOperators()
*/
@Override
public boolean allowRestrictPointerOperators() {
return false;
}
/*
* @see org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration#supportAlignOfUnaryExpression()
*/
@Override
public boolean supportAlignOfUnaryExpression() {
return false;
}
/*
* @see org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration#supportAttributeSpecifiers()
*/
@Override
public boolean supportAttributeSpecifiers() {
return false;
}
/*
* @see org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration#supportComplexNumbers()
*/
@Override
public boolean supportComplexNumbers() {
return false;
}
/*
* @see org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration#supportDeclspecSpecifiers()
*/
@Override
public boolean supportDeclspecSpecifiers() {
return false;
}
/*
* @see org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration#supportExtendedTemplateSyntax()
*/
@Override
public boolean supportExtendedTemplateSyntax() {
return false;
}
/*
* @see org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration#supportGCCOtherBuiltinSymbols()
*/
@Override
public boolean supportGCCOtherBuiltinSymbols() {
return false;
}
/*
* @see org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration#supportKnRC()
*/
@Override
public boolean supportKnRC() {
return false;
}
/*
* @see org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration#supportLongLongs()
*/
@Override
public boolean supportLongLongs() {
return false;
}
/*
* @see org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration#supportMinAndMaxOperators()
*/
@Override
public boolean supportMinAndMaxOperators() {
return false;
}
/*
* @see org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration#supportRestrictKeyword()
*/
@Override
public boolean supportRestrictKeyword() {
return false;
}
/*
* @see org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration#supportStatementsInExpressions()
*/
@Override
public boolean supportStatementsInExpressions() {
return false;
}
/*
* @see org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration#supportTypeofUnaryExpressions()
*/
@Override
public boolean supportTypeofUnaryExpressions() {
return false;
@ -159,9 +117,6 @@ public abstract class AbstractCPPParserExtensionConfiguration implements ICPPPar
return false;
}
/*
* @see org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration#getBuiltinBindingsProvider()
*/
@Override
public IBuiltinBindingsProvider getBuiltinBindingsProvider() {
return new GCCBuiltinSymbolProvider(ParserLanguage.CPP, supportGCCOtherBuiltinSymbols());

View file

@ -30,8 +30,9 @@ import org.eclipse.cdt.internal.core.dom.parser.IASTInternalScope;
/**
* Handles ambiguities for parameter declarations.
* <br>
* <pre>
* void function(const D*); // is D a type?
* </pre>
* @since 5.0.1
*/
public class CASTAmbiguousSimpleDeclaration extends ASTAmbiguousNode implements IASTAmbiguousSimpleDeclaration {
@ -47,7 +48,7 @@ public class CASTAmbiguousSimpleDeclaration extends ASTAmbiguousNode implements
@Override
protected void beforeResolution() {
// populate containing scope, so that it will not be affected by the alternative branches.
// Populate containing scope, so that it will not be affected by the alternative branches.
IScope scope= CVisitor.getContainingScope(this);
if (scope instanceof IASTInternalScope) {
((IASTInternalScope) scope).populateCache();
@ -94,6 +95,7 @@ public class CASTAmbiguousSimpleDeclaration extends ASTAmbiguousNode implements
return fSimpleDecl.getAttributes();
}
@Deprecated
@Override
public void addAttribute(IASTAttribute attribute) {
fSimpleDecl.addAttribute(attribute);
@ -114,18 +116,18 @@ public class CASTAmbiguousSimpleDeclaration extends ASTAmbiguousNode implements
final IASTAmbiguityParent owner= (IASTAmbiguityParent) getParent();
IASTNode nodeToReplace= this;
// handle nested ambiguities first
// Handle nested ambiguities first.
owner.replace(nodeToReplace, fSimpleDecl);
IASTDeclSpecifier declSpec= fSimpleDecl.getDeclSpecifier();
declSpec.accept(resolver);
// find nested names
// Find nested names.
final NameCollector nameCollector= new NameCollector();
declSpec.accept(nameCollector);
final IASTName[] names= nameCollector.getNames();
// resolve names
// Resolve names.
boolean hasIssue= false;
for (IASTName name : names) {
try {
@ -140,13 +142,13 @@ public class CASTAmbiguousSimpleDeclaration extends ASTAmbiguousNode implements
}
}
if (hasIssue) {
// use the alternate version
// Use the alternate version.
final IASTAmbiguityParent parent = (IASTAmbiguityParent) fSimpleDecl;
parent.replace(declSpec, fAltDeclSpec);
parent.replace(fSimpleDecl.getDeclarators()[0], fAltDtor);
}
// resolve further nested ambiguities
// Resolve further nested ambiguities.
fSimpleDecl.accept(resolver);
return fSimpleDecl;
}

View file

@ -15,11 +15,13 @@
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@ -95,7 +97,7 @@ public class ClassTypeHelper {
return new IBinding[] { new ProblemBinding(node, IProblemBinding.SEMANTIC_DEFINITION_NOT_FOUND, host.getNameCharArray()) };
}
}
ObjectSet<IBinding> resultSet = new ObjectSet<IBinding>(2);
ObjectSet<IBinding> resultSet = new ObjectSet<>(2);
IASTDeclaration[] members = host.getCompositeTypeSpecifier().getMembers();
for (IASTDeclaration decl : members) {
while (decl instanceof ICPPASTTemplateDeclaration) {
@ -134,7 +136,7 @@ public class ClassTypeHelper {
* A class is considered a friend of itself.
* @param binding a binding.
* @param classType a class.
* @return <code>true</code> if <code>binding</code> is a friend of <code>classType</code>.
* @return {@code true} if {@code binding} is a friend of {@code classType}.
*/
public static boolean isFriend(IBinding binding, ICPPClassType classType) {
IType type;
@ -282,7 +284,7 @@ public class ClassTypeHelper {
* @return An array of base classes in arbitrary order.
*/
public static ICPPClassType[] getAllBases(ICPPClassType classType, IASTNode point) {
HashSet<ICPPClassType> result= new HashSet<ICPPClassType>();
HashSet<ICPPClassType> result= new HashSet<>();
result.add(classType);
getAllBases(classType, result, point);
result.remove(classType);
@ -304,7 +306,7 @@ public class ClassTypeHelper {
/**
* Checks inheritance relationship between two classes.
* @return <code>true</code> if {@code subclass} is a subclass of {@code superclass}.
* @return {@code true} if {@code subclass} is a subclass of {@code superclass}.
*/
public static boolean isSubclass(ICPPClassType subclass, ICPPClassType superclass, IASTNode point) {
ICPPBase[] bases= getBases(subclass, point);
@ -348,7 +350,7 @@ public class ClassTypeHelper {
* include methods declared in base classes.
*/
public static ObjectSet<ICPPMethod> getOwnMethods(ICPPClassType classType, IASTNode point) {
ObjectSet<ICPPMethod> set= new ObjectSet<ICPPMethod>(4);
ObjectSet<ICPPMethod> set= new ObjectSet<>(4);
set.addAll(ClassTypeHelper.getDeclaredMethods(classType, point));
set.addAll(getImplicitMethods(classType, point));
return set;
@ -585,8 +587,8 @@ public class ClassTypeHelper {
if (mcl == null)
return ICPPMethod.EMPTY_CPPMETHOD_ARRAY;
final ArrayList<ICPPMethod> result= new ArrayList<ICPPMethod>();
final HashMap<ICPPClassType, Boolean> virtualInClass= new HashMap<ICPPClassType, Boolean>();
final ArrayList<ICPPMethod> result= new ArrayList<>();
final HashMap<ICPPClassType, Boolean> virtualInClass= new HashMap<>();
final ICPPFunctionType methodType= method.getType();
virtualInClass.put(mcl, method.isVirtual());
@ -679,7 +681,7 @@ public class ClassTypeHelper {
public static ICPPMethod[] findOverriders(ICPPClassType[] subclasses, ICPPMethod method) {
final char[] mname= method.getNameCharArray();
final ICPPFunctionType mft= method.getType();
final ArrayList<ICPPMethod> result= new ArrayList<ICPPMethod>();
final ArrayList<ICPPMethod> result= new ArrayList<>();
for (ICPPClassType subClass : subclasses) {
ICPPMethod[] methods= subClass.getDeclaredMethods();
for (ICPPMethod candidate : methods) {
@ -693,14 +695,15 @@ public class ClassTypeHelper {
}
private static ICPPClassType[] getSubClasses(IIndex index, ICPPClassType mcl) throws CoreException {
List<ICPPBinding> result= new LinkedList<ICPPBinding>();
HashSet<String> handled= new HashSet<String>();
Deque<ICPPBinding> result= new ArrayDeque<>();
HashSet<String> handled= new HashSet<>();
getSubClasses(index, mcl, result, handled);
result.remove(0);
return result.toArray(new ICPPClassType[result.size()]);
}
private static void getSubClasses(IIndex index, ICPPBinding classOrTypedef, List<ICPPBinding> result, HashSet<String> handled) throws CoreException {
private static void getSubClasses(IIndex index, ICPPBinding classOrTypedef,
Collection<ICPPBinding> result, HashSet<String> handled) throws CoreException {
if (!(classOrTypedef instanceof IType))
return;
@ -778,7 +781,7 @@ public class ClassTypeHelper {
ICPPParameter[] parameters = method.getParameters();
if (parameters.length == 0)
return Collections.emptyList();
List<IType> types = new ArrayList<IType>(parameters.length);
List<IType> types = new ArrayList<>(parameters.length);
for (ICPPParameter parameter : parameters) {
if (!parameter.hasDefaultValue() && !parameter.isParameterPack())
types.add(parameter.getType());
@ -800,7 +803,7 @@ public class ClassTypeHelper {
if (kind == MethodKind.OTHER)
return null;
List<IType> inheritedTypeids = new ArrayList<IType>();
List<IType> inheritedTypeids = new ArrayList<>();
ICPPClassType[] bases= getAllBases(owner, point);
for (ICPPClassType base : bases) {
if (!(base instanceof ICPPDeferredClassInstance)) {
@ -874,11 +877,11 @@ public class ClassTypeHelper {
}
/**
* Returns the visibility for a given <code>member</code> in the <code>host</code>.
* Throws an IllegalArgumentException if <code>member</code> is not a member of <code>host</code>
* Returns the visibility for a given {@code member} in the {@code host}.
* Throws an IllegalArgumentException if {@code member} is not a member of {@code host}
*
* @param classType The class to get the member's visibility specifier of.
* @return the visibility of the <code>member</code>.
* @return the visibility of the {@code member}.
*/
public static int getVisibility(ICPPInternalClassTypeMixinHost classType, IBinding member) {
if (classType.getDefinition() == null) {

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2010 Tomasz Wesolowski
* Copyright (c) 2010, 2014 Tomasz Wesolowski
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -39,6 +39,7 @@ import org.eclipse.cdt.core.dom.ast.INodeFactory;
import org.eclipse.cdt.core.dom.ast.IPointerType;
import org.eclipse.cdt.core.dom.ast.IQualifierType;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTName;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNameSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTPointerToMember;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
@ -128,18 +129,19 @@ public class DeclarationGeneratorImpl extends DeclarationGenerator {
IASTDeclarator returnedDeclarator = null;
try {
// Addition of pointer operators has to be in reverse order, so it's deferred until the end
// Addition of pointer operators has to be in reverse order, so it's deferred until
// the end.
Map<IASTDeclarator, LinkedList<IASTPointerOperator>> pointerOperatorMap = new HashMap<IASTDeclarator, LinkedList<IASTPointerOperator>>();
IASTName newName = name != null ? factory.newName(name) : factory.newName();
// If the type is an array of something, create a declaration of a pointer to something instead
// (to allow assignment, etc)
// If the type is an array of something, create a declaration of a pointer to something
// instead (to allow assignment, etc).
boolean replaceInitialArrayWithPointer = true;
// If the type is a function, create a declaration of a pointer to this function
// (shorthand notation for function address)
// (shorthand notation for function address).
boolean changeInitialFunctionToFuncPtr = true;
@ -151,7 +153,7 @@ public class DeclarationGeneratorImpl extends DeclarationGenerator {
} else if (changeInitialFunctionToFuncPtr && type instanceof IFunctionType) {
returnedDeclarator = factory.newDeclarator(newName);
returnedDeclarator.addPointerOperator(factory.newPointer());
// leave type as it is, next iteration will handle the function
// Leave type as it is, next iteration will handle the function.
} else if (type instanceof IArrayType) {
IArrayType arrayType = (IArrayType) type;
IASTArrayDeclarator arrayDeclarator = factory.newArrayDeclarator(null);
@ -161,7 +163,7 @@ public class DeclarationGeneratorImpl extends DeclarationGenerator {
arrayDeclarator.setNestedDeclarator(returnedDeclarator);
arrayDeclarator.setName(factory.newName());
}
// consume all immediately following array expressions
// Consume all immediately following array expressions.
while (type instanceof IArrayType) {
arrayType = (IArrayType) type;
IASTExpression arraySizeExpression = arrayType.getArraySizeExpression();
@ -233,7 +235,7 @@ public class DeclarationGeneratorImpl extends DeclarationGenerator {
IASTDeclarator returnedDeclarator, IASTPointerOperator ptrOp) {
LinkedList<IASTPointerOperator> list;
if (!pointerOperatorMap.containsKey(returnedDeclarator)) {
list = new LinkedList<IASTPointerOperator>();
list = new LinkedList<>();
pointerOperatorMap.put(returnedDeclarator, list);
} else {
list = pointerOperatorMap.get(returnedDeclarator);
@ -289,13 +291,12 @@ public class DeclarationGeneratorImpl extends DeclarationGenerator {
ICPPASTTemplateId tempId = getTemplateId(type, templateName);
ICPPASTQualifiedName newQualifiedName =
((ICPPNodeFactory) factory).newQualifiedName();
((ICPPNodeFactory) factory).newQualifiedName(tempId);
ICPPASTNameSpecifier[] qualifier = fullQualifiedName.getQualifier();
int nbQualifiedNames = qualifier.length;
for (int i = 0; i < nbQualifiedNames; i++) {
newQualifiedName.addNameSpecifier(qualifier[i].copy(CopyStyle.withLocations));
}
newQualifiedName.setLastName(tempId);
return factory.newTypedefNameSpecifier(newQualifiedName);
} else {
@ -329,9 +330,12 @@ public class DeclarationGeneratorImpl extends DeclarationGenerator {
char[][] qualifiedNameCharArray = CPPVisitor.getQualifiedNameCharArray(binding);
IASTName name;
if (qualifiedNameCharArray.length > 1) {
name = ((ICPPNodeFactory) factory).newQualifiedName();
for (char[] cs : qualifiedNameCharArray) {
((ICPPASTQualifiedName) name).addName(factory.newName(cs));
char[] cs = qualifiedNameCharArray[qualifiedNameCharArray.length - 1];
IASTName segment = factory.newName(cs);
name = ((ICPPNodeFactory) factory).newQualifiedName((ICPPASTName) segment);
for (int i = 0; i < qualifiedNameCharArray.length - 1; i++) {
segment = factory.newName(cs);
((ICPPASTQualifiedName) name).addName(factory.newName(qualifiedNameCharArray[i]));
}
} else if (qualifiedNameCharArray.length == 1) {
name = factory.newName(qualifiedNameCharArray[0]);

View file

@ -234,12 +234,12 @@ public class MacroDefinitionParser {
default:
throw new InvalidMacroDefinitionException(name.getCharImage(), name.getOffset(), param.getEndOffset());
}
}
while (fHasVarArgs==0 && next.getType() == IToken.tCOMMA);
} while (fHasVarArgs == 0 && next.getType() == IToken.tCOMMA);
if (next.getType() != IToken.tRPAREN) {
throw new InvalidMacroDefinitionException(name.getCharImage(), name.getOffset(), next.getEndOffset());
}
next= lex.nextToken(); // consume the closing parenthesis
next= lex.nextToken(); // Consume the closing parenthesis.
return paramList.toArray(new char[paramList.size()][]);
}