mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-05 00:36:16 +02:00
fixed calculation of conversion function names
This commit is contained in:
parent
f891a885bd
commit
1d4f6f9b9f
3 changed files with 33 additions and 32 deletions
|
@ -113,5 +113,14 @@ public class C99CompleteParser2Tests extends CompleteParser2Tests {
|
|||
//fail();
|
||||
} catch(AssertionFailedError _) { }
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void testGNUASMExtension() throws Exception {
|
||||
try {
|
||||
super.testGNUASMExtension();
|
||||
fail();
|
||||
} catch(AssertionFailedError _) { }
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -309,24 +309,6 @@ public abstract class BuildASTParserAction {
|
|||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Converts the given token list to a char[] suitable for
|
||||
* creating a name node. Spaces are discarded.
|
||||
*/
|
||||
protected static char[] tokenListToNameCharArray(List<IToken> tokens) {
|
||||
StringBuilder sb = new StringBuilder(20); // longest operator name: operator delete[]
|
||||
|
||||
for(IToken t : tokens)
|
||||
sb.append(t.toString());
|
||||
|
||||
int n = sb.length();
|
||||
char[] cs = new char[n];
|
||||
sb.getChars(0, n, cs, 0);
|
||||
return cs;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Finds the tokens in the given list that are between startOffset and endOffset.
|
||||
* Note, the offsets have to be exact.
|
||||
|
|
|
@ -426,7 +426,9 @@ public class CPPBuildASTParserAction extends BuildASTParserAction {
|
|||
public void consumeConversionName() {
|
||||
if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
|
||||
|
||||
char[] chars = tokenListToNameCharArray(parser.getRuleTokens());
|
||||
String rep = createStringRepresentation(parser.getRuleTokens());
|
||||
char[] chars = rep.toCharArray();
|
||||
|
||||
IASTTypeId typeId = (IASTTypeId) astStack.pop();
|
||||
ICPPASTConversionName name = nodeFactory.newCPPConversionName(chars, typeId);
|
||||
setOffsetAndLength(name);
|
||||
|
@ -445,8 +447,7 @@ public class CPPBuildASTParserAction extends BuildASTParserAction {
|
|||
public void consumeDestructorName() {
|
||||
if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
|
||||
|
||||
// concatenate the '~' with the identifier token
|
||||
char[] chars = tokenListToNameCharArray(parser.getRuleTokens());
|
||||
char[] chars = ("~" + parser.getRightIToken()).toCharArray(); //$NON-NLS-1$
|
||||
|
||||
IASTName name = nodeFactory.newName(chars);
|
||||
setOffsetAndLength(name);
|
||||
|
@ -746,19 +747,14 @@ public class CPPBuildASTParserAction extends BuildASTParserAction {
|
|||
for(IASTName name : reverseIterable(names))
|
||||
qualifiedName.addName(name);
|
||||
|
||||
// compute the signature, find the tokens that make up the name
|
||||
List<IToken> nameTokens = tokenOffsetSubList(parser.getRuleTokens(), startOffset, endOffset);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
IToken prev = null;
|
||||
for(IToken t : nameTokens) {
|
||||
if(needSpaceBetween(prev, t))
|
||||
sb.append(' ');
|
||||
sb.append(t.toString());
|
||||
prev = t;
|
||||
if(qualifiedName instanceof CPPASTQualifiedName) {
|
||||
// compute the signature, find the tokens that make up the name
|
||||
List<IToken> nameTokens = tokenOffsetSubList(parser.getRuleTokens(), startOffset, endOffset);
|
||||
String signature = createStringRepresentation(nameTokens);
|
||||
((CPPASTQualifiedName)qualifiedName).setSignature(signature);
|
||||
}
|
||||
((CPPASTQualifiedName)qualifiedName).setSignature(sb.toString());
|
||||
|
||||
// there must be a dummy name in the AST after the last double colon, this happens with pointer to member
|
||||
// there must be a dummy name in the AST after the last double colon, this happens with pointer to member names
|
||||
if(endsWithColonColon) {
|
||||
IASTName dummyName = nodeFactory.newName();
|
||||
setOffsetAndLength(dummyName, endOffset, 0);
|
||||
|
@ -769,7 +765,21 @@ public class CPPBuildASTParserAction extends BuildASTParserAction {
|
|||
}
|
||||
|
||||
|
||||
private static String createStringRepresentation(List<IToken> nameTokens) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
IToken prev = null;
|
||||
for(IToken t : nameTokens) {
|
||||
if(needSpaceBetween(prev, t))
|
||||
sb.append(' ');
|
||||
sb.append(t.toString());
|
||||
prev = t;
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
private static boolean needSpaceBetween(IToken prev, IToken iter) {
|
||||
// this logic was copied from BasicTokenDuple.createCharArrayRepresentation()
|
||||
if(prev == null)
|
||||
return false;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue