From 2852b6fafd41fdc98d11138dda85934725d94710 Mon Sep 17 00:00:00 2001 From: Andrew Niefer Date: Mon, 31 Jan 2005 21:05:19 +0000 Subject: [PATCH] C/C++ Problems & Exceptions - semantic problems result in IProblemBindings - attempting to do too much with an IProblemBinding results in a DOMException - All IBinding, IType & IScope interface functions throw DOMException --- .../core/parser/tests/FileBasePluginTest.java | 11 - .../core/parser/tests/ast2/AST2KnRTests.java | 8 +- .../cdt/core/parser/tests/ast2/AST2Tests.java | 4 +- .../tests/ast2/CompleteParser2Tests.java | 7 +- .../cdt/core/dom/ast/DOMException.java | 35 +++ .../eclipse/cdt/core/dom/ast/IArrayType.java | 2 +- .../eclipse/cdt/core/dom/ast/IBasicType.java | 10 +- .../eclipse/cdt/core/dom/ast/IBinding.java | 2 +- .../cdt/core/dom/ast/ICompositeType.java | 9 +- .../cdt/core/dom/ast/IEnumeration.java | 2 +- .../eclipse/cdt/core/dom/ast/IEnumerator.java | 2 +- .../eclipse/cdt/core/dom/ast/IFunction.java | 13 +- .../cdt/core/dom/ast/IFunctionType.java | 4 +- .../org/eclipse/cdt/core/dom/ast/ILabel.java | 2 +- .../cdt/core/dom/ast/IPointerType.java | 6 +- .../cdt/core/dom/ast/IProblemBinding.java | 8 +- .../cdt/core/dom/ast/IQualifierType.java | 6 +- .../org/eclipse/cdt/core/dom/ast/IScope.java | 4 +- .../eclipse/cdt/core/dom/ast/ITypedef.java | 2 +- .../eclipse/cdt/core/dom/ast/IVariable.java | 2 +- .../cdt/core/dom/ast/c/ICArrayType.java | 11 +- .../cdt/core/dom/ast/c/ICBasicType.java | 3 +- .../core/dom/ast/c/ICCompositeTypeScope.java | 3 +- .../cdt/core/dom/ast/c/ICFunctionScope.java | 5 +- .../eclipse/cdt/core/dom/ast/c/ICScope.java | 7 +- .../cdt/core/dom/ast/cpp/ICPPClassType.java | 16 +- .../dom/ast/cpp/ICPPCompositeBinding.java | 3 +- .../cdt/core/dom/ast/cpp/ICPPConstructor.java | 6 +- .../cdt/core/dom/ast/cpp/ICPPMember.java | 4 +- .../cdt/core/dom/ast/cpp/ICPPNamespace.java | 3 +- .../core/dom/ast/cpp/ICPPReferenceType.java | 3 +- .../cdt/core/dom/ast/cpp/ICPPScope.java | 7 +- .../ast/cpp/ICPPTemplateTypeParameter.java | 3 +- .../core/dom/ast/gnu/cpp/IGPPBasicType.java | 5 +- .../core/dom/parser/ITypeContainer.java | 3 +- .../core/dom/parser/ProblemBinding.java | 28 +- .../core/dom/parser/c/CEnumeration.java | 15 + .../internal/core/dom/parser/c/CField.java | 6 +- .../internal/core/dom/parser/c/CFunction.java | 17 +- .../core/dom/parser/c/CFunctionType.java | 15 +- .../internal/core/dom/parser/c/CLabel.java | 12 + .../core/dom/parser/c/CParameter.java | 12 + .../core/dom/parser/c/CStructure.java | 15 +- .../internal/core/dom/parser/c/CVariable.java | 34 +-- .../internal/core/dom/parser/c/CVisitor.java | 190 +++++++++---- .../parser/cpp/CPPASTNamespaceDefinition.java | 7 +- .../core/dom/parser/cpp/CPPArrayType.java | 7 +- .../core/dom/parser/cpp/CPPClassScope.java | 14 +- .../core/dom/parser/cpp/CPPClassType.java | 12 +- .../dom/parser/cpp/CPPCompositeBinding.java | 3 +- .../core/dom/parser/cpp/CPPConstructor.java | 10 + .../core/dom/parser/cpp/CPPEnumeration.java | 14 + .../core/dom/parser/cpp/CPPField.java | 18 ++ .../core/dom/parser/cpp/CPPFunction.java | 28 +- .../core/dom/parser/cpp/CPPFunctionScope.java | 3 +- .../core/dom/parser/cpp/CPPFunctionType.java | 21 +- .../core/dom/parser/cpp/CPPMethod.java | 19 +- .../core/dom/parser/cpp/CPPReferenceType.java | 7 +- .../core/dom/parser/cpp/CPPScope.java | 32 ++- .../core/dom/parser/cpp/CPPSemantics.java | 128 +++++---- .../core/dom/parser/cpp/CPPTypedef.java | 7 +- .../core/dom/parser/cpp/CPPVariable.java | 12 + .../core/dom/parser/cpp/CPPVisitor.java | 269 ++++++++++++------ 63 files changed, 827 insertions(+), 349 deletions(-) create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/DOMException.java diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/FileBasePluginTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/FileBasePluginTest.java index aef65c27e8e..6a13f846145 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/FileBasePluginTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/FileBasePluginTest.java @@ -15,16 +15,12 @@ package org.eclipse.cdt.core.parser.tests; import java.io.ByteArrayInputStream; -import java.io.FileInputStream; -import java.io.FileNotFoundException; import java.io.InputStream; -import java.util.ArrayList; import java.util.Iterator; import java.util.List; import junit.framework.TestCase; - import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.parser.CodeReader; @@ -32,7 +28,6 @@ import org.eclipse.cdt.core.parser.IParser; import org.eclipse.cdt.core.parser.IProblem; import org.eclipse.cdt.core.parser.ISourceElementRequestor; import org.eclipse.cdt.core.parser.NullLogService; -import org.eclipse.cdt.core.parser.NullSourceElementRequestor; import org.eclipse.cdt.core.parser.ParserFactory; import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ParserMode; @@ -74,9 +69,7 @@ import org.eclipse.cdt.core.parser.ast.IASTUsingDirective; import org.eclipse.cdt.core.parser.ast.IASTVariable; import org.eclipse.cdt.core.parser.ast.IASTVariableReference; import org.eclipse.cdt.core.testplugin.CProjectHelper; -import org.eclipse.cdt.core.testplugin.CTestPlugin; import org.eclipse.cdt.core.testplugin.FileManager; - import org.eclipse.cdt.internal.core.parser.Parser; import org.eclipse.cdt.internal.core.parser.ParserException; import org.eclipse.cdt.internal.core.search.indexing.IndexManager; @@ -86,11 +79,7 @@ import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.core.runtime.Path; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.dialogs.SaveAsDialog; /** * @author dsteffle diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2KnRTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2KnRTests.java index 0d9dce42896..f500e6c584e 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2KnRTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2KnRTests.java @@ -10,8 +10,6 @@ ***********************************************************************/ package org.eclipse.cdt.core.parser.tests.ast2; -import java.util.List; - import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator; import org.eclipse.cdt.core.dom.ast.IASTArraySubscriptExpression; import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression; @@ -457,9 +455,9 @@ public class AST2KnRTests extends AST2BaseTest { assertEquals( A_struct_name1.toString(), "A_struct" ); //$NON-NLS-1$ ICompositeType A_struct_type1 = (ICompositeType)A_struct_name1.resolveBinding(); assertEquals( ((ICBinding)A_struct_type1).getPhysicalNode(), A_struct.getDeclSpecifier() ); - List fields = A_struct_type1.getFields(); - IField a1 = (IField)fields.get(0); - IField c1 = (IField)fields.get(1); + IField[] fields = A_struct_type1.getFields(); + IField a1 = fields[0]; + IField c1 = fields[1]; assertEquals( a1.getName().toString(), "a" ); //$NON-NLS-1$ assertEquals( c1.getName().toString(), "c" ); //$NON-NLS-1$ IBasicType a1_t = (IBasicType)a1.getType(); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java index 77a3b53a00b..c09b509a643 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java @@ -83,7 +83,7 @@ import org.eclipse.cdt.internal.core.parser.ParserException; */ public class AST2Tests extends AST2BaseTest { - public void testBasicFunction() throws ParserException { + public void testBasicFunction() throws Exception { StringBuffer buff = new StringBuffer(); buff.append("int x;\n"); //$NON-NLS-1$ buff.append("void f(int y) {\n"); //$NON-NLS-1$ @@ -216,7 +216,7 @@ public class AST2Tests extends AST2BaseTest { ICScope.NAMESPACE_TYPE_OTHER, new String("y").toCharArray())); //$NON-NLS-1$ } - public void testSimpleStruct() throws ParserException { + public void testSimpleStruct() throws Exception { StringBuffer buff = new StringBuffer(); buff.append("typedef struct {\n"); //$NON-NLS-1$ buff.append(" int x;\n"); //$NON-NLS-1$ diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CompleteParser2Tests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CompleteParser2Tests.java index 3856ad1477f..68c51b63b67 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CompleteParser2Tests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CompleteParser2Tests.java @@ -35,6 +35,7 @@ import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.ICompositeType; import org.eclipse.cdt.core.dom.ast.IEnumeration; import org.eclipse.cdt.core.dom.ast.IEnumerator; +import org.eclipse.cdt.core.dom.ast.IField; import org.eclipse.cdt.core.dom.ast.IFunction; import org.eclipse.cdt.core.dom.ast.IFunctionType; import org.eclipse.cdt.core.dom.ast.ILabel; @@ -370,9 +371,9 @@ public class CompleteParser2Tests extends TestCase { ICPPField x = (ICPPField) col.getName(1).resolveBinding(); assertSame( x.getScope(), A.getCompositeScope() ); - List fields = A.getFields(); - assertEquals( fields.size(), 1 ); - assertSame( fields.get(0), x ); + IField [] fields = A.getFields(); + assertEquals( fields.length, 1 ); + assertSame( fields[0], x ); } public void testUsingClauses() throws Exception diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/DOMException.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/DOMException.java new file mode 100644 index 00000000000..1d7edf8437d --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/DOMException.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ + +/* + * Created on Jan 31, 2005 + */ +package org.eclipse.cdt.core.dom.ast; + +import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPSemantics; + +/** + * @author aniefer + */ +public class DOMException extends Exception { + IProblemBinding problemBinding; + /** + * + */ + public DOMException( IProblemBinding problem ) { + super( problem != null ? problem.getMessage() : CPPSemantics.EMPTY_NAME ); + problemBinding = problem; + } + + public IProblemBinding getProblem(){ + return problemBinding; + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IArrayType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IArrayType.java index 4d23480c99a..0b92721100b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IArrayType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IArrayType.java @@ -19,5 +19,5 @@ package org.eclipse.cdt.core.dom.ast; */ public interface IArrayType extends IType { - IType getType(); + IType getType() throws DOMException; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IBasicType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IBasicType.java index 0ba852151ee..85c0d8248d1 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IBasicType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IBasicType.java @@ -26,7 +26,7 @@ public interface IBasicType extends IType { * * @return */ - public int getType(); + public int getType() throws DOMException; public static final int t_unspecified = IASTSimpleDeclSpecifier.t_unspecified; public static final int t_void = IASTSimpleDeclSpecifier.t_void; @@ -35,8 +35,8 @@ public interface IBasicType extends IType { public static final int t_float = IASTSimpleDeclSpecifier.t_float; public static final int t_double = IASTSimpleDeclSpecifier.t_double; - public boolean isSigned(); - public boolean isUnsigned(); - public boolean isShort(); - public boolean isLong(); + public boolean isSigned() throws DOMException; + public boolean isUnsigned() throws DOMException; + public boolean isShort() throws DOMException; + public boolean isLong() throws DOMException; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IBinding.java index 8a429e79555..2bace021525 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IBinding.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IBinding.java @@ -28,6 +28,6 @@ public interface IBinding { * * @return the scope of this name */ - public IScope getScope(); + public IScope getScope() throws DOMException; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ICompositeType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ICompositeType.java index 0483f9ba44b..da95a604d44 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ICompositeType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ICompositeType.java @@ -10,7 +10,6 @@ **********************************************************************/ package org.eclipse.cdt.core.dom.ast; -import java.util.List; /** * @author Doug Schaefer @@ -23,14 +22,14 @@ public interface ICompositeType extends IBinding, IType { * what kind of composite type is this? * @return */ - public int getKey(); + public int getKey() throws DOMException; /** * Returns the fields for this type. * * @return List of IField */ - public List getFields(); + public IField[] getFields() throws DOMException; /** * returns the field that matches name, @@ -39,7 +38,7 @@ public interface ICompositeType extends IBinding, IType { * @param name * @return */ - public IField findField( String name ); + public IField findField( String name ) throws DOMException; - public IScope getCompositeScope(); + public IScope getCompositeScope() throws DOMException; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IEnumeration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IEnumeration.java index cfcc158ee23..d609d2ec637 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IEnumeration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IEnumeration.java @@ -18,5 +18,5 @@ package org.eclipse.cdt.core.dom.ast; * @author aniefer */ public interface IEnumeration extends IBinding, IType { - + IEnumerator [] getEnumerators() throws DOMException; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IEnumerator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IEnumerator.java index ae008aafa10..b32a38e99dd 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IEnumerator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IEnumerator.java @@ -21,5 +21,5 @@ public interface IEnumerator extends IBinding { /** * @return the type of the variable */ - public IType getType(); + public IType getType() throws DOMException; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IFunction.java index 718228e999c..e1ec10681f9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IFunction.java @@ -23,16 +23,23 @@ public interface IFunction extends IBinding { * This gets the parameters to the function which are IVariables. * * @return List of IParameter + * @throws DOMException if this is a problem binding */ - public IParameter [] getParameters(); + public IParameter [] getParameters() throws DOMException; /** * Get the function scope * * @return + * @throws DOMException if this is a problem binding */ - public IScope getFunctionScope(); + public IScope getFunctionScope() throws DOMException; - public IFunctionType getType(); + /** + * + * @return + * @throws DOMException if this is a problem binding + */ + public IFunctionType getType() throws DOMException; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IFunctionType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IFunctionType.java index 5ba0fddf995..f431bd5be1d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IFunctionType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IFunctionType.java @@ -18,7 +18,7 @@ package org.eclipse.cdt.core.dom.ast; * @author aniefer */ public interface IFunctionType extends IType { - public IType getReturnType(); + public IType getReturnType() throws DOMException; - public IType [] getParameterTypes(); + public IType [] getParameterTypes() throws DOMException; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ILabel.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ILabel.java index 592945e443d..8a94120f931 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ILabel.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ILabel.java @@ -23,6 +23,6 @@ public interface ILabel extends IBinding { * * @return */ - public IASTLabelStatement getLabelStatement(); + public IASTLabelStatement getLabelStatement() throws DOMException; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IPointerType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IPointerType.java index f6c628937d4..3ab227dc05f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IPointerType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IPointerType.java @@ -18,7 +18,7 @@ package org.eclipse.cdt.core.dom.ast; * @author aniefer */ public interface IPointerType extends IType { - public IType getType(); - public boolean isConst(); - public boolean isVolatile(); + public IType getType() throws DOMException; + public boolean isConst() throws DOMException; + public boolean isVolatile() throws DOMException; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IProblemBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IProblemBinding.java index 0db92444156..7a3a286e037 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IProblemBinding.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IProblemBinding.java @@ -17,7 +17,7 @@ package org.eclipse.cdt.core.dom.ast; /** * @author aniefer */ -public interface IProblemBinding extends IBinding { +public interface IProblemBinding extends IBinding, IScope, IType { /** * Returns the problem id @@ -106,5 +106,9 @@ public interface IProblemBinding extends IBinding { public static final int SEMANTIC_ILLFORMED_FRIEND = 0x011; public static final int SEMANTIC_RECURSIVE_TEMPLATE_INSTANTIATION = 0x012; - public static final int LAST_PROBLEM = SEMANTIC_RECURSIVE_TEMPLATE_INSTANTIATION; + + public static final int SEMANTIC_DEFINITION_NOT_FOUND = 0x013; + public static final int SEMANTIC_KNR_PARAMETER_DECLARATION_NOT_FOUND = 0x014; + public static final int SEMANTIC_LABEL_STATEMENT_NOT_FOUND = 0x015; + public static final int LAST_PROBLEM = SEMANTIC_LABEL_STATEMENT_NOT_FOUND; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IQualifierType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IQualifierType.java index cad1389dea6..221cca9dbc2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IQualifierType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IQualifierType.java @@ -18,8 +18,8 @@ package org.eclipse.cdt.core.dom.ast; * @author aniefer */ public interface IQualifierType extends IType { - public boolean isConst(); - public boolean isVolatile(); + public boolean isConst() throws DOMException; + public boolean isVolatile() throws DOMException; - public IType getType(); + public IType getType() throws DOMException; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IScope.java index 06127b8ec86..d491741943b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IScope.java @@ -24,7 +24,7 @@ public interface IScope { * * @return */ - public IScope getParent(); + public IScope getParent() throws DOMException; /** * This is the general lookup entry point. It returns the list of @@ -33,5 +33,5 @@ public interface IScope { * @param searchString * @return List of IBinding */ - public List find(String name); + public List find(String name) throws DOMException; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ITypedef.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ITypedef.java index c3d2272dc0d..26c73162994 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ITypedef.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ITypedef.java @@ -20,6 +20,6 @@ public interface ITypedef extends IBinding, IType { * * @return */ - public IType getType(); + public IType getType() throws DOMException; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IVariable.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IVariable.java index 3e75216a8f5..7cf7da33640 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IVariable.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IVariable.java @@ -18,5 +18,5 @@ public interface IVariable extends IBinding { /** * @return the type of the variable */ - public IType getType(); + public IType getType() throws DOMException; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICArrayType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICArrayType.java index 00be8dae734..34930da3020 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICArrayType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICArrayType.java @@ -10,15 +10,16 @@ *******************************************************************************/ package org.eclipse.cdt.core.dom.ast.c; +import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IArrayType; /** * @author dsteffle */ public interface ICArrayType extends IArrayType { - public boolean isConst(); - public boolean isRestrict(); - public boolean isVolatile(); - public boolean isStatic(); - public boolean isVariableLength(); + public boolean isConst() throws DOMException; + public boolean isRestrict() throws DOMException; + public boolean isVolatile() throws DOMException; + public boolean isStatic() throws DOMException; + public boolean isVariableLength() throws DOMException; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICBasicType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICBasicType.java index db20679da7b..a2c361674f2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICBasicType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICBasicType.java @@ -13,6 +13,7 @@ */ package org.eclipse.cdt.core.dom.ast.c; +import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IBasicType; /** @@ -24,5 +25,5 @@ public interface ICBasicType extends IBasicType { public static final int t_Complex = ICASTSimpleDeclSpecifier.t_Complex; public static final int t_Imaginary = ICASTSimpleDeclSpecifier.t_Imaginary; - public boolean isLongLong(); + public boolean isLongLong() throws DOMException; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICCompositeTypeScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICCompositeTypeScope.java index 4c1dc270ae5..9c5dcbd1cd5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICCompositeTypeScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICCompositeTypeScope.java @@ -14,11 +14,12 @@ */ package org.eclipse.cdt.core.dom.ast.c; +import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IBinding; /** * @author aniefer */ public interface ICCompositeTypeScope extends ICScope { - public IBinding getBinding( char[] name ); + public IBinding getBinding( char[] name ) throws DOMException; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICFunctionScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICFunctionScope.java index f3128635cf3..736a6d0c60d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICFunctionScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICFunctionScope.java @@ -14,6 +14,7 @@ */ package org.eclipse.cdt.core.dom.ast.c; +import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IScope; @@ -21,7 +22,7 @@ import org.eclipse.cdt.core.dom.ast.IScope; * @author aniefer */ public interface ICFunctionScope extends ICScope { - public IScope getBodyScope(); - public IBinding getBinding( char[] name ); + public IScope getBodyScope() throws DOMException; + public IBinding getBinding( char[] name ) throws DOMException; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICScope.java index 05db6d79f4c..aa96ea11b0d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICScope.java @@ -14,6 +14,7 @@ */ package org.eclipse.cdt.core.dom.ast.c; +import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IScope; @@ -24,7 +25,7 @@ public interface ICScope extends IScope { public static final int NAMESPACE_TYPE_TAG = 0; public static final int NAMESPACE_TYPE_OTHER = 1; - void addBinding( IBinding binding ); - void removeBinding( IBinding binding ); - public IBinding getBinding( int namespaceType, char [] name ); + void addBinding( IBinding binding ) throws DOMException; + void removeBinding( IBinding binding ) throws DOMException; + public IBinding getBinding( int namespaceType, char [] name ) throws DOMException; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassType.java index f90500f4822..9a5af7fba04 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassType.java @@ -12,7 +12,9 @@ package org.eclipse.cdt.core.dom.ast.cpp; import java.util.List; +import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.ICompositeType; +import org.eclipse.cdt.core.dom.ast.IField; /** * Represents a C++ class. @@ -28,13 +30,13 @@ public interface ICPPClassType extends ICompositeType { * * @return List of ICPPBase */ - public ICPPBase [] getBases(); + public ICPPBase [] getBases() throws DOMException; /** * Get fields is restated here just to point out that this method returns * a list of ICPPField objects representing all fields, declared or inherited. */ - public List getFields(); + public IField[] getFields() throws DOMException; /** * Returns a list of ICPPField objects representing fields declared in this @@ -42,7 +44,7 @@ public interface ICPPClassType extends ICompositeType { * * @return List of ICPPField */ - public List getDeclaredFields(); + public List getDeclaredFields() throws DOMException; /** * Returns a list of ICPPMethod objects representing all methods defined for @@ -51,7 +53,7 @@ public interface ICPPClassType extends ICompositeType { * * @return List of ICPPMethod */ - public List getMethods(); + public List getMethods() throws DOMException; /** * Returns a list of ICPPMethod objects representing all method explicitly @@ -60,7 +62,7 @@ public interface ICPPClassType extends ICompositeType { * * @return List of ICPPMethod */ - public List getAllDeclaredMethods(); + public List getAllDeclaredMethods() throws DOMException; /** * Returns a list of ICPPMethod objects representing all methods explicitly @@ -69,11 +71,11 @@ public interface ICPPClassType extends ICompositeType { * * @return List of ICPPMethod */ - public List getDeclaredMethods(); + public List getDeclaredMethods() throws DOMException; /** * @return */ - public ICPPConstructor[] getConstructors(); + public ICPPConstructor[] getConstructors() throws DOMException; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPCompositeBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPCompositeBinding.java index f7d352b79c9..11772c54fab 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPCompositeBinding.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPCompositeBinding.java @@ -13,11 +13,12 @@ */ package org.eclipse.cdt.core.dom.ast.cpp; +import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IBinding; /** * @author aniefer */ public interface ICPPCompositeBinding extends IBinding { - IBinding [] getBindings(); + IBinding [] getBindings() throws DOMException; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPConstructor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPConstructor.java index de6634f3b1e..ec7c962e5df 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPConstructor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPConstructor.java @@ -13,14 +13,18 @@ */ package org.eclipse.cdt.core.dom.ast.cpp; +import org.eclipse.cdt.core.dom.ast.DOMException; + /** * @author aniefer */ public interface ICPPConstructor extends ICPPMethod { /** + * * @return + * @throws DOMException */ - boolean isExplicit(); + boolean isExplicit() throws DOMException; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPMember.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPMember.java index 0f49f75d75d..ba40e96a4f2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPMember.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPMember.java @@ -10,6 +10,8 @@ **********************************************************************/ package org.eclipse.cdt.core.dom.ast.cpp; +import org.eclipse.cdt.core.dom.ast.DOMException; + /** * Represents a member of a class. Adds in the visibility attribute. * @@ -22,7 +24,7 @@ public interface ICPPMember { * * @return */ - public int getVisibility(); + public int getVisibility() throws DOMException; public static final int v_private = ICPPASTVisiblityLabel.v_private; public static final int v_protected = ICPPASTVisiblityLabel.v_protected; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPNamespace.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPNamespace.java index 989123af6dd..0a9a6f12d6d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPNamespace.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPNamespace.java @@ -13,11 +13,12 @@ */ package org.eclipse.cdt.core.dom.ast.cpp; +import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IBinding; /** * @author aniefer */ public interface ICPPNamespace extends IBinding { - public ICPPNamespaceScope getNamespaceScope(); + public ICPPNamespaceScope getNamespaceScope() throws DOMException; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPReferenceType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPReferenceType.java index 727e33090a0..62ebe1f38b2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPReferenceType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPReferenceType.java @@ -14,11 +14,12 @@ */ package org.eclipse.cdt.core.dom.ast.cpp; +import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IType; /** * @author aniefer */ public interface ICPPReferenceType extends IType { - public IType getType(); + public IType getType() throws DOMException; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPScope.java index 214f273fb5d..8b756d2a873 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPScope.java @@ -13,6 +13,7 @@ */ package org.eclipse.cdt.core.dom.ast.cpp; +import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IBinding; @@ -22,7 +23,7 @@ import org.eclipse.cdt.core.dom.ast.IScope; * @author aniefer */ public interface ICPPScope extends IScope { - public IASTNode getPhysicalNode(); - public void addBinding( IBinding binding ); - public IBinding getBinding( IASTName name ); + public IASTNode getPhysicalNode() throws DOMException; + public void addBinding( IBinding binding ) throws DOMException; + public IBinding getBinding( IASTName name ) throws DOMException; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPTemplateTypeParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPTemplateTypeParameter.java index 3e5dcd9ee51..e7c2f2a9f05 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPTemplateTypeParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPTemplateTypeParameter.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.core.dom.ast.cpp; +import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IType; /** @@ -22,6 +23,6 @@ public interface ICPPTemplateTypeParameter extends ICPPTemplateParameter, IType * * @return */ - public IType getDefault(); + public IType getDefault() throws DOMException; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/cpp/IGPPBasicType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/cpp/IGPPBasicType.java index d615f88c838..ef2ff24476d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/cpp/IGPPBasicType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/cpp/IGPPBasicType.java @@ -13,6 +13,7 @@ */ package org.eclipse.cdt.core.dom.ast.gnu.cpp; +import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType; @@ -25,7 +26,7 @@ public interface IGPPBasicType extends ICPPBasicType { public static final int t_Imaginary = IGPPASTSimpleDeclSpecifier.t_Imaginary; public static final int t_typeof = IGPPASTSimpleDeclSpecifier.t_typeof; - public boolean isLongLong(); + public boolean isLongLong() throws DOMException; - public IType getTypeofType(); + public IType getTypeofType() throws DOMException; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ITypeContainer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ITypeContainer.java index 10abf451c18..c4cadb44185 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ITypeContainer.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ITypeContainer.java @@ -14,12 +14,13 @@ */ package org.eclipse.cdt.internal.core.dom.parser; +import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IType; /** * @author aniefer */ public interface ITypeContainer extends IType{ - IType getType(); + IType getType() throws DOMException; void setType( IType type ); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ProblemBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ProblemBinding.java index b8f203dbb90..9c1d16c600e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ProblemBinding.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ProblemBinding.java @@ -15,7 +15,9 @@ package org.eclipse.cdt.internal.core.dom.parser; import java.text.MessageFormat; +import java.util.List; +import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IProblemBinding; import org.eclipse.cdt.core.dom.ast.IScope; @@ -26,7 +28,7 @@ import org.eclipse.cdt.internal.core.parser.ParserMessages; /** * @author aniefer */ -public class ProblemBinding implements IProblemBinding, IType { +public class ProblemBinding implements IProblemBinding, IType, IScope { private final int id; private final char [] arg; @@ -101,19 +103,35 @@ public class ProblemBinding implements IProblemBinding, IType { /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.IBinding#getScope() */ - public IScope getScope() { - return null; + public IScope getScope() throws DOMException { + throw new DOMException( this ); } /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.IBinding#getPhysicalNode() */ - public IASTNode getPhysicalNode() { - return null; + public IASTNode getPhysicalNode() throws DOMException { + throw new DOMException( this ); } public Object clone(){ //don't clone problems return this; } + + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IScope#getParent() + */ + public IScope getParent() throws DOMException { + throw new DOMException( this ); + } + + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IScope#find(java.lang.String) + */ + public List find( String name ) throws DOMException { + throw new DOMException( this ); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CEnumeration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CEnumeration.java index 36d032611a8..10e40b2c122 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CEnumeration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CEnumeration.java @@ -14,8 +14,10 @@ */ package org.eclipse.cdt.internal.core.dom.parser.c; +import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IEnumeration; +import org.eclipse.cdt.core.dom.ast.IEnumerator; import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.c.ICASTEnumerationSpecifier; @@ -64,4 +66,17 @@ public class CEnumeration implements IEnumeration { } return t; } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IEnumeration#getEnumerators() + */ + public IEnumerator[] getEnumerators() { + IASTEnumerationSpecifier.IASTEnumerator[] enums = enumSpec.getEnumerators(); + IEnumerator [] bindings = new IEnumerator [ enums.length ]; + + for( int i = 0; i < enums.length; i++ ){ + bindings[i] = (IEnumerator) enums[i].getName().resolveBinding(); + } + return bindings; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CField.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CField.java index bd113fb9653..019fbdb294b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CField.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CField.java @@ -19,7 +19,11 @@ import org.eclipse.cdt.core.dom.ast.IField; * @author aniefer */ public class CField extends CVariable implements IField { - + public static class CFieldProblem extends CVariable.CVariableProblem implements IField { + public CFieldProblem( int id, char[] arg ) { + super( id, arg ); + } + } /** * @param name */ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunction.java index 037db7b410d..fc334465733 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunction.java @@ -23,6 +23,7 @@ import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IFunction; import org.eclipse.cdt.core.dom.ast.IFunctionType; import org.eclipse.cdt.core.dom.ast.IParameter; +import org.eclipse.cdt.core.dom.ast.IProblemBinding; import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator; @@ -88,21 +89,17 @@ public class CFunction implements IFunction, ICBinding { } } } else if (dtor instanceof ICASTKnRFunctionDeclarator) { - IASTDeclaration[] params = ((ICASTKnRFunctionDeclarator)dtor).getParameterDeclarations(); IASTName[] names = ((ICASTKnRFunctionDeclarator)dtor).getParameterNames(); result = new IParameter[ names.length ]; if( names.length > 0 ){ // ensures that the List of parameters is created in the same order as the K&R C parameter names for( int i=0; i 0 ){ for( int i = 0; i < size; i++ ){ @@ -107,7 +104,7 @@ public class CStructure implements ICompositeType, ICBinding { IASTDeclarator declarator = declarators[j]; IBinding binding = declarator.getName().resolveBinding(); if( binding != null ) - fields.add( binding ); + fields[i] = (IField) binding; } } } @@ -123,7 +120,7 @@ public class CStructure implements ICompositeType, ICBinding { if( definition == null ){ ICASTCompositeTypeSpecifier temp = checkForDefinition( declarations[0] ); if( temp == null ) - return null; + return new CField.CFieldProblem( IProblemBinding.SEMANTIC_DEFINITION_NOT_FOUND, getNameCharArray() ); definition = temp; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVariable.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVariable.java index 68b1208f1ed..5f9d03d7cf8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVariable.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVariable.java @@ -11,6 +11,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.c; +import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTName; @@ -18,42 +19,33 @@ import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IVariable; +import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; /** * Created on Nov 5, 2004 * @author aniefer */ public class CVariable implements IVariable, ICBinding { + public static class CVariableProblem extends ProblemBinding implements IVariable { + public CVariableProblem( int id, char[] arg ) { + super( id, arg ); + } + + public IType getType() throws DOMException { + throw new DOMException( this ); + } + + } final IASTName name; private IType type = null; public CVariable( IASTName name ){ -// name = checkForDefinition( name ); this.name = name; } public IASTNode getPhysicalNode(){ return name; } -// private IASTName checkForDefinition( IASTName nm ){ -// IASTDeclarator dtor = (IASTDeclarator) nm.getParent(); -// IASTSimpleDeclaration dcl = (IASTSimpleDeclaration) dtor.getParent(); -// IASTDeclSpecifier declSpec = dcl.getDeclSpecifier(); -// if( declSpec.getStorageClass() == IASTDeclSpecifier.sc_extern ){ -// IASTDeclarator prev = dtor, tmp = CVisitor.findDefinition( dtor, CVisitor.AT_BEGINNING ); -// while( tmp != null && tmp != prev ){ -// CASTName n = (CASTName) tmp.getName(); -// IASTDeclSpecifier spec = ((IASTSimpleDeclaration)tmp.getParent()).getDeclSpecifier(); -// if( spec.getStorageClass() != IASTDeclSpecifier.sc_extern ){ -// nm = n; -// } -// n.setBinding( this ); -// prev = tmp; -// tmp = CVisitor.findDefinition( tmp, CVisitor.AT_NEXT ); -// } -// } -// -// return nm; -// } + /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.IVariable#getType() */ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java index 75c5b166774..2c4c644e607 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java @@ -14,6 +14,7 @@ package org.eclipse.cdt.internal.core.dom.parser.c; import java.util.List; import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; +import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator; import org.eclipse.cdt.core.dom.ast.IASTArrayModifier; import org.eclipse.cdt.core.dom.ast.IASTArraySubscriptExpression; @@ -71,6 +72,7 @@ import org.eclipse.cdt.core.dom.ast.IFunction; import org.eclipse.cdt.core.dom.ast.IFunctionType; import org.eclipse.cdt.core.dom.ast.ILabel; import org.eclipse.cdt.core.dom.ast.IParameter; +import org.eclipse.cdt.core.dom.ast.IProblemBinding; import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.ITypedef; @@ -142,9 +144,13 @@ public class CVisitor { } public int processName(IASTName name) { if ( ((CASTName)name).hasBinding() ) { - ICScope scope = (ICScope)name.resolveBinding().getScope(); - if ( scope != null ) - scope.removeBinding(name.resolveBinding()); + ICScope scope; + try { + scope = (ICScope)name.resolveBinding().getScope(); + if ( scope != null ) + scope.removeBinding(name.resolveBinding()); + } catch ( DOMException e ) { + } ((CASTName) name ).setBinding( null ); } @@ -490,30 +496,42 @@ public class CVisitor { private static IBinding createBinding( ICASTEnumerationSpecifier enumeration ){ IEnumeration binding = new CEnumeration( enumeration ); - ((ICScope)binding.getScope()).addBinding( binding ); - return binding; + try { + ((ICScope)binding.getScope()).addBinding( binding ); + } catch ( DOMException e ) { + } + return binding; } private static IBinding createBinding( IASTEnumerator enumerator ){ IEnumerator binding = new CEnumerator( enumerator ); - ((ICScope)binding.getScope()).addBinding( binding ); + try { + ((ICScope)binding.getScope()).addBinding( binding ); + } catch ( DOMException e ) { + } return binding; } private static IBinding createBinding( IASTStatement statement ){ if( statement instanceof IASTGotoStatement ){ + char [] gotoName = ((IASTGotoStatement)statement).getName().toCharArray(); IScope scope = getContainingScope( statement ); if( scope != null && scope instanceof ICFunctionScope ){ CFunctionScope functionScope = (CFunctionScope) scope; List labels = functionScope.getLabels(); for( int i = 0; i < labels.size(); i++ ){ ILabel label = (ILabel) labels.get(i); - if( label.getName().equals( ((IASTGotoStatement)statement).getName().toString() ) ){ + if( CharArrayUtils.equals( label.getNameCharArray(), gotoName) ){ return label; } } + //label not found + return new CLabel.CLabelProblem( IProblemBinding.SEMANTIC_LABEL_STATEMENT_NOT_FOUND, gotoName ); } } else if( statement instanceof IASTLabelStatement ){ IBinding binding = new CLabel( (IASTLabelStatement) statement ); - ((ICFunctionScope) binding.getScope()).addBinding( binding ); + try { + ((ICFunctionScope) binding.getScope()).addBinding( binding ); + } catch ( DOMException e ) { + } return binding; } return null; @@ -527,7 +545,10 @@ public class CVisitor { IBinding binding = resolveBinding( elabTypeSpec, CURRENT_SCOPE | TAGS ); if( binding == null ){ binding = new CStructure( elabTypeSpec ); - ((ICScope) binding.getScope()).addBinding( binding ); + try { + ((ICScope) binding.getScope()).addBinding( binding ); + } catch ( DOMException e ) { + } } return binding; } @@ -547,38 +568,50 @@ public class CVisitor { type = getExpressionType( fieldOwner ); } while( type != null && type instanceof ITypeContainer) { - type = ((ITypeContainer)type).getType(); + try { + type = ((ITypeContainer)type).getType(); + } catch ( DOMException e ) { + return e.getProblem(); + } } if( type != null && type instanceof ICompositeType ){ - return ((ICompositeType) type).findField( fieldReference.getFieldName().toString() ); + try { + return ((ICompositeType) type).findField( fieldReference.getFieldName().toString() ); + } catch ( DOMException e ) { + return e.getProblem(); + } } return null; } private static IType getExpressionType( IASTExpression expression ) { - if( expression instanceof IASTIdExpression ){ - IBinding binding = resolveBinding( expression ); - if( binding instanceof IVariable ){ - return ((IVariable)binding).getType(); - } - } else if( expression instanceof IASTCastExpression ){ - IASTTypeId id = ((IASTCastExpression)expression).getTypeId(); - IBinding binding = resolveBinding( id ); - if( binding != null && binding instanceof IType ){ - return (IType) binding; - } - } else if( expression instanceof IASTFieldReference ){ - IBinding binding = ((IASTFieldReference)expression).getFieldName().resolveBinding(); - - if( binding instanceof IVariable ){ - return ((IVariable)binding).getType(); - } - } - else if( expression instanceof IASTUnaryExpression ) - { - if( ((IASTUnaryExpression)expression).getOperator() == IASTUnaryExpression.op_bracketedPrimary ) - return getExpressionType(((IASTUnaryExpression)expression).getOperand() ); + try{ + if( expression instanceof IASTIdExpression ){ + IBinding binding = resolveBinding( expression ); + if( binding instanceof IVariable ){ + return ((IVariable)binding).getType(); + } + } else if( expression instanceof IASTCastExpression ){ + IASTTypeId id = ((IASTCastExpression)expression).getTypeId(); + IBinding binding = resolveBinding( id ); + if( binding != null && binding instanceof IType ){ + return (IType) binding; + } + } else if( expression instanceof IASTFieldReference ){ + IBinding binding = ((IASTFieldReference)expression).getFieldName().resolveBinding(); + + if( binding instanceof IVariable ){ + return ((IVariable)binding).getType(); + } + } + else if( expression instanceof IASTUnaryExpression ) + { + if( ((IASTUnaryExpression)expression).getOperator() == IASTUnaryExpression.op_bracketedPrimary ) + return getExpressionType(((IASTUnaryExpression)expression).getOperand() ); + } + } catch( DOMException e ){ + return e.getProblem(); } return null; } @@ -613,7 +646,10 @@ public class CVisitor { if ( declarator.getParent() instanceof IASTFunctionDefinition ) { ICScope scope = (ICScope) ((IASTCompoundStatement)((IASTFunctionDefinition)declarator.getParent()).getBody()).getScope(); if ( scope != null && binding != null ) - scope.addBinding(binding); + try { + scope.addBinding(binding); + } catch ( DOMException e ) { + } } } } else if( parent instanceof IASTSimpleDeclaration ){ @@ -628,7 +664,10 @@ public class CVisitor { if( parent instanceof IASTFunctionDefinition ){ ICScope scope = (ICScope) ((IASTCompoundStatement)((IASTFunctionDefinition)parent).getBody()).getScope(); if ( scope != null && binding != null ) - scope.addBinding(binding); + try { + scope.addBinding(binding); + } catch ( DOMException e ) { + } } } } else if ( parent instanceof IASTFunctionDeclarator ) { @@ -650,18 +689,25 @@ public class CVisitor { ICScope scope = (ICScope) getContainingScope( parent ); IBinding binding = null; - binding = ( scope != null ) ? scope.getBinding( ICScope.NAMESPACE_TYPE_OTHER, declarator.getName().toCharArray() ) : null; + try { + binding = ( scope != null ) ? scope.getBinding( ICScope.NAMESPACE_TYPE_OTHER, declarator.getName().toCharArray() ) : null; + } catch ( DOMException e1 ) { + binding = null; + } if( declarator instanceof IASTFunctionDeclarator ){ if( binding != null && binding instanceof IFunction ){ - IFunction function = (IFunction) binding; - IFunctionType ftype = function.getType(); - IType type = createType( declarator.getName() ); - if( ftype.equals( type ) ){ - if( parent instanceof IASTSimpleDeclaration ) - ((CFunction)function).addDeclarator( (IASTFunctionDeclarator) declarator ); - - return function; + try{ + IFunction function = (IFunction) binding; + IFunctionType ftype = function.getType(); + IType type = createType( declarator.getName() ); + if( ftype.equals( type ) ){ + if( parent instanceof IASTSimpleDeclaration ) + ((CFunction)function).addDeclarator( (IASTFunctionDeclarator) declarator ); + + return function; + } + } catch( DOMException e ){ } } @@ -681,15 +727,23 @@ public class CVisitor { } if( scope != null && binding != null ) - scope.addBinding( binding ); + try { + scope.addBinding( binding ); + } catch ( DOMException e ) { + } return binding; } private static IBinding createBinding( ICASTCompositeTypeSpecifier compositeTypeSpec ){ ICompositeType binding = new CStructure( compositeTypeSpec ); - ICScope scope = (ICScope) binding.getScope(); - scope.addBinding( binding ); + ICScope scope; + try { + scope = (ICScope) binding.getScope(); + scope.addBinding( binding ); + } catch ( DOMException e ) { + } + return binding; } @@ -702,10 +756,16 @@ public class CVisitor { IBinding binding = null; if( simpleDeclaration.getDeclSpecifier().getStorageClass() == IASTDeclSpecifier.sc_typedef ){ binding = new CTypeDef( name ); - ((ICScope) binding.getScope()).addBinding( binding ); + try { + ((ICScope) binding.getScope()).addBinding( binding ); + } catch ( DOMException e ) { + } } else if( simpleDeclaration.getParent() instanceof ICASTCompositeTypeSpecifier ){ binding = new CField( name ); - ((ICScope) binding.getScope()).addBinding( binding ); + try { + ((ICScope) binding.getScope()).addBinding( binding ); + } catch ( DOMException e ) { + } } else { CScope scope = (CScope) CVisitor.getContainingScope( simpleDeclaration ); binding = scope.getBinding( ICScope.NAMESPACE_TYPE_OTHER, name.toCharArray() ); @@ -787,10 +847,16 @@ public class CVisitor { if ( struct instanceof CStructure ) { return ((CStructure)struct).findField(((ICASTFieldDesignator)node).getName().toString()); } else if ( struct instanceof ITypeContainer ) { - IType type = ((ITypeContainer)struct).getType(); - while ( type instanceof ITypeContainer && !(type instanceof CStructure) ) { - type = ((ITypeContainer)type).getType(); - } + IType type; + try { + type = ((ITypeContainer)struct).getType(); + while ( type instanceof ITypeContainer && !(type instanceof CStructure) ) { + type = ((ITypeContainer)type).getType(); + } + } catch ( DOMException e ) { + return e.getProblem(); + } + if ( type instanceof CStructure ) return ((CStructure)type).findField(((ICASTFieldDesignator)node).getName().toString()); @@ -855,13 +921,21 @@ public class CVisitor { } else if( parent instanceof IASTFunctionDefinition ){ IASTFunctionDeclarator fnDeclarator = ((IASTFunctionDefinition) parent ).getDeclarator(); IFunction function = (IFunction) fnDeclarator.getName().resolveBinding(); - scope = function.getFunctionScope(); + try { + scope = function.getFunctionScope(); + } catch ( DOMException e ) { + return e.getProblem(); + } } if( statement instanceof IASTGotoStatement || statement instanceof IASTLabelStatement ){ //labels have function scope while( scope != null && !(scope instanceof ICFunctionScope) ){ - scope = scope.getParent(); + try { + scope = scope.getParent(); + } catch ( DOMException e ) { + scope = e.getProblem(); + } } } @@ -928,7 +1002,11 @@ public class CVisitor { if( scope != null ){ int namespaceType = (bits & TAGS) != 0 ? ICScope.NAMESPACE_TYPE_TAG : ICScope.NAMESPACE_TYPE_OTHER; - binding = scope.getBinding( namespaceType, name.toCharArray() ); + try { + binding = scope.getBinding( namespaceType, name.toCharArray() ); + } catch ( DOMException e ) { + binding = null; + } if( binding != null ) return binding; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNamespaceDefinition.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNamespaceDefinition.java index ea69fd9c948..ec2b6dd145c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNamespaceDefinition.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNamespaceDefinition.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IScope; @@ -88,7 +89,11 @@ public class CPPASTNamespaceDefinition extends CPPASTNode implements * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition#getScope() */ public IScope getScope() { - return ((ICPPNamespace) name.resolveBinding()).getNamespaceScope(); + try { + return ((ICPPNamespace) name.resolveBinding()).getNamespaceScope(); + } catch ( DOMException e ) { + return e.getProblem(); + } } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPArrayType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPArrayType.java index 99b1ef5dd53..5decad53230 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPArrayType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPArrayType.java @@ -14,6 +14,7 @@ */ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IArrayType; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; @@ -38,7 +39,11 @@ public class CPPArrayType implements IArrayType, ITypeContainer { public boolean equals(Object obj) { if( obj instanceof IArrayType ){ - return ((IArrayType) obj).getType().equals( type ); + try { + return ((IArrayType) obj).getType().equals( type ); + } catch ( DOMException e ) { + return false; + } } return false; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassScope.java index 79f3ee923f8..04e30ddff27 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassScope.java @@ -17,6 +17,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNode; @@ -53,9 +54,14 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope { private void createImplicitMembers(){ //create bindings for the implicit members, if the user declared them then those declarations //will resolve to these bindings. - ICPPASTCompositeTypeSpecifier compTypeSpec = (ICPPASTCompositeTypeSpecifier) getPhysicalNode(); - - //default constructor: A() + ICPPASTCompositeTypeSpecifier compTypeSpec; + try { + compTypeSpec = (ICPPASTCompositeTypeSpecifier) getPhysicalNode(); + } catch ( DOMException e ) { + return; + } + + //default constructor: A() addBinding( new CPPImplicitConstructor( this, IParameter.EMPTY_PARAMETER_ARRAY ) ); ICPPClassType clsType = (ICPPClassType) compTypeSpec.getName().resolveBinding(); @@ -119,7 +125,7 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope { /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPScope#getBinding(int, char[]) */ - public IBinding getBinding( IASTName name ) { + public IBinding getBinding( IASTName name ) throws DOMException { char [] c = name.toCharArray(); ICPPASTCompositeTypeSpecifier compType = (ICPPASTCompositeTypeSpecifier) getPhysicalNode(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassType.java index 267c1ed3fa4..5a551b13101 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassType.java @@ -13,7 +13,6 @@ */ package org.eclipse.cdt.internal.core.dom.parser.cpp; -import java.util.ArrayList; import java.util.List; import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement; @@ -28,6 +27,7 @@ import org.eclipse.cdt.core.dom.ast.IASTStatement; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IField; +import org.eclipse.cdt.core.dom.ast.IProblemBinding; import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier; @@ -131,16 +131,16 @@ public class CPPClassType implements ICPPClassType, ICPPBinding { /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.ICompositeType#getFields() */ - public List getFields() { + public IField[] getFields() { if( definition == null ){ checkForDefinition(); if( definition == null ) - return null; //TODO IProblem + return new IField [] { new CPPField.CPPFieldProblem( IProblemBinding.SEMANTIC_DEFINITION_NOT_FOUND, getNameCharArray() ) }; } IASTDeclaration[] members = definition.getMembers(); int size = members.length; - List fields = new ArrayList( size ); + IField[] fields = new IField[ size ]; if( size > 0 ){ for( int i = 0; i < size; i++ ){ @@ -151,7 +151,7 @@ public class CPPClassType implements ICPPClassType, ICPPBinding { IASTDeclarator declarator = declarators[i]; IBinding binding = declarator.getName().resolveBinding(); if( binding != null && binding instanceof IField ) - fields.add( binding ); + fields[i] = (IField) binding; } } } @@ -303,7 +303,7 @@ public class CPPClassType implements ICPPClassType, ICPPBinding { if( definition == null ){ checkForDefinition(); if( definition == null ){ - return null; //TODO problem + return new ICPPConstructor [] { new CPPConstructor.CPPConstructorProblem( IProblemBinding.SEMANTIC_DEFINITION_NOT_FOUND, getNameCharArray() ) }; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPCompositeBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPCompositeBinding.java index da6eb437884..80fd1cf706f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPCompositeBinding.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPCompositeBinding.java @@ -15,6 +15,7 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; import java.util.List; +import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IScope; @@ -49,7 +50,7 @@ public class CPPCompositeBinding implements ICPPCompositeBinding { /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.IBinding#getScope() */ - public IScope getScope() { + public IScope getScope() throws DOMException { return bindings[0].getScope(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPConstructor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPConstructor.java index a518cc50043..6d7fa3d72fa 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPConstructor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPConstructor.java @@ -13,6 +13,7 @@ */ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor; @@ -21,6 +22,15 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor; */ public class CPPConstructor extends CPPMethod implements ICPPConstructor { + static public class CPPConstructorProblem extends CPPMethod.CPPMethodProblem implements ICPPConstructor { + public CPPConstructorProblem( int id, char[] arg ) { + super( id, arg ); + } + + public boolean isExplicit() throws DOMException{ + throw new DOMException( this ); + } + } /** * @param declarator */ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPEnumeration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPEnumeration.java index a404c3b1d1e..c57f9ab3fca 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPEnumeration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPEnumeration.java @@ -17,6 +17,7 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IEnumeration; +import org.eclipse.cdt.core.dom.ast.IEnumerator; import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IType; @@ -84,4 +85,17 @@ public class CPPEnumeration implements IEnumeration, ICPPBinding { return t; } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IEnumeration#getEnumerators() + */ + public IEnumerator[] getEnumerators() { + IASTEnumerationSpecifier.IASTEnumerator[] enums = enumSpecifier.getEnumerators(); + IEnumerator [] bindings = new IEnumerator [ enums.length ]; + + for( int i = 0; i < enums.length; i++ ){ + bindings[i] = (IEnumerator) enums[i].getName().resolveBinding(); + } + return bindings; + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPField.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPField.java index 7a184990536..fddc1de981b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPField.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPField.java @@ -13,6 +13,7 @@ */ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.cpp.ICPPField; @@ -20,6 +21,23 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPField; * @author aniefer */ public class CPPField extends CPPVariable implements ICPPField, ICPPBinding { + public static class CPPFieldProblem extends CPPVariable.CPPVariableProblem implements ICPPField { + /** + * @param id + * @param arg + */ + public CPPFieldProblem( int id, char[] arg ) { + super( id, arg ); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPMember#getVisibility() + */ + public int getVisibility() throws DOMException { + throw new DOMException( this ); + } + } + public CPPField( IASTDeclarator declarator ){ super( declarator ); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java index 6fce8e01cf8..0dcd0a6596f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java @@ -13,22 +13,48 @@ */ package org.eclipse.cdt.internal.core.dom.parser.cpp; -import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator; +import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IFunction; import org.eclipse.cdt.core.dom.ast.IFunctionType; import org.eclipse.cdt.core.dom.ast.IParameter; import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator; +import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; /** * @author aniefer */ public class CPPFunction implements IFunction, ICPPBinding { + + public static class CPPFunctionProblem extends ProblemBinding implements IFunction { + + /** + * @param id + * @param arg + */ + public CPPFunctionProblem( int id, char[] arg ) { + super( id, arg ); + } + + public IParameter[] getParameters() throws DOMException { + throw new DOMException( this ); + } + + public IScope getFunctionScope() throws DOMException { + throw new DOMException( this ); + } + + public IFunctionType getType() throws DOMException { + throw new DOMException( this ); + } + } + protected ICPPASTFunctionDeclarator [] declarations; protected ICPPASTFunctionDeclarator definition; protected IFunctionType type = null; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionScope.java index 95dd88bed4d..8cb6b8005c2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionScope.java @@ -15,6 +15,7 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; import java.util.List; +import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IBinding; @@ -69,7 +70,7 @@ public class CPPFunctionScope extends CPPScope implements ICPPFunctionScope { return null; } - public IScope getParent() { + public IScope getParent() throws DOMException { IASTFunctionDefinition fn = (IASTFunctionDefinition) getPhysicalNode(); IFunction function = (IFunction) fn.getDeclarator().getName().resolveBinding(); if( function instanceof ICPPMethod ){ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionType.java index 922f4925dad..9053bec18ad 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionType.java @@ -14,6 +14,7 @@ */ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IFunctionType; import org.eclipse.cdt.core.dom.ast.IType; @@ -36,16 +37,24 @@ public class CPPFunctionType implements IFunctionType { public boolean equals( Object o ){ if( o instanceof IFunctionType ){ IFunctionType ft = (IFunctionType) o; - IType [] fps = ft.getParameterTypes(); - + IType [] fps; + try { + fps = ft.getParameterTypes(); + } catch ( DOMException e ) { + return false; + } if( fps.length != parameters.length ) return false; - //constructors & destructors have null return type - if( ( returnType == null ) ^ ( ft.getReturnType() == null ) ) - return false; - else if( returnType != null && ! returnType.equals( ft.getReturnType() ) ) + try { + //constructors & destructors have null return type + if( ( returnType == null ) ^ ( ft.getReturnType() == null ) ) + return false; + else if( returnType != null && ! returnType.equals( ft.getReturnType() ) ) + return false; + } catch ( DOMException e1 ) { return false; + } for( int i = 0; i < parameters.length; i++ ) if( ! parameters[i].equals( fps[i] ) ) return false; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethod.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethod.java index 27d81acca9e..dd14d2c68c9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethod.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethod.java @@ -13,6 +13,7 @@ */ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDeclarator; @@ -32,11 +33,25 @@ import org.eclipse.cdt.core.parser.util.CharArrayUtils; */ public class CPPMethod extends CPPFunction implements ICPPMethod { + public static class CPPMethodProblem extends CPPFunctionProblem implements ICPPMethod { + /** + * @param id + * @param arg + */ + public CPPMethodProblem( int id, char[] arg ) { + super( id, arg ); + } + + public int getVisibility() throws DOMException { + throw new DOMException( this ); + } + } + public CPPMethod( ICPPASTFunctionDeclarator declarator ){ super( declarator ); } - public IASTDeclaration getPrimaryDeclaration(){ + public IASTDeclaration getPrimaryDeclaration() throws DOMException{ //first check if we already know it if( declarations != null ){ for( int i = 0; i < declarations.length; i++ ){ @@ -76,7 +91,7 @@ public class CPPMethod extends CPPFunction implements ICPPMethod { /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPMember#getVisibility() */ - public int getVisibility() { + public int getVisibility() throws DOMException { IASTDeclaration decl = getPrimaryDeclaration(); IASTCompositeTypeSpecifier cls = (IASTCompositeTypeSpecifier) decl.getParent(); IASTDeclaration [] members = cls.getMembers(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPReferenceType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPReferenceType.java index d577269c765..feb0291ba42 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPReferenceType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPReferenceType.java @@ -14,6 +14,7 @@ */ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType; import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; @@ -47,7 +48,11 @@ public class CPPReferenceType implements ICPPReferenceType, ITypeContainer { return (obj == null); if( obj instanceof ICPPReferenceType ){ - return type.equals( ((ICPPReferenceType) obj).getType() ); + try { + return type.equals( ((ICPPReferenceType) obj).getType() ); + } catch ( DOMException e ) { + return false; + } } return false; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScope.java index 890a3b59aa5..5f3109d8ce9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScope.java @@ -13,14 +13,42 @@ */ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import java.util.List; + +import org.eclipse.cdt.core.dom.ast.DOMException; +import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope; +import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; /** * @author aniefer */ abstract public class CPPScope implements ICPPScope{ + public static class CPPScopeProblem extends ProblemBinding implements ICPPScope { + public CPPScopeProblem( int id, char[] arg ) { + super( id, arg ); + } + public void addBinding( IBinding binding ) throws DOMException { + throw new DOMException( this ); + } + + public IBinding getBinding( IASTName name ) throws DOMException { + throw new DOMException( this ); + } + + public IScope getParent() throws DOMException { + throw new DOMException( this ); + } + + public List find( String name ) throws DOMException { + throw new DOMException( this ); + } + } + + private IASTNode physicalNode; public CPPScope( IASTNode physicalNode ) { this.physicalNode = physicalNode; @@ -29,11 +57,11 @@ abstract public class CPPScope implements ICPPScope{ /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.IScope#getParent() */ - public IScope getParent() { + public IScope getParent() throws DOMException { return CPPVisitor.getContainingScope( physicalNode ); } - public IASTNode getPhysicalNode(){ + public IASTNode getPhysicalNode() throws DOMException{ return physicalNode; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java index 5f9e8bbd034..dd9867d1496 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java @@ -17,6 +17,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; @@ -199,7 +200,7 @@ public class CPPSemantics { public static final int USERDEFINED_CONVERSION_RANK = 4; public static final int ELLIPSIS_CONVERSION = 5; - public int compare( Cost cost ){ + public int compare( Cost cost ) throws DOMException{ int result = 0; if( rank != cost.rank ){ @@ -243,18 +244,26 @@ public class CPPSemantics { op1 = null; op2 = null; while( true ){ - if( t1 instanceof ITypedef ) - t1 = ((ITypedef)t1).getType(); - else { + if( t1 instanceof ITypedef ) + try { + t1 = ((ITypedef)t1).getType(); + } catch ( DOMException e ) { + t1 = e.getProblem(); + } + else { if( t1 instanceof IPointerType ) op1 = (IPointerType) t1; break; } } while( true ){ - if( t2 instanceof ITypedef ) - t2 = ((ITypedef)t2).getType(); - else { + if( t2 instanceof ITypedef ) + try { + t2 = ((ITypedef)t2).getType(); + } catch ( DOMException e ) { + t2 = e.getProblem(); + } + else { if( t2 instanceof IPointerType ) op1 = (IPointerType) t2; break; @@ -305,22 +314,35 @@ public class CPPSemantics { //1: get some context info off of the name to figure out what kind of lookup we want LookupData data = createLookupData( name ); - //2: lookup - lookup( data, name ); + try { + //2: lookup + lookup( data, name ); + } catch ( DOMException e1 ) { + data.problem = (ProblemBinding) e1.getProblem(); + } if( data.problem != null ) return data.problem; //3: resolve ambiguities - IBinding binding = resolveAmbiguities( data, name ); - - //4: post processing + IBinding binding; + try { + binding = resolveAmbiguities( data, name ); + } catch ( DOMException e2 ) { + binding = e2.getProblem(); + } + //4: post processing if( binding instanceof ICPPClassType && data.considerConstructors() ){ ICPPClassType cls = (ICPPClassType) binding; - //force resolution of constructor bindings - cls.getConstructors(); - //then use the class scope to resolve which one. - binding = ((ICPPClassScope)cls.getCompositeScope()).getBinding( name ); + try { + //force resolution of constructor bindings + cls.getConstructors(); + //then use the class scope to resolve which one. + binding = ((ICPPClassScope)cls.getCompositeScope()).getBinding( name ); + } catch ( DOMException e ) { + binding = e.getProblem(); + } + } if( binding != null && data.forDefinition() && !( binding instanceof IProblemBinding ) ){ addDefinition( binding, name ); @@ -380,7 +402,7 @@ public class CPPSemantics { return data; } - static private ICPPScope getLookupScope( IASTName name ){ + static private ICPPScope getLookupScope( IASTName name ) throws DOMException{ IASTNode parent = name.getParent(); if( parent instanceof ICPPASTBaseSpecifier ) { @@ -395,7 +417,7 @@ public class CPPSemantics { return (ICPPScope) CPPVisitor.getContainingScope( name ); } - static private void lookup( CPPSemantics.LookupData data, IASTName name ){ + static private void lookup( CPPSemantics.LookupData data, IASTName name ) throws DOMException{ IASTNode node = name; ICPPScope scope = getLookupScope( name ); @@ -458,7 +480,7 @@ public class CPPSemantics { } } - private static List lookupInParents( CPPSemantics.LookupData data, ICPPClassScope lookIn ){ + private static List lookupInParents( CPPSemantics.LookupData data, ICPPClassScope lookIn ) throws DOMException{ ICPPASTCompositeTypeSpecifier compositeTypeSpec = (ICPPASTCompositeTypeSpecifier) lookIn.getPhysicalNode(); ICPPASTBaseSpecifier [] bases = compositeTypeSpec.getBaseSpecifiers(); @@ -559,7 +581,7 @@ public class CPPSemantics { return false; } - static private void processDirectives( CPPSemantics.LookupData data, IScope scope, List directives ){ + static private void processDirectives( CPPSemantics.LookupData data, IScope scope, List directives ) throws DOMException{ if( directives == null || directives.size() == 0 ) return; @@ -596,7 +618,7 @@ public class CPPSemantics { } - static private ICPPScope getClosestEnclosingScope( IScope scope1, IScope scope2 ){ + static private ICPPScope getClosestEnclosingScope( IScope scope1, IScope scope2 ) throws DOMException{ ObjectSet set = new ObjectSet( 2 ); IScope parent = scope1; while( parent != null ){ @@ -614,8 +636,9 @@ public class CPPSemantics { * * @param scope * @return List of encountered using directives + * @throws DOMException */ - static private List lookupInScope( CPPSemantics.LookupData data, ICPPScope scope, IASTNode blockItem, List usingDirectives ) { + static private List lookupInScope( CPPSemantics.LookupData data, ICPPScope scope, IASTNode blockItem, List usingDirectives ) throws DOMException { IASTName possible = null; IASTNode [] nodes = null; IASTNode parent = scope.getPhysicalNode(); @@ -691,7 +714,7 @@ public class CPPSemantics { return found; } - static private List lookupInNominated( CPPSemantics.LookupData data, ICPPScope scope, List transitives ){ + static private List lookupInNominated( CPPSemantics.LookupData data, ICPPScope scope, List transitives ) throws DOMException{ if( data.usingDirectives.isEmpty() ) return transitives; @@ -859,7 +882,11 @@ public class CPPSemantics { LookupData data = createLookupData( name ); data.foundItems = bindings; - return resolveAmbiguities( data, name ); + try { + return resolveAmbiguities( data, name ); + } catch ( DOMException e ) { + return e.getProblem(); + } } static private boolean declaredBefore( IBinding binding, IASTNode node ){ @@ -876,7 +903,7 @@ public class CPPSemantics { return false; } - static private IBinding resolveAmbiguities( CPPSemantics.LookupData data, IASTName name ) { + static private IBinding resolveAmbiguities( CPPSemantics.LookupData data, IASTName name ) throws DOMException { if( data.foundItems == null || data.foundItems.size() == 0 ) return null; @@ -942,7 +969,7 @@ public class CPPSemantics { return obj; } - static private boolean functionHasParameters( IFunction function, IASTParameterDeclaration [] params ){ + static private boolean functionHasParameters( IFunction function, IASTParameterDeclaration [] params ) throws DOMException{ IFunctionType ftype = function.getType(); if( params.length == 0 ){ return ftype.getParameterTypes().length == 0; @@ -956,7 +983,7 @@ public class CPPSemantics { return false; } - static private void reduceToViable( LookupData data, List functions ){ + static private void reduceToViable( LookupData data, List functions ) throws DOMException{ Object [] fParams = data.functionParameters; int numParameters = ( fParams != null ) ? fParams.length : 0; int num; @@ -1047,7 +1074,7 @@ public class CPPSemantics { return VOID_TYPE; return null; } - static private IBinding resolveFunction( CPPSemantics.LookupData data, List fns ){ + static private IBinding resolveFunction( CPPSemantics.LookupData data, List fns ) throws DOMException{ if( data.forUsingDeclaration() ){ if( fns.size() == 1 ) return (IBinding) fns.get( 0 ); @@ -1209,7 +1236,7 @@ public class CPPSemantics { return bestFn; } - static private Cost checkStandardConversionSequence( IType source, IType target ) { + static private Cost checkStandardConversionSequence( IType source, IType target ) throws DOMException { Cost cost = lvalue_to_rvalue( source, target ); if( cost.source == null || cost.target == null ){ @@ -1250,7 +1277,7 @@ public class CPPSemantics { return cost; } - static private Cost checkUserDefinedConversionSequence( IType source, IType target ) { + static private Cost checkUserDefinedConversionSequence( IType source, IType target ) throws DOMException { Cost cost = null; Cost constructorCost = null; Cost conversionCost = null; @@ -1320,18 +1347,22 @@ public class CPPSemantics { } static protected IType getUltimateType( IType type ){ - while( true ){ - if( type instanceof ITypedef ) - type = ((ITypedef)type).getType(); - else if( type instanceof IQualifierType ) - type = ((IQualifierType)type).getType(); - else if( type instanceof IPointerType ) - type = ((IPointerType) type).getType(); - else if( type instanceof ICPPReferenceType ) - type = ((ICPPReferenceType)type).getType(); - else - return type; - } + try { + while( true ){ + if( type instanceof ITypedef ) + type = ((ITypedef)type).getType(); + else if( type instanceof IQualifierType ) + type = ((IQualifierType)type).getType(); + else if( type instanceof IPointerType ) + type = ((IPointerType) type).getType(); + else if( type instanceof ICPPReferenceType ) + type = ((ICPPReferenceType)type).getType(); + else + return type; + } + } catch ( DOMException e ) { + return e.getProblem(); + } } static private boolean isCompleteType( IType type ){ @@ -1341,7 +1372,7 @@ public class CPPSemantics { } return true; } - static private Cost lvalue_to_rvalue( IType source, IType target ){ + static private Cost lvalue_to_rvalue( IType source, IType target ) throws DOMException{ Cost cost = new Cost( source, target ); if( ! isCompleteType( source ) ){ @@ -1363,7 +1394,7 @@ public class CPPSemantics { return cost; } - static private void qualificationConversion( Cost cost ){ + static private void qualificationConversion( Cost cost ) throws DOMException{ boolean canConvert = true; IPointerType op1, op2; @@ -1441,8 +1472,9 @@ public class CPPSemantics { * following that can hold it: int, unsigned int, long unsigned long. * 4.5-4 bool can be promoted to int * 4.6 float can be promoted to double + * @throws DOMException */ - static private void promotion( Cost cost ){ + static private void promotion( Cost cost ) throws DOMException{ IType src = getUltimateType( cost.source ); IType trg = getUltimateType( cost.target ); @@ -1467,7 +1499,7 @@ public class CPPSemantics { cost.rank = (cost.promotion > 0 ) ? Cost.PROMOTION_RANK : Cost.NO_MATCH_RANK; } - static private void conversion( Cost cost ){ + static private void conversion( Cost cost ) throws DOMException{ IType src = cost.source; IType trg = cost.target; @@ -1530,7 +1562,7 @@ public class CPPSemantics { } - static private void derivedToBaseConversion( Cost cost ) { + static private void derivedToBaseConversion( Cost cost ) throws DOMException { IType s = getUltimateType( cost.source ); IType t = getUltimateType( cost.target ); @@ -1544,7 +1576,7 @@ public class CPPSemantics { } } - static private int hasBaseClass( ICPPClassType symbol, ICPPClassType base, boolean needVisibility ) { + static private int hasBaseClass( ICPPClassType symbol, ICPPClassType base, boolean needVisibility ) throws DOMException { if( symbol == base ){ return 0; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTypedef.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTypedef.java index 4d6e35c16ee..aafe48381a5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTypedef.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTypedef.java @@ -13,6 +13,7 @@ */ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IScope; @@ -52,7 +53,11 @@ public class CPPTypedef implements ITypedef, ITypeContainer, ICPPBinding { public boolean equals( Object o ){ if( o instanceof ITypedef ) - return getType().equals( ((ITypedef)o).getType()); + try { + return getType().equals( ((ITypedef)o).getType()); + } catch ( DOMException e ) { + return false; + } if( !( o instanceof IType ) ) return false; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVariable.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVariable.java index 1adde9f3f1f..c9e373425fb 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVariable.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVariable.java @@ -13,16 +13,28 @@ */ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IVariable; +import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; /** * @author aniefer */ public class CPPVariable implements IVariable, ICPPBinding { + public static class CPPVariableProblem extends ProblemBinding implements IVariable{ + public CPPVariableProblem( int id, char[] arg ) { + super( id, arg ); + } + + public IType getType() throws DOMException { + throw new DOMException( this ); + } + + } private IASTDeclarator declarator = null; private IType type = null; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java index 4b0277d9289..e99bf30534b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java @@ -16,6 +16,7 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; import java.util.ArrayList; +import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator; import org.eclipse.cdt.core.dom.ast.IASTArrayModifier; import org.eclipse.cdt.core.dom.ast.IASTArraySubscriptExpression; @@ -171,45 +172,69 @@ public class CPPVisitor { private static IBinding createBinding( IASTGotoStatement gotoStatement ) { ICPPFunctionScope functionScope = (ICPPFunctionScope) getContainingScope( gotoStatement ); IASTName name = gotoStatement.getName(); - IBinding binding = functionScope.getBinding( name ); - if( binding == null ){ - binding = new CPPLabel( gotoStatement ); - functionScope.addBinding( binding ); - } + IBinding binding; + try { + binding = functionScope.getBinding( name ); + if( binding == null ){ + binding = new CPPLabel( gotoStatement ); + functionScope.addBinding( binding ); + } + } catch ( DOMException e ) { + binding = e.getProblem(); + } + return binding; } private static IBinding createBinding( IASTLabelStatement labelStatement ) { ICPPFunctionScope functionScope = (ICPPFunctionScope) getContainingScope( labelStatement ); IASTName name = labelStatement.getName(); - IBinding binding = functionScope.getBinding( name ); - if( binding == null ){ - binding = new CPPLabel( labelStatement ); - functionScope.addBinding( binding ); - } else { - ((CPPLabel)binding).setLabelStatement( labelStatement ); - } + IBinding binding; + try { + binding = functionScope.getBinding( name ); + if( binding == null ){ + binding = new CPPLabel( labelStatement ); + functionScope.addBinding( binding ); + } else { + ((CPPLabel)binding).setLabelStatement( labelStatement ); + } + } catch ( DOMException e ) { + binding = e.getProblem(); + } + return binding; } private static IBinding createBinding( IASTEnumerator enumerator ) { ICPPScope scope = (ICPPScope) getContainingScope( enumerator ); - IBinding enumtor = scope.getBinding( enumerator.getName() ); - if( enumtor == null ){ - enumtor = new CPPEnumerator( enumerator ); - scope.addBinding( enumtor ); + IBinding enumtor; + try { + enumtor = scope.getBinding( enumerator.getName() ); + if( enumtor == null ){ + enumtor = new CPPEnumerator( enumerator ); + scope.addBinding( enumtor ); + } + } catch ( DOMException e ) { + enumtor = e.getProblem(); } + return enumtor; } private static IBinding createBinding( IASTEnumerationSpecifier specifier ) { ICPPScope scope = (ICPPScope) getContainingScope( specifier ); - IBinding enumeration = scope.getBinding( specifier.getName() ); - if( enumeration == null ){ - enumeration = new CPPEnumeration( specifier ); - scope.addBinding( enumeration ); + IBinding enumeration; + try { + enumeration = scope.getBinding( specifier.getName() ); + if( enumeration == null ){ + enumeration = new CPPEnumeration( specifier ); + scope.addBinding( enumeration ); + } + } catch ( DOMException e ) { + enumeration = e.getProblem(); } + return enumeration; } @@ -227,14 +252,20 @@ public class CPPVisitor { } ICPPScope scope = (ICPPScope) getContainingScope( elabType ); - CPPClassType binding = (CPPClassType) scope.getBinding( elabType.getName() ); - if( binding == null ){ - if( elabType.getKind() != IASTElaboratedTypeSpecifier.k_enum ) - binding = new CPPClassType( elabType ); - scope.addBinding( binding ); - } else { - binding.addDeclaration( elabType ); - } + IBinding binding; + try { + binding = scope.getBinding( elabType.getName() ); + if( binding == null ){ + if( elabType.getKind() != IASTElaboratedTypeSpecifier.k_enum ) + binding = new CPPClassType( elabType ); + scope.addBinding( binding ); + } else { + ((CPPClassType)binding).addDeclaration( elabType ); + } + } catch ( DOMException e ) { + binding = e.getProblem(); + } + return binding; } private static IBinding createBinding( ICPPASTCompositeTypeSpecifier compType ){ @@ -244,24 +275,35 @@ public class CPPVisitor { name = ns[ ns.length - 1 ]; } ICPPScope scope = (ICPPScope) getContainingScope( name ); - IBinding binding = scope.getBinding( compType.getName() ); - if( binding == null || !(binding instanceof ICPPClassType) ){ - binding = new CPPClassType( compType ); - scope.addBinding( binding ); - } else { - ((CPPClassType)binding).addDefinition( compType ); - } + IBinding binding; + try { + binding = scope.getBinding( compType.getName() ); + if( binding == null || !(binding instanceof ICPPClassType) ){ + binding = new CPPClassType( compType ); + scope.addBinding( binding ); + } else { + ((CPPClassType)binding).addDefinition( compType ); + } + } catch ( DOMException e ) { + binding = e.getProblem(); + } + return binding; } private static IBinding createBinding( IASTDeclaration declaration ){ if( declaration instanceof ICPPASTNamespaceDefinition ){ ICPPASTNamespaceDefinition namespaceDef = (ICPPASTNamespaceDefinition) declaration; ICPPScope scope = (ICPPScope) getContainingScope( namespaceDef ); - CPPNamespace binding = (CPPNamespace) scope.getBinding( namespaceDef.getName() ); - if( binding == null ){ - binding = new CPPNamespace( namespaceDef.getName() ); - scope.addBinding( binding ); - } + IBinding binding; + try { + binding = scope.getBinding( namespaceDef.getName() ); + if( binding == null ){ + binding = new CPPNamespace( namespaceDef.getName() ); + scope.addBinding( binding ); + } + } catch ( DOMException e ) { + binding = e.getProblem(); + } return binding; } else if( declaration instanceof ICPPASTUsingDirective ){ return CPPSemantics.resolveBinding( ((ICPPASTUsingDirective) declaration).getQualifiedName() ); @@ -288,21 +330,30 @@ public class CPPVisitor { } ICPPScope scope = (ICPPScope) getContainingScope( parent ); - IBinding binding = ( scope != null ) ? scope.getBinding( declarator.getName() ) : null; - - if( declarator instanceof ICPPASTFunctionDeclarator ){ + IBinding binding; + try { + binding = ( scope != null ) ? scope.getBinding( declarator.getName() ) : null; + } catch ( DOMException e ) { + binding = null; + } + + if( declarator instanceof ICPPASTFunctionDeclarator ){ if( binding != null && binding instanceof IFunction ){ IFunction function = (IFunction) binding; - IFunctionType ftype = function.getType(); - IType type = createType( declarator ); - if( ftype.equals( type ) ){ - if( parent instanceof IASTSimpleDeclaration ) - ((CPPFunction)function).addDeclaration( (ICPPASTFunctionDeclarator) declarator ); - else - ((CPPFunction)function).addDefinition( (ICPPASTFunctionDeclarator) declarator ); - - return function; - } + IFunctionType ftype; + try { + ftype = function.getType(); + IType type = createType( declarator ); + if( ftype.equals( type ) ){ + if( parent instanceof IASTSimpleDeclaration ) + ((CPPFunction)function).addDeclaration( (ICPPASTFunctionDeclarator) declarator ); + else + ((CPPFunction)function).addDefinition( (ICPPASTFunctionDeclarator) declarator ); + + return function; + } + } catch ( DOMException e1 ) { + } } if( scope instanceof ICPPClassScope ){ if( isConstructor( scope, declarator) ) @@ -328,8 +379,13 @@ public class CPPVisitor { } } - if( scope != null && binding != null ) - scope.addBinding( binding ); + if( scope != null && binding != null ){ + try { + scope.addBinding( binding ); + } catch ( DOMException e1 ) { + } + } + return binding; } @@ -337,8 +393,13 @@ public class CPPVisitor { if( containingScope == null || !(containingScope instanceof ICPPClassScope) ) return false; - ICPPASTCompositeTypeSpecifier clsTypeSpec = (ICPPASTCompositeTypeSpecifier) ((ICPPClassScope)containingScope).getPhysicalNode(); - return isConstructor( clsTypeSpec.getName(), declarator ); + ICPPASTCompositeTypeSpecifier clsTypeSpec; + try { + clsTypeSpec = (ICPPASTCompositeTypeSpecifier) ((ICPPClassScope)containingScope).getPhysicalNode(); + } catch ( DOMException e ) { + return false; + } + return isConstructor( clsTypeSpec.getName(), declarator ); } public static boolean isConstructor( IASTName parentName, IASTDeclarator declarator ){ if( declarator == null || !(declarator instanceof IASTFunctionDeclarator) ) @@ -407,26 +468,30 @@ public class CPPVisitor { } public static IScope getContainingScope( IASTName name ){ IASTNode parent = name.getParent(); - if( parent instanceof ICPPASTQualifiedName ){ - IASTName [] names = ((ICPPASTQualifiedName) parent).getNames(); - int i = 0; - for( ; i < names.length; i++ ){ - if( names[i] == name ) break; - } - if( i > 0 ){ - IBinding binding = names[i - 1].resolveBinding(); - if( binding instanceof ICPPClassType ){ - return ((ICPPClassType)binding).getCompositeScope(); - } else if( binding instanceof ICPPNamespace ){ - return ((ICPPNamespace)binding).getNamespaceScope(); + try { + if( parent instanceof ICPPASTQualifiedName ){ + IASTName [] names = ((ICPPASTQualifiedName) parent).getNames(); + int i = 0; + for( ; i < names.length; i++ ){ + if( names[i] == name ) break; + } + if( i > 0 ){ + IBinding binding = names[i - 1].resolveBinding(); + if( binding instanceof ICPPClassType ){ + return ((ICPPClassType)binding).getCompositeScope(); + } else if( binding instanceof ICPPNamespace ){ + return ((ICPPNamespace)binding).getNamespaceScope(); + } + } + } else if( parent instanceof ICPPASTFieldReference ){ + IASTExpression owner = ((ICPPASTFieldReference)parent).getFieldOwner(); + IType type = CPPSemantics.getUltimateType( getExpressionType( owner ) ); + if( type instanceof ICPPClassType ){ + return ((ICPPClassType) type).getCompositeScope(); } } - } else if( parent instanceof ICPPASTFieldReference ){ - IASTExpression owner = ((ICPPASTFieldReference)parent).getFieldOwner(); - IType type = CPPSemantics.getUltimateType( getExpressionType( owner ) ); - if( type instanceof ICPPClassType ){ - return ((ICPPClassType) type).getCompositeScope(); - } + } catch( DOMException e ){ + return e.getProblem(); } return getContainingScope( parent ); } @@ -462,13 +527,21 @@ public class CPPVisitor { } else if( parent instanceof IASTFunctionDefinition ){ IASTFunctionDeclarator fnDeclarator = ((IASTFunctionDefinition) parent ).getDeclarator(); IFunction function = (IFunction) fnDeclarator.getName().resolveBinding(); - scope = function.getFunctionScope(); + try { + scope = function.getFunctionScope(); + } catch ( DOMException e ) { + return e.getProblem(); + } } if( statement instanceof IASTGotoStatement || statement instanceof IASTLabelStatement ){ //labels have function scope while( scope != null && !(scope instanceof ICPPFunctionScope) ){ - scope = scope.getParent(); + try { + scope = scope.getParent(); + } catch ( DOMException e ) { + return e.getProblem(); + } } } @@ -1127,11 +1200,19 @@ public class CPPVisitor { ArrayList temp = new ArrayList(); for( int i = 0; i < parameters.length; i++ ){ - pt = parameters[i].getType(); + try { + pt = parameters[i].getType(); + } catch ( DOMException e ) { + pt = e.getProblem(); + } temp.add( pt.clone() ); while( pt instanceof ITypeContainer){ - pt = ((ITypeContainer)pt).getType(); + try { + pt = ((ITypeContainer)pt).getType(); + } catch ( DOMException e1 ) { + pt = e1.getProblem(); + } if( pt instanceof ITypeContainer && !(pt instanceof ITypedef) ){ IType t = (IType) pt.clone(); ((ITypeContainer) temp.get( temp.size() - 1 )).setType( t ); @@ -1152,7 +1233,11 @@ public class CPPVisitor { IType lastType = (IType) temp.get( lastIdx ); if( lastType instanceof IArrayType ){ - lastType = new CPPPointerType( ((IArrayType) lastType).getType() ); + try { + lastType = new CPPPointerType( ((IArrayType) lastType).getType() ); + } catch ( DOMException e1 ) { + lastType = e1.getProblem(); + } } else if( lastType instanceof IFunctionType ){ lastType = new CPPPointerType( lastType ); } @@ -1181,7 +1266,11 @@ public class CPPVisitor { //any parameter of type array of T is adjusted to be pointer to T if( pt instanceof IArrayType ){ IArrayType at = (IArrayType) pt; - pt = new CPPPointerType( at.getType() ); + try { + pt = new CPPPointerType( at.getType() ); + } catch ( DOMException e ) { + pt = e.getProblem(); + } } //any parameter to type function returning T is adjusted to be pointer to function @@ -1316,7 +1405,11 @@ public class CPPVisitor { if( expression instanceof IASTIdExpression ){ IBinding binding = resolveBinding( expression ); if( binding instanceof IVariable ){ - return ((IVariable)binding).getType(); + try { + return ((IVariable)binding).getType(); + } catch ( DOMException e ) { + return e.getProblem(); + } } } else if( expression instanceof IASTCastExpression ){ IASTTypeId id = ((IASTCastExpression)expression).getTypeId(); @@ -1342,9 +1435,15 @@ public class CPPVisitor { } else if( expression instanceof IASTFunctionCallExpression ){ IBinding binding = resolveBinding( expression ); if( binding instanceof IFunction ){ - IFunctionType fType = ((IFunction)binding).getType(); - if( fType != null ) - return fType.getReturnType(); + IFunctionType fType; + try { + fType = ((IFunction)binding).getType(); + if( fType != null ) + return fType.getReturnType(); + } catch ( DOMException e ) { + return e.getProblem(); + } + } } else if( expression instanceof IASTUnaryExpression )