mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-07 01:36:01 +02:00
Cosmetics.
This commit is contained in:
parent
c1a3773622
commit
bb1eb7f5f7
1 changed files with 36 additions and 35 deletions
|
@ -73,9 +73,9 @@ import org.eclipse.core.runtime.NullProgressMonitor;
|
||||||
public class CScope implements ICScope, IASTInternalScope {
|
public class CScope implements ICScope, IASTInternalScope {
|
||||||
/**
|
/**
|
||||||
* ISO C:99 6.2.3 there are separate namespaces for various categories of
|
* ISO C:99 6.2.3 there are separate namespaces for various categories of
|
||||||
* identifiers: - label names ( labels have ICFunctionScope ) - tags of
|
* identifiers: - label names (labels have ICFunctionScope) - tags of
|
||||||
* structures or unions : NAMESPACE_TYPE_TAG - members of structures or
|
* structures or unions : NAMESPACE_TYPE_TAG - members of structures or
|
||||||
* unions ( members have ICCompositeTypeScope ) - all other identifiers :
|
* unions (members have ICCompositeTypeScope) - all other identifiers :
|
||||||
* NAMESPACE_TYPE_OTHER
|
* NAMESPACE_TYPE_OTHER
|
||||||
*/
|
*/
|
||||||
public static final int NAMESPACE_TYPE_TAG = 0;
|
public static final int NAMESPACE_TYPE_TAG = 0;
|
||||||
|
@ -128,37 +128,39 @@ public class CScope implements ICScope, IASTInternalScope {
|
||||||
* @see org.eclipse.cdt.core.dom.ast.IScope#getParent()
|
* @see org.eclipse.cdt.core.dom.ast.IScope#getParent()
|
||||||
*/
|
*/
|
||||||
public IScope getParent() {
|
public IScope getParent() {
|
||||||
return CVisitor.getContainingScope( physicalNode );
|
return CVisitor.getContainingScope(physicalNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static class CollectNamesAction extends ASTVisitor {
|
protected static class CollectNamesAction extends ASTVisitor {
|
||||||
private char [] name;
|
private char[] name;
|
||||||
private IASTName [] result = null;
|
private IASTName[] result = null;
|
||||||
CollectNamesAction( char [] n ){
|
|
||||||
|
CollectNamesAction(char[] n) {
|
||||||
name = n;
|
name = n;
|
||||||
shouldVisitNames = true;
|
shouldVisitNames = true;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public int visit( IASTName n ){
|
public int visit(IASTName n) {
|
||||||
ASTNodeProperty prop = n.getPropertyInParent();
|
ASTNodeProperty prop = n.getPropertyInParent();
|
||||||
if( prop == IASTElaboratedTypeSpecifier.TYPE_NAME ||
|
if (prop == IASTElaboratedTypeSpecifier.TYPE_NAME ||
|
||||||
prop == IASTCompositeTypeSpecifier.TYPE_NAME ||
|
prop == IASTCompositeTypeSpecifier.TYPE_NAME ||
|
||||||
prop == IASTDeclarator.DECLARATOR_NAME )
|
prop == IASTDeclarator.DECLARATOR_NAME) {
|
||||||
{
|
if (CharArrayUtils.equals(n.toCharArray(), name))
|
||||||
if( CharArrayUtils.equals( n.toCharArray(), name ) )
|
result = (IASTName[]) ArrayUtil.append(IASTName.class, result, n);
|
||||||
result = (IASTName[]) ArrayUtil.append( IASTName.class, result, n );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return PROCESS_CONTINUE;
|
return PROCESS_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int visit( IASTStatement statement ){
|
public int visit(IASTStatement statement) {
|
||||||
if( statement instanceof IASTDeclarationStatement )
|
if (statement instanceof IASTDeclarationStatement)
|
||||||
return PROCESS_CONTINUE;
|
return PROCESS_CONTINUE;
|
||||||
return PROCESS_SKIP;
|
return PROCESS_SKIP;
|
||||||
}
|
}
|
||||||
public IASTName [] getNames(){
|
|
||||||
return (IASTName[]) ArrayUtil.trim( IASTName.class, result );
|
public IASTName[] getNames() {
|
||||||
|
return (IASTName[]) ArrayUtil.trim(IASTName.class, result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,7 +171,7 @@ public class CScope implements ICScope, IASTInternalScope {
|
||||||
return CVisitor.findBindings(this, name);
|
return CVisitor.findBindings(this, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IBinding getBinding( int namespaceType, char [] name ){
|
public IBinding getBinding(int namespaceType, char[] name) {
|
||||||
Object o= mapsToNameOrBinding[namespaceType].get(name);
|
Object o= mapsToNameOrBinding[namespaceType].get(name);
|
||||||
if (o instanceof IBinding)
|
if (o instanceof IBinding)
|
||||||
return (IBinding) o;
|
return (IBinding) o;
|
||||||
|
@ -221,19 +223,18 @@ public class CScope implements ICScope, IASTInternalScope {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getNamespaceType( IASTName name ){
|
private int getNamespaceType(IASTName name) {
|
||||||
ASTNodeProperty prop = name.getPropertyInParent();
|
ASTNodeProperty prop = name.getPropertyInParent();
|
||||||
if( prop == IASTCompositeTypeSpecifier.TYPE_NAME ||
|
if (prop == IASTCompositeTypeSpecifier.TYPE_NAME ||
|
||||||
prop == IASTElaboratedTypeSpecifier.TYPE_NAME ||
|
prop == IASTElaboratedTypeSpecifier.TYPE_NAME ||
|
||||||
prop == IASTEnumerationSpecifier.ENUMERATION_NAME ||
|
prop == IASTEnumerationSpecifier.ENUMERATION_NAME ||
|
||||||
prop == CVisitor.STRING_LOOKUP_TAGS_PROPERTY )
|
prop == CVisitor.STRING_LOOKUP_TAGS_PROPERTY) {
|
||||||
{
|
|
||||||
return NAMESPACE_TYPE_TAG;
|
return NAMESPACE_TYPE_TAG;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NAMESPACE_TYPE_OTHER;
|
return NAMESPACE_TYPE_OTHER;
|
||||||
}
|
}
|
||||||
public final IBinding getBinding( IASTName name, boolean resolve ) {
|
public final IBinding getBinding(IASTName name, boolean resolve) {
|
||||||
return getBinding(name, resolve, IIndexFileSet.EMPTY);
|
return getBinding(name, resolve, IIndexFileSet.EMPTY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -243,7 +244,7 @@ public class CScope implements ICScope, IASTInternalScope {
|
||||||
|
|
||||||
public final IBinding getBinding(IASTName name, boolean resolve, IIndexFileSet fileSet) {
|
public final IBinding getBinding(IASTName name, boolean resolve, IIndexFileSet fileSet) {
|
||||||
char[] c = name.toCharArray();
|
char[] c = name.toCharArray();
|
||||||
if( c.length == 0 ){
|
if (c.length == 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -272,7 +273,7 @@ public class CScope implements ICScope, IASTInternalScope {
|
||||||
if (resolve && physicalNode instanceof IASTTranslationUnit) {
|
if (resolve && physicalNode instanceof IASTTranslationUnit) {
|
||||||
final IASTTranslationUnit tu = (IASTTranslationUnit)physicalNode;
|
final IASTTranslationUnit tu = (IASTTranslationUnit)physicalNode;
|
||||||
IIndex index= tu.getIndex();
|
IIndex index= tu.getIndex();
|
||||||
if(index!=null) {
|
if (index != null) {
|
||||||
try {
|
try {
|
||||||
IBinding[] bindings= index.findBindings(name.toCharArray(), INDEX_FILTERS[type], new NullProgressMonitor());
|
IBinding[] bindings= index.findBindings(name.toCharArray(), INDEX_FILTERS[type], new NullProgressMonitor());
|
||||||
if (fileSet != null) {
|
if (fileSet != null) {
|
||||||
|
@ -310,8 +311,7 @@ public class CScope implements ICScope, IASTInternalScope {
|
||||||
if (parent instanceof IASTSimpleDeclSpecifier) {
|
if (parent instanceof IASTSimpleDeclSpecifier) {
|
||||||
if (((IASTSimpleDeclSpecifier) parent).getDeclTypeExpression() != null)
|
if (((IASTSimpleDeclSpecifier) parent).getDeclTypeExpression() != null)
|
||||||
return false;
|
return false;
|
||||||
}
|
} else if (parent instanceof IASTTypeIdExpression) {
|
||||||
else if (parent instanceof IASTTypeIdExpression) {
|
|
||||||
if (((IASTTypeIdExpression) parent).getOperator() == IASTTypeIdExpression.op_typeof)
|
if (((IASTTypeIdExpression) parent).getOperator() == IASTTypeIdExpression.op_typeof)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -324,7 +324,7 @@ public class CScope implements ICScope, IASTInternalScope {
|
||||||
* @see org.eclipse.cdt.core.dom.ast.c.ICScope#getBinding(org.eclipse.cdt.core.dom.ast.IASTName, boolean)
|
* @see org.eclipse.cdt.core.dom.ast.c.ICScope#getBinding(org.eclipse.cdt.core.dom.ast.IASTName, boolean)
|
||||||
*/
|
*/
|
||||||
public final IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup, IIndexFileSet fileSet) {
|
public final IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup, IIndexFileSet fileSet) {
|
||||||
char [] c = name.toCharArray();
|
char[] c = name.toCharArray();
|
||||||
Object[] obj = null;
|
Object[] obj = null;
|
||||||
|
|
||||||
populateCache();
|
populateCache();
|
||||||
|
@ -348,15 +348,16 @@ public class CScope implements ICScope, IASTInternalScope {
|
||||||
IIndex index = tu.getIndex();
|
IIndex index = tu.getIndex();
|
||||||
if (index != null) {
|
if (index != null) {
|
||||||
try {
|
try {
|
||||||
IBinding[] bindings = prefixLookup ? index.findBindingsForContentAssist(name.toCharArray(), true, INDEX_FILTERS[NAMESPACE_TYPE_BOTH], null)
|
IBinding[] bindings = prefixLookup ?
|
||||||
: index.findBindings(name.toCharArray(), INDEX_FILTERS[NAMESPACE_TYPE_BOTH], null);
|
index.findBindingsForContentAssist(name.toCharArray(), true, INDEX_FILTERS[NAMESPACE_TYPE_BOTH], null) :
|
||||||
|
index.findBindings(name.toCharArray(), INDEX_FILTERS[NAMESPACE_TYPE_BOTH], null);
|
||||||
if (fileSet != null) {
|
if (fileSet != null) {
|
||||||
bindings = fileSet.filterFileLocalBindings(bindings);
|
bindings = fileSet.filterFileLocalBindings(bindings);
|
||||||
}
|
}
|
||||||
|
|
||||||
obj = ArrayUtil.addAll(Object.class, obj, bindings);
|
obj = ArrayUtil.addAll(Object.class, obj, bindings);
|
||||||
} catch (CoreException ce) {
|
} catch (CoreException e) {
|
||||||
CCorePlugin.log(ce);
|
CCorePlugin.log(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -392,13 +393,13 @@ public class CScope implements ICScope, IASTInternalScope {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Index results from global scope, differ from ast results from translation unit scope. This routine
|
* Index results from global scope, differ from ast results from translation unit scope. This routine
|
||||||
* is intended to fix results from the index to be consistent with ast scope behaviour.
|
* is intended to fix results from the index to be consistent with ast scope behavior.
|
||||||
* @param name the name as it occurs in the ast
|
* @param name the name as it occurs in the ast
|
||||||
* @param bindings the set of candidate bindings
|
* @param bindings the set of candidate bindings
|
||||||
* @return the appropriate binding, or null if no binding is appropriate for the ast name
|
* @return the appropriate binding, or null if no binding is appropriate for the ast name
|
||||||
*/
|
*/
|
||||||
private IBinding processIndexResults(IASTName name, IBinding[] bindings) {
|
private IBinding processIndexResults(IASTName name, IBinding[] bindings) {
|
||||||
if(bindings.length!=1)
|
if (bindings.length != 1)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
return bindings[0];
|
return bindings[0];
|
||||||
|
@ -569,7 +570,7 @@ public class CScope implements ICScope, IASTInternalScope {
|
||||||
* @see org.eclipse.cdt.core.dom.ast.IScope#getScopeName()
|
* @see org.eclipse.cdt.core.dom.ast.IScope#getScopeName()
|
||||||
*/
|
*/
|
||||||
public IName getScopeName() {
|
public IName getScopeName() {
|
||||||
if( physicalNode instanceof IASTCompositeTypeSpecifier ){
|
if (physicalNode instanceof IASTCompositeTypeSpecifier) {
|
||||||
return ((IASTCompositeTypeSpecifier) physicalNode).getName();
|
return ((IASTCompositeTypeSpecifier) physicalNode).getName();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
Loading…
Add table
Reference in a new issue