From a0f0ff7593c8df12c58e2abc6e09ea30177381ca Mon Sep 17 00:00:00 2001 From: Andrew Niefer Date: Wed, 23 Feb 2005 18:37:05 +0000 Subject: [PATCH] fix bug 86279 --- .../core/parser/tests/ast2/AST2CPPTests.java | 24 +++++++++++++++++ .../cdt/core/parser/util/ArrayUtil.java | 26 +++++++++++++++++++ .../core/dom/parser/cpp/CPPSemantics.java | 10 ++++++- .../core/dom/parser/cpp/CPPVisitor.java | 1 + 4 files changed, 60 insertions(+), 1 deletion(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java index 3c4000fb03f..be19fb133e2 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java @@ -2014,5 +2014,29 @@ public class AST2CPPTests extends AST2BaseTest { assertEquals( other.getName(), "other" ); //$NON-NLS-1$ } + + public void testBug86279() throws Exception { + StringBuffer buffer = new StringBuffer(); + buffer.append("extern \"C\" { \n"); //$NON-NLS-1$ + buffer.append(" void printf( const char * ); \n"); //$NON-NLS-1$ + buffer.append(" void sprintf( const char * ); \n"); //$NON-NLS-1$ + buffer.append("} \n"); //$NON-NLS-1$ + buffer.append("void foo(){ \n"); //$NON-NLS-1$ + buffer.append(" char *p; \n"); //$NON-NLS-1$ + buffer.append(" printf( p ); \n"); //$NON-NLS-1$ + buffer.append(" printf( \"abc\" ); \n"); //$NON-NLS-1$ + buffer.append("} \n"); //$NON-NLS-1$ + + IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); + CPPNameCollector col = new CPPNameCollector(); + tu.getVisitor().visitTranslationUnit( col); + + IFunction r1 = (IFunction) col.getName(6).resolveBinding(); + IFunction r2 = (IFunction) col.getName(8).resolveBinding(); + IFunction printf = (IFunction) col.getName(0).resolveBinding(); + + assertSame( printf, r1 ); + assertSame( printf, r2 ); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/ArrayUtil.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/ArrayUtil.java index bfb3f5f7acf..b52d193a63e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/ArrayUtil.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/ArrayUtil.java @@ -134,4 +134,30 @@ public class ArrayUtil { System.arraycopy( source, 0, temp, firstFree, numToAdd ); return temp; } + + /** + * Replaces the item at index idx with the given object. If the obj is an Object[], + * then the contents of that array are inserted with the first element overwriting + * whatever was at idx. + * @param class1 + * @param nodes + * @param declarations + * @return + */ + public static Object[] replace( Class c, Object[] array, int idx, Object obj ) { + if( array == null || idx >= array.length ) + return array; + + if( obj instanceof Object [] ){ + Object [] objs = (Object[]) obj; + Object [] temp = (Object[]) Array.newInstance( c, array.length + objs.length - 1 ); + System.arraycopy( array, 0, temp, 0, idx ); + System.arraycopy( objs, 0, temp, idx, objs.length ); + System.arraycopy( array, idx + 1, temp, idx + objs.length, array.length - idx - 1); + array = temp; + } else { + array[idx] = obj; + } + return array; + } } 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 13a869c9854..006ba388346 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 @@ -66,6 +66,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTElaboratedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFieldReference; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLinkageSpecification; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceAlias; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition; @@ -871,6 +872,10 @@ public class CPPSemantics { IASTNode item = ( nodes != null ? (nodes.length > 0 ? nodes[++idx] : null ) : parent ); while( item != null ) { + if( item instanceof ICPPASTLinkageSpecification ){ + nodes = (IASTNode[]) ArrayUtil.replace( IASTDeclaration.class, nodes, idx, ((ICPPASTLinkageSpecification)item).getDeclarations() ); + item = nodes[idx]; + } if( !checkWholeClassScope && blockItem != null && ((ASTNode)item).getOffset() > ((ASTNode) blockItem).getOffset() ) break; @@ -1896,7 +1901,10 @@ public class CPPSemantics { } if( s instanceof IQualifierType ^ t instanceof IQualifierType ){ - canConvert = false; + if( t instanceof IQualifierType ) + canConvert = true; + else + canConvert = false; } else if( s instanceof IQualifierType && t instanceof IQualifierType ){ IQualifierType qs = (IQualifierType) s, qt = (IQualifierType) t; if( qs.isConst() && !qt.isConst() || qs.isVolatile() && !qt.isVolatile() ) 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 ec0ebcf2f67..2190bedf1ae 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 @@ -1763,6 +1763,7 @@ public class CPPVisitor implements ICPPASTVisitor { return new CPPBasicType( IBasicType.t_int, 0 ); case IASTLiteralExpression.lk_string_literal: IType type = new CPPBasicType( IBasicType.t_char, 0 ); + type = new CPPQualifierType( type, true, false ); return new CPPPointerType( type ); }