mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Fixes exceptions parsing c-files, bug 213287
This commit is contained in:
parent
f0953b21f0
commit
da6d9d1a66
4 changed files with 47 additions and 39 deletions
|
@ -1168,7 +1168,7 @@ public class IndexBugsTests extends BaseTestCase {
|
||||||
fIndex.acquireReadLock();
|
fIndex.acquireReadLock();
|
||||||
try {
|
try {
|
||||||
IIndexBinding[] bindings = fIndex.findBindings("staticInHeader".toCharArray(),
|
IIndexBinding[] bindings = fIndex.findBindings("staticInHeader".toCharArray(),
|
||||||
IndexFilter.ALL, NPM);
|
IndexFilter.C_DECLARED_OR_IMPLICIT, NPM);
|
||||||
IFunction func = (IFunction) bindings[0];
|
IFunction func = (IFunction) bindings[0];
|
||||||
assertTrue(func.isStatic());
|
assertTrue(func.isStatic());
|
||||||
IIndexName[] refs = fIndex.findReferences(func);
|
IIndexName[] refs = fIndex.findReferences(func);
|
||||||
|
@ -1195,7 +1195,7 @@ public class IndexBugsTests extends BaseTestCase {
|
||||||
fIndex.acquireReadLock();
|
fIndex.acquireReadLock();
|
||||||
try {
|
try {
|
||||||
IIndexBinding[] bindings = fIndex.findBindings("staticConstInHeader".toCharArray(),
|
IIndexBinding[] bindings = fIndex.findBindings("staticConstInHeader".toCharArray(),
|
||||||
IndexFilter.ALL, NPM);
|
IndexFilter.C_DECLARED_OR_IMPLICIT, NPM);
|
||||||
IVariable var = (IVariable) bindings[0];
|
IVariable var = (IVariable) bindings[0];
|
||||||
assertTrue(var.isStatic());
|
assertTrue(var.isStatic());
|
||||||
IIndexName[] refs = fIndex.findReferences(var);
|
IIndexName[] refs = fIndex.findReferences(var);
|
||||||
|
|
|
@ -34,7 +34,6 @@ import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator;
|
||||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||||
import org.eclipse.cdt.internal.core.dom.Linkage;
|
import org.eclipse.cdt.internal.core.dom.Linkage;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor;
|
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.PlatformObject;
|
import org.eclipse.core.runtime.PlatformObject;
|
||||||
|
|
||||||
|
@ -110,7 +109,7 @@ public class CFunction extends PlatformObject implements IFunction, ICInternalFu
|
||||||
bits |= RESOLUTION_IN_PROGRESS;
|
bits |= RESOLUTION_IN_PROGRESS;
|
||||||
IASTTranslationUnit tu = getTranslationUnit();
|
IASTTranslationUnit tu = getTranslationUnit();
|
||||||
if( tu != null ){
|
if( tu != null ){
|
||||||
CPPVisitor.getDeclarations( tu, this );
|
CVisitor.getDeclarations( tu, this );
|
||||||
}
|
}
|
||||||
declarators = (IASTStandardFunctionDeclarator[]) ArrayUtil.trim( IASTStandardFunctionDeclarator.class, declarators );
|
declarators = (IASTStandardFunctionDeclarator[]) ArrayUtil.trim( IASTStandardFunctionDeclarator.class, declarators );
|
||||||
bits |= FULLY_RESOLVED;
|
bits |= FULLY_RESOLVED;
|
||||||
|
|
|
@ -91,7 +91,6 @@ import org.eclipse.cdt.core.dom.ast.c.ICASTSimpleDeclSpecifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.c.ICASTTypedefNameSpecifier;
|
import org.eclipse.cdt.core.dom.ast.c.ICASTTypedefNameSpecifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.c.ICCompositeTypeScope;
|
import org.eclipse.cdt.core.dom.ast.c.ICCompositeTypeScope;
|
||||||
import org.eclipse.cdt.core.dom.ast.c.ICFunctionScope;
|
import org.eclipse.cdt.core.dom.ast.c.ICFunctionScope;
|
||||||
import org.eclipse.cdt.core.dom.ast.c.ICScope;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression;
|
import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator;
|
import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator;
|
||||||
import org.eclipse.cdt.core.dom.ast.gnu.c.IGCCASTSimpleDeclSpecifier;
|
import org.eclipse.cdt.core.dom.ast.gnu.c.IGCCASTSimpleDeclSpecifier;
|
||||||
|
@ -119,9 +118,8 @@ public class CVisitor {
|
||||||
}
|
}
|
||||||
public int visit(IASTName name) {
|
public int visit(IASTName name) {
|
||||||
if ( name.getBinding() != null ) {
|
if ( name.getBinding() != null ) {
|
||||||
ICScope scope;
|
|
||||||
try {
|
try {
|
||||||
scope = (ICScope)name.resolveBinding().getScope();
|
IScope scope = name.resolveBinding().getScope();
|
||||||
if ( scope != null )
|
if ( scope != null )
|
||||||
ASTInternal.removeBinding(scope, name.resolveBinding());
|
ASTInternal.removeBinding(scope, name.resolveBinding());
|
||||||
} catch ( DOMException e ) {
|
} catch ( DOMException e ) {
|
||||||
|
@ -492,13 +490,14 @@ public class CVisitor {
|
||||||
|
|
||||||
private static IBinding createBinding( ICASTEnumerationSpecifier enumeration ){
|
private static IBinding createBinding( ICASTEnumerationSpecifier enumeration ){
|
||||||
IASTName name = enumeration.getName();
|
IASTName name = enumeration.getName();
|
||||||
ICScope scope = (ICScope) getContainingScope( enumeration );
|
IScope scope = getContainingScope( enumeration );
|
||||||
IBinding binding;
|
IBinding binding= null;
|
||||||
try {
|
if (scope != null) {
|
||||||
binding = scope.getBinding( name, false );
|
try {
|
||||||
} catch ( DOMException e ) {
|
binding = scope.getBinding( name, false );
|
||||||
binding = null;
|
} catch ( DOMException e ) {
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (binding != null && !(binding instanceof IIndexBinding)) {
|
if (binding != null && !(binding instanceof IIndexBinding)) {
|
||||||
if (binding instanceof IEnumeration) {
|
if (binding instanceof IEnumeration) {
|
||||||
if (binding instanceof CEnumeration) {
|
if (binding instanceof CEnumeration) {
|
||||||
|
@ -721,9 +720,11 @@ public class CVisitor {
|
||||||
int op = ((IASTUnaryExpression)expression).getOperator();
|
int op = ((IASTUnaryExpression)expression).getOperator();
|
||||||
if( op == IASTUnaryExpression.op_sizeof ){
|
if( op == IASTUnaryExpression.op_sizeof ){
|
||||||
IScope scope = getContainingScope( expression );
|
IScope scope = getContainingScope( expression );
|
||||||
IBinding [] bs = scope.find( SIZE_T );
|
if (scope != null) {
|
||||||
if( bs.length > 0 && bs[0] instanceof IType ){
|
IBinding [] bs = scope.find( SIZE_T );
|
||||||
return (IType) bs[0];
|
if( bs.length > 0 && bs[0] instanceof IType ){
|
||||||
|
return (IType) bs[0];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return new CBasicType( IBasicType.t_int, CBasicType.IS_LONG | CBasicType.IS_UNSIGNED, expression );
|
return new CBasicType( IBasicType.t_int, CBasicType.IS_LONG | CBasicType.IS_UNSIGNED, expression );
|
||||||
}
|
}
|
||||||
|
@ -815,7 +816,7 @@ public class CVisitor {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( declarator.getParent() instanceof IASTFunctionDefinition ) {
|
if ( declarator.getParent() instanceof IASTFunctionDefinition ) {
|
||||||
ICScope scope = (ICScope) ((IASTCompoundStatement)((IASTFunctionDefinition)declarator.getParent()).getBody()).getScope();
|
IScope scope = ((IASTCompoundStatement)((IASTFunctionDefinition)declarator.getParent()).getBody()).getScope();
|
||||||
if ( scope != null && binding != null )
|
if ( scope != null && binding != null )
|
||||||
try {
|
try {
|
||||||
ASTInternal.addName( scope, name);
|
ASTInternal.addName( scope, name);
|
||||||
|
@ -854,7 +855,7 @@ public class CVisitor {
|
||||||
}
|
}
|
||||||
while (node instanceof IASTDeclarator);
|
while (node instanceof IASTDeclarator);
|
||||||
|
|
||||||
ICScope scope = (ICScope) getContainingScope( parent );
|
IScope scope = getContainingScope( parent );
|
||||||
|
|
||||||
ASTNodeProperty prop = parent.getPropertyInParent();
|
ASTNodeProperty prop = parent.getPropertyInParent();
|
||||||
if( prop == IASTDeclarationStatement.DECLARATION ){
|
if( prop == IASTDeclarationStatement.DECLARATION ){
|
||||||
|
@ -941,19 +942,21 @@ public class CVisitor {
|
||||||
|
|
||||||
|
|
||||||
private static IBinding createBinding( ICASTCompositeTypeSpecifier compositeTypeSpec ){
|
private static IBinding createBinding( ICASTCompositeTypeSpecifier compositeTypeSpec ){
|
||||||
ICScope scope = null;
|
IScope scope = null;
|
||||||
IBinding binding = null;
|
IBinding binding = null;
|
||||||
IASTName name = compositeTypeSpec.getName();
|
IASTName name = compositeTypeSpec.getName();
|
||||||
try {
|
try {
|
||||||
scope = (ICScope) getContainingScope( compositeTypeSpec );
|
scope = getContainingScope( compositeTypeSpec );
|
||||||
while( scope instanceof ICCompositeTypeScope )
|
while( scope instanceof ICCompositeTypeScope )
|
||||||
scope = (ICScope) scope.getParent();
|
scope = scope.getParent();
|
||||||
|
|
||||||
binding = scope.getBinding( name, false );
|
if (scope != null) {
|
||||||
if( binding != null && !(binding instanceof IIndexBinding)){
|
binding = scope.getBinding( name, false );
|
||||||
if (binding instanceof CStructure)
|
if( binding != null && !(binding instanceof IIndexBinding)){
|
||||||
((CStructure)binding).addDefinition( compositeTypeSpec );
|
if (binding instanceof CStructure)
|
||||||
return binding;
|
((CStructure)binding).addDefinition( compositeTypeSpec );
|
||||||
|
return binding;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (DOMException e2) {
|
} catch (DOMException e2) {
|
||||||
}
|
}
|
||||||
|
@ -961,8 +964,8 @@ public class CVisitor {
|
||||||
binding = new CStructure( name );
|
binding = new CStructure( name );
|
||||||
|
|
||||||
try {
|
try {
|
||||||
scope = (ICScope) binding.getScope();
|
scope= binding.getScope();
|
||||||
ASTInternal.addName( scope, name );
|
ASTInternal.addName(scope, name);
|
||||||
} catch ( DOMException e ) {
|
} catch ( DOMException e ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1094,6 +1097,9 @@ public class CVisitor {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* May return <code>null</code>, e.g. for parameter names in function-prototypes.
|
||||||
|
*/
|
||||||
public static IScope getContainingScope( IASTNode node ){
|
public static IScope getContainingScope( IASTNode node ){
|
||||||
if( node == null )
|
if( node == null )
|
||||||
return null;
|
return null;
|
||||||
|
@ -1122,7 +1128,7 @@ public class CVisitor {
|
||||||
parent = ((IASTDeclarator)parent).getParent();
|
parent = ((IASTDeclarator)parent).getParent();
|
||||||
if ( parent instanceof IASTFunctionDefinition )
|
if ( parent instanceof IASTFunctionDefinition )
|
||||||
return ((IASTCompoundStatement)((IASTFunctionDefinition)parent).getBody()).getScope();
|
return ((IASTCompoundStatement)((IASTFunctionDefinition)parent).getBody()).getScope();
|
||||||
return null;
|
return null; // parameter name in function declarations
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if( node instanceof IASTEnumerator ){
|
else if( node instanceof IASTEnumerator ){
|
||||||
|
@ -1206,10 +1212,10 @@ public class CVisitor {
|
||||||
|
|
||||||
IASTNode parent = blockItem.getParent();
|
IASTNode parent = blockItem.getParent();
|
||||||
IASTNode [] nodes = null;
|
IASTNode [] nodes = null;
|
||||||
ICScope scope = null;
|
IScope scope = null;
|
||||||
if( parent instanceof IASTCompoundStatement ){
|
if( parent instanceof IASTCompoundStatement ){
|
||||||
IASTCompoundStatement compound = (IASTCompoundStatement) parent;
|
IASTCompoundStatement compound = (IASTCompoundStatement) parent;
|
||||||
scope = (ICScope) compound.getScope();
|
scope = compound.getScope();
|
||||||
|
|
||||||
if( parent.getParent() instanceof IASTFunctionDefinition ){
|
if( parent.getParent() instanceof IASTFunctionDefinition ){
|
||||||
IASTFunctionDeclarator dtor = ((IASTFunctionDefinition)parent.getParent()).getDeclarator();
|
IASTFunctionDeclarator dtor = ((IASTFunctionDefinition)parent.getParent()).getDeclarator();
|
||||||
|
@ -1225,7 +1231,7 @@ public class CVisitor {
|
||||||
IASTTranslationUnit translation = (IASTTranslationUnit) parent;
|
IASTTranslationUnit translation = (IASTTranslationUnit) parent;
|
||||||
if (!prefix) {
|
if (!prefix) {
|
||||||
nodes = translation.getDeclarations();
|
nodes = translation.getDeclarations();
|
||||||
scope = (ICScope) translation.getScope();
|
scope = translation.getScope();
|
||||||
} else {
|
} else {
|
||||||
// The index will be search later, still we need to look at the declarations found in
|
// The index will be search later, still we need to look at the declarations found in
|
||||||
// the AST, bug 180883
|
// the AST, bug 180883
|
||||||
|
@ -1235,11 +1241,11 @@ public class CVisitor {
|
||||||
} else if( parent instanceof IASTStandardFunctionDeclarator ){
|
} else if( parent instanceof IASTStandardFunctionDeclarator ){
|
||||||
IASTStandardFunctionDeclarator dtor = (IASTStandardFunctionDeclarator) parent;
|
IASTStandardFunctionDeclarator dtor = (IASTStandardFunctionDeclarator) parent;
|
||||||
nodes = dtor.getParameters();
|
nodes = dtor.getParameters();
|
||||||
scope = (ICScope) getContainingScope( blockItem );
|
scope = getContainingScope( blockItem );
|
||||||
} else if( parent instanceof ICASTKnRFunctionDeclarator ){
|
} else if( parent instanceof ICASTKnRFunctionDeclarator ){
|
||||||
ICASTKnRFunctionDeclarator dtor = (ICASTKnRFunctionDeclarator) parent;
|
ICASTKnRFunctionDeclarator dtor = (ICASTKnRFunctionDeclarator) parent;
|
||||||
nodes = dtor.getParameterDeclarations();
|
nodes = dtor.getParameterDeclarations();
|
||||||
scope = (ICScope) getContainingScope( blockItem );
|
scope = getContainingScope( blockItem );
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean typesOnly = (bits & TAGS) != 0;
|
boolean typesOnly = (bits & TAGS) != 0;
|
||||||
|
@ -1401,7 +1407,7 @@ public class CVisitor {
|
||||||
return external;
|
return external;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IASTName checkForBinding( ICScope scope, IASTDeclSpecifier declSpec, IASTName name, boolean typesOnly, CharArrayObjectMap prefixMap ) throws DOMException{
|
private static IASTName checkForBinding( IScope scope, IASTDeclSpecifier declSpec, IASTName name, boolean typesOnly, CharArrayObjectMap prefixMap ) throws DOMException{
|
||||||
IASTName tempName = null;
|
IASTName tempName = null;
|
||||||
IASTName resultName = null;
|
IASTName resultName = null;
|
||||||
char [] n = name.toCharArray();
|
char [] n = name.toCharArray();
|
||||||
|
@ -1485,7 +1491,7 @@ public class CVisitor {
|
||||||
return prefixMap;
|
return prefixMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IASTName checkForBinding( ICScope scope, IASTParameterDeclaration paramDecl, IASTName name, boolean typesOnly, CharArrayObjectMap prefixMap ) throws DOMException{
|
private static IASTName checkForBinding( IScope scope, IASTParameterDeclaration paramDecl, IASTName name, boolean typesOnly, CharArrayObjectMap prefixMap ) throws DOMException{
|
||||||
if( paramDecl == null ) return null;
|
if( paramDecl == null ) return null;
|
||||||
|
|
||||||
IASTDeclarator dtor = paramDecl.getDeclarator();
|
IASTDeclarator dtor = paramDecl.getDeclarator();
|
||||||
|
@ -1513,7 +1519,7 @@ public class CVisitor {
|
||||||
* if not a prefix lookup, returns IASTName
|
* if not a prefix lookup, returns IASTName
|
||||||
* if doing prefix lookup, results are in prefixMap, returns null
|
* if doing prefix lookup, results are in prefixMap, returns null
|
||||||
*/
|
*/
|
||||||
private static IASTName checkForBinding( ICScope scope, IASTNode node, IASTName name, boolean typesOnly, CharArrayObjectMap prefixMap ) throws DOMException{
|
private static IASTName checkForBinding( IScope scope, IASTNode node, IASTName name, boolean typesOnly, CharArrayObjectMap prefixMap ) throws DOMException{
|
||||||
if( node instanceof IASTDeclaration ){
|
if( node instanceof IASTDeclaration ){
|
||||||
return checkForBinding( scope, (IASTDeclaration) node, name, typesOnly, prefixMap );
|
return checkForBinding( scope, (IASTDeclaration) node, name, typesOnly, prefixMap );
|
||||||
} else if( node instanceof IASTParameterDeclaration ){
|
} else if( node instanceof IASTParameterDeclaration ){
|
||||||
|
@ -1528,7 +1534,7 @@ public class CVisitor {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
private static IASTName checkForBinding( ICScope scope, IASTDeclaration declaration, IASTName name, boolean typesOnly, CharArrayObjectMap prefixMap ) throws DOMException{
|
private static IASTName checkForBinding( IScope scope, IASTDeclaration declaration, IASTName name, boolean typesOnly, CharArrayObjectMap prefixMap ) throws DOMException{
|
||||||
char [] n = name.toCharArray();
|
char [] n = name.toCharArray();
|
||||||
IASTName tempName = null;
|
IASTName tempName = null;
|
||||||
IASTName resultName = null;
|
IASTName resultName = null;
|
||||||
|
|
|
@ -51,6 +51,7 @@ import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
import org.eclipse.core.runtime.IStatus;
|
import org.eclipse.core.runtime.IStatus;
|
||||||
import org.eclipse.core.runtime.MultiStatus;
|
import org.eclipse.core.runtime.MultiStatus;
|
||||||
|
import org.eclipse.core.runtime.Status;
|
||||||
import org.eclipse.osgi.util.NLS;
|
import org.eclipse.osgi.util.NLS;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -142,6 +143,8 @@ abstract public class PDOMWriter {
|
||||||
if (msg.equals(status.getMessage())) {
|
if (msg.equals(status.getMessage())) {
|
||||||
throw new CoreException(status);
|
throw new CoreException(status);
|
||||||
}
|
}
|
||||||
|
throw new CoreException(new Status(status.getSeverity(), status.getPlugin(), status.getCode(),
|
||||||
|
msg + ':' + status.getMessage(), status.getException()));
|
||||||
}
|
}
|
||||||
throw new CoreException(new MultiStatus(CCorePlugin.PLUGIN_ID, 0,
|
throw new CoreException(new MultiStatus(CCorePlugin.PLUGIN_ID, 0,
|
||||||
(IStatus[]) stati.toArray(new IStatus[stati.size()]), msg, null));
|
(IStatus[]) stati.toArray(new IStatus[stati.size()]), msg, null));
|
||||||
|
|
Loading…
Add table
Reference in a new issue