mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 10:16:03 +02:00
fix bug 86279
This commit is contained in:
parent
511c556400
commit
a0f0ff7593
4 changed files with 60 additions and 1 deletions
|
@ -2014,5 +2014,29 @@ public class AST2CPPTests extends AST2BaseTest {
|
||||||
|
|
||||||
assertEquals( other.getName(), "other" ); //$NON-NLS-1$
|
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 );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -134,4 +134,30 @@ public class ArrayUtil {
|
||||||
System.arraycopy( source, 0, temp, firstFree, numToAdd );
|
System.arraycopy( source, 0, temp, firstFree, numToAdd );
|
||||||
return temp;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.ICPPASTElaboratedTypeSpecifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFieldReference;
|
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.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.ICPPASTNamedTypeSpecifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceAlias;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceAlias;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
|
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 );
|
IASTNode item = ( nodes != null ? (nodes.length > 0 ? nodes[++idx] : null ) : parent );
|
||||||
|
|
||||||
while( item != null ) {
|
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() )
|
if( !checkWholeClassScope && blockItem != null && ((ASTNode)item).getOffset() > ((ASTNode) blockItem).getOffset() )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -1896,6 +1901,9 @@ public class CPPSemantics {
|
||||||
}
|
}
|
||||||
|
|
||||||
if( s instanceof IQualifierType ^ t instanceof IQualifierType ){
|
if( s instanceof IQualifierType ^ t instanceof IQualifierType ){
|
||||||
|
if( t instanceof IQualifierType )
|
||||||
|
canConvert = true;
|
||||||
|
else
|
||||||
canConvert = false;
|
canConvert = false;
|
||||||
} else if( s instanceof IQualifierType && t instanceof IQualifierType ){
|
} else if( s instanceof IQualifierType && t instanceof IQualifierType ){
|
||||||
IQualifierType qs = (IQualifierType) s, qt = (IQualifierType) t;
|
IQualifierType qs = (IQualifierType) s, qt = (IQualifierType) t;
|
||||||
|
|
|
@ -1763,6 +1763,7 @@ public class CPPVisitor implements ICPPASTVisitor {
|
||||||
return new CPPBasicType( IBasicType.t_int, 0 );
|
return new CPPBasicType( IBasicType.t_int, 0 );
|
||||||
case IASTLiteralExpression.lk_string_literal:
|
case IASTLiteralExpression.lk_string_literal:
|
||||||
IType type = new CPPBasicType( IBasicType.t_char, 0 );
|
IType type = new CPPBasicType( IBasicType.t_char, 0 );
|
||||||
|
type = new CPPQualifierType( type, true, false );
|
||||||
return new CPPPointerType( type );
|
return new CPPPointerType( type );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue