mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Further Scanner2 work and improvements.
This commit is contained in:
parent
9b08f32b17
commit
d134c5e5d3
4 changed files with 25 additions and 8 deletions
|
@ -12,6 +12,7 @@ package org.eclipse.cdt.core.parser.tests;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.parser.ParserFactory;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration;
|
import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
|
import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTExpression;
|
import org.eclipse.cdt.core.parser.ast.IASTExpression;
|
||||||
|
@ -247,8 +248,11 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
|
||||||
|
|
||||||
i = getDeclarations( test );
|
i = getDeclarations( test );
|
||||||
IASTVariable someInt = (IASTVariable) i.next();
|
IASTVariable someInt = (IASTVariable) i.next();
|
||||||
IASTExpression exp = someInt.getInitializerClause().getAssigmentExpression();
|
IASTExpression exp = someInt.getInitializerClause().getAssigmentExpression();
|
||||||
assertEquals( exp.toString(), "foo(int(3), short(4), double(3.0), float(4.0), char('a'), wchar_t('a'), signed(2), unsigned(3), bool(false), long(3))" ); //$NON-NLS-1$
|
if( ParserFactory.USE_NEW_SCANNER )
|
||||||
|
assertEquals( exp.toString(), "foo(int(3), short(4), double(3.0), float(4.0), char('a'), wchar_t('a'), signed(2), unsigned(3), bool(false), long(3L))" ); //$NON-NLS-1$
|
||||||
|
else
|
||||||
|
assertEquals( exp.toString(), "foo(int(3), short(4), double(3.0), float(4.0), char('a'), wchar_t('a'), signed(2), unsigned(3), bool(false), long(3))" ); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
|
||||||
// Kind POSTFIX_TYPENAME_IDENTIFIER
|
// Kind POSTFIX_TYPENAME_IDENTIFIER
|
||||||
|
|
|
@ -337,14 +337,24 @@ public class ASTUtil {
|
||||||
return expression.getLiteralString();
|
return expression.getLiteralString();
|
||||||
|
|
||||||
StringBuffer buffer = new StringBuffer();
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
boolean quoted = false;
|
||||||
|
String literalString = expression.getLiteralString();
|
||||||
if( kind == Kind.PRIMARY_CHAR_LITERAL ){
|
if( kind == Kind.PRIMARY_CHAR_LITERAL ){
|
||||||
buffer.append( '\'' );
|
quoted = ( literalString.charAt(0) == literalString.charAt(literalString.length() - 1 ) &&
|
||||||
buffer.append( expression.getLiteralString() );
|
literalString.charAt(0) == '\'' );
|
||||||
buffer.append( '\'' );
|
if( !quoted )
|
||||||
|
buffer.append( '\'' );
|
||||||
|
buffer.append( literalString );
|
||||||
|
if( !quoted )
|
||||||
|
buffer.append( '\'' );
|
||||||
} else if( kind == Kind.PRIMARY_STRING_LITERAL ) {
|
} else if( kind == Kind.PRIMARY_STRING_LITERAL ) {
|
||||||
buffer.append( '"' );
|
quoted = ( literalString.charAt(0) == literalString.charAt(literalString.length() - 1 ) &&
|
||||||
|
literalString.charAt(0) == '\"' );
|
||||||
|
if( !quoted )
|
||||||
|
buffer.append( '"' );
|
||||||
buffer.append( expression.getLiteralString() );
|
buffer.append( expression.getLiteralString() );
|
||||||
buffer.append( '"' );
|
if( !quoted )
|
||||||
|
buffer.append( '"' );
|
||||||
}
|
}
|
||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1320,7 +1320,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
|
||||||
parameters = expResultList.getResultList();
|
parameters = expResultList.getResultList();
|
||||||
|
|
||||||
}else {
|
}else {
|
||||||
parameters = new ArrayList();
|
parameters = new ArrayList(1);
|
||||||
parameters.add(expResult.getResult());
|
parameters.add(expResult.getResult());
|
||||||
}
|
}
|
||||||
if( functionScope.equals( startingScope ) )
|
if( functionScope.equals( startingScope ) )
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
***********************************************************************/
|
***********************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.parser.token;
|
package org.eclipse.cdt.internal.core.parser.token;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.parser.ParserFactory;
|
||||||
import org.eclipse.cdt.internal.core.parser.scanner.ContextStack;
|
import org.eclipse.cdt.internal.core.parser.scanner.ContextStack;
|
||||||
import org.eclipse.cdt.internal.core.parser.scanner.IScannerContext;
|
import org.eclipse.cdt.internal.core.parser.scanner.IScannerContext;
|
||||||
|
|
||||||
|
@ -76,6 +77,8 @@ public class ImagedToken extends SimpleToken {
|
||||||
public int getLength() {
|
public int getLength() {
|
||||||
if( getCharImage() == null )
|
if( getCharImage() == null )
|
||||||
return 0;
|
return 0;
|
||||||
|
if( ParserFactory.USE_NEW_SCANNER )
|
||||||
|
return getCharImage().length;
|
||||||
switch( getType() )
|
switch( getType() )
|
||||||
{
|
{
|
||||||
case tSTRING:
|
case tSTRING:
|
||||||
|
|
Loading…
Add table
Reference in a new issue