1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-30 04:15:35 +02:00
This commit is contained in:
John Camelon 2004-06-10 18:51:47 +00:00
parent 47dd3dc302
commit b7caa59093
7 changed files with 36 additions and 18 deletions

View file

@ -1196,4 +1196,23 @@ public class CompletionParseTest extends CompletionParseBaseTest {
} }
return false; return false;
} }
public void testBug66543() throws Exception
{
Writer writer = new StringWriter();
writer.write( "struct packet { int a; int b; };\n" ); //$NON-NLS-1$
writer.write( "struct packet buffer[5];\n" ); //$NON-NLS-1$
writer.write( "int main(int argc, char **argv) {\n" ); //$NON-NLS-1$
writer.write( " buffer[2]." ); //$NON-NLS-1$
String code = writer.toString();
IASTCompletionNode node = parse( code, code.indexOf( "[2].") + 4 ); //$NON-NLS-1$
assertNotNull( node );
assertNotNull( node.getCompletionContext() );
IASTNode.LookupKind [] kinds = new LookupKind[ 1 ];
kinds[0] = LookupKind.FIELDS;
ILookupResult result = node.getCompletionScope().lookup( node.getCompletionPrefix(), kinds, node.getCompletionContext(), node.getFunctionParameters() );
assertNotNull( result );
assertEquals( result.getResultsSize(), 2 );
}
} }

View file

@ -82,8 +82,7 @@ public class ASTCodeScope extends ASTScope implements IASTCodeScope {
{ {
if(declarations != null) if(declarations != null)
return declarations.iterator(); return declarations.iterator();
else return super.getDeclarations();
return super.getDeclarations();
} }
public void addDeclaration(IASTDeclaration declaration) public void addDeclaration(IASTDeclaration declaration)

View file

@ -330,8 +330,7 @@ public class ASTFunction extends ASTScope implements IASTFunction
{ {
if(declarations != null) if(declarations != null)
return declarations.iterator(); return declarations.iterator();
else return super.getDeclarations();
return super.getDeclarations();
} }
public void addDeclaration(IASTDeclaration declaration) public void addDeclaration(IASTDeclaration declaration)

View file

@ -1636,6 +1636,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
if ((info != null)) if ((info != null))
{ {
info.addOperatorExpression( TypeInfo.OperatorExpression.subscript ); info.addOperatorExpression( TypeInfo.OperatorExpression.subscript );
info = info.getFinalType( null );
}else { }else {
handleProblem( scope, IProblem.SEMANTIC_MALFORMED_EXPRESSION, null ); handleProblem( scope, IProblem.SEMANTIC_MALFORMED_EXPRESSION, null );
} }

View file

@ -19,7 +19,6 @@ import java.util.List;
import org.eclipse.cdt.core.parser.GCCKeywords; import org.eclipse.cdt.core.parser.GCCKeywords;
import org.eclipse.cdt.core.parser.ITokenDuple; import org.eclipse.cdt.core.parser.ITokenDuple;
import org.eclipse.cdt.core.parser.ParserMode; import org.eclipse.cdt.core.parser.ParserMode;
import org.eclipse.cdt.core.parser.ast.ASTExpressionEvaluationException;
import org.eclipse.cdt.core.parser.ast.ASTUtil; import org.eclipse.cdt.core.parser.ast.ASTUtil;
import org.eclipse.cdt.core.parser.ast.IASTExpression; import org.eclipse.cdt.core.parser.ast.IASTExpression;
import org.eclipse.cdt.core.parser.ast.IASTScope; import org.eclipse.cdt.core.parser.ast.IASTScope;
@ -29,7 +28,6 @@ import org.eclipse.cdt.core.parser.ast.IASTExpression.Kind;
import org.eclipse.cdt.core.parser.ast.gcc.IASTGCCExpression; import org.eclipse.cdt.core.parser.ast.gcc.IASTGCCExpression;
import org.eclipse.cdt.internal.core.parser.ast.GCCASTExtension; import org.eclipse.cdt.internal.core.parser.ast.GCCASTExtension;
import org.eclipse.cdt.internal.core.parser.ast.complete.ASTBinaryExpression; import org.eclipse.cdt.internal.core.parser.ast.complete.ASTBinaryExpression;
import org.eclipse.cdt.internal.core.parser.ast.complete.ASTIdExpression;
import org.eclipse.cdt.internal.core.parser.ast.complete.ASTTypeIdExpression; import org.eclipse.cdt.internal.core.parser.ast.complete.ASTTypeIdExpression;
import org.eclipse.cdt.internal.core.parser.ast.complete.ASTUnaryExpression; import org.eclipse.cdt.internal.core.parser.ast.complete.ASTUnaryExpression;
import org.eclipse.cdt.internal.core.parser.ast.complete.ExpressionFactory; import org.eclipse.cdt.internal.core.parser.ast.complete.ExpressionFactory;
@ -59,10 +57,10 @@ public class GCCASTCompleteExtension extends GCCASTExtension {
{ {
return new ASTBinaryExpression( kind, references, lhs, rhs ){ return new ASTBinaryExpression( kind, references, lhs, rhs ){
public String toString(){ public String toString(){
IASTExpression.Kind kind = getExpressionKind(); IASTExpression.Kind k = getExpressionKind();
StringBuffer buffer = new StringBuffer(); StringBuffer buffer = new StringBuffer();
buffer.append( ASTUtil.getExpressionString( getLHSExpression() ) ); buffer.append( ASTUtil.getExpressionString( getLHSExpression() ) );
if( kind == IASTGCCExpression.Kind.RELATIONAL_MAX ) if( k == IASTGCCExpression.Kind.RELATIONAL_MAX )
buffer.append( " >? " ); //$NON-NLS-1$ buffer.append( " >? " ); //$NON-NLS-1$
else else
buffer.append( " <? " ); //$NON-NLS-1$ buffer.append( " <? " ); //$NON-NLS-1$
@ -77,9 +75,9 @@ public class GCCASTCompleteExtension extends GCCASTExtension {
{ {
return new ASTUnaryExpression( kind, references, lhs ){ return new ASTUnaryExpression( kind, references, lhs ){
public String toString(){ public String toString(){
IASTExpression.Kind kind = getExpressionKind(); IASTExpression.Kind k = getExpressionKind();
StringBuffer buffer = new StringBuffer(); StringBuffer buffer = new StringBuffer();
if( kind == IASTGCCExpression.Kind.UNARY_ALIGNOF_UNARYEXPRESSION ) if( k == IASTGCCExpression.Kind.UNARY_ALIGNOF_UNARYEXPRESSION )
buffer.append( GCCKeywords.__ALIGNOF__ ); buffer.append( GCCKeywords.__ALIGNOF__ );
else else
buffer.append( GCCKeywords.TYPEOF ); buffer.append( GCCKeywords.TYPEOF );
@ -95,9 +93,9 @@ public class GCCASTCompleteExtension extends GCCASTExtension {
{ {
return new ASTTypeIdExpression( kind, references, typeId ){ return new ASTTypeIdExpression( kind, references, typeId ){
public String toString(){ public String toString(){
IASTExpression.Kind kind = getExpressionKind(); IASTExpression.Kind k = getExpressionKind();
StringBuffer buffer = new StringBuffer(); StringBuffer buffer = new StringBuffer();
if( kind == IASTGCCExpression.Kind.UNARY_ALIGNOF_TYPEID ) if( k == IASTGCCExpression.Kind.UNARY_ALIGNOF_TYPEID )
buffer.append( GCCKeywords.__ALIGNOF__ ); buffer.append( GCCKeywords.__ALIGNOF__ );
else else
buffer.append( GCCKeywords.TYPEOF ); buffer.append( GCCKeywords.TYPEOF );

View file

@ -75,10 +75,10 @@ public class GCCASTExpressionExtension extends GCCASTExtension {
{ {
return new ASTBinaryExpression( kind, lhs, rhs ){ return new ASTBinaryExpression( kind, lhs, rhs ){
public String toString(){ public String toString(){
IASTExpression.Kind kind = getExpressionKind(); IASTExpression.Kind k = getExpressionKind();
StringBuffer buffer = new StringBuffer(); StringBuffer buffer = new StringBuffer();
buffer.append( ASTUtil.getExpressionString( getLHSExpression() ) ); buffer.append( ASTUtil.getExpressionString( getLHSExpression() ) );
if( kind == IASTGCCExpression.Kind.RELATIONAL_MAX ) if( k == IASTGCCExpression.Kind.RELATIONAL_MAX )
buffer.append( " >? " ); //$NON-NLS-1$ buffer.append( " >? " ); //$NON-NLS-1$
else else
buffer.append( " <? " ); //$NON-NLS-1$ buffer.append( " <? " ); //$NON-NLS-1$
@ -93,9 +93,9 @@ public class GCCASTExpressionExtension extends GCCASTExtension {
{ {
return new ASTUnaryExpression( kind, lhs ){ return new ASTUnaryExpression( kind, lhs ){
public String toString(){ public String toString(){
IASTExpression.Kind kind = getExpressionKind(); IASTExpression.Kind k = getExpressionKind();
StringBuffer buffer = new StringBuffer(); StringBuffer buffer = new StringBuffer();
if( kind == IASTGCCExpression.Kind.UNARY_ALIGNOF_UNARYEXPRESSION ) if( k == IASTGCCExpression.Kind.UNARY_ALIGNOF_UNARYEXPRESSION )
buffer.append( GCCKeywords.__ALIGNOF__ ); buffer.append( GCCKeywords.__ALIGNOF__ );
else else
buffer.append( GCCKeywords.TYPEOF ); buffer.append( GCCKeywords.TYPEOF );
@ -111,9 +111,9 @@ public class GCCASTExpressionExtension extends GCCASTExtension {
{ {
return new ASTTypeIdExpression( kind, typeId ){ return new ASTTypeIdExpression( kind, typeId ){
public String toString(){ public String toString(){
IASTExpression.Kind kind = getExpressionKind(); IASTExpression.Kind k = getExpressionKind();
StringBuffer buffer = new StringBuffer(); StringBuffer buffer = new StringBuffer();
if( kind == IASTGCCExpression.Kind.UNARY_ALIGNOF_TYPEID ) if( k == IASTGCCExpression.Kind.UNARY_ALIGNOF_TYPEID )
buffer.append( GCCKeywords.__ALIGNOF__ ); buffer.append( GCCKeywords.__ALIGNOF__ );
else else
buffer.append( GCCKeywords.TYPEOF ); buffer.append( GCCKeywords.TYPEOF );

View file

@ -2137,6 +2137,8 @@ public class ParserSymbolTable {
returnInfo.copy( topInfo ); returnInfo.copy( topInfo );
} else } else
returnInfo = new TypeInfo( topInfo ); returnInfo = new TypeInfo( topInfo );
returnInfo.applyOperatorExpressions( topInfo.getOperatorExpressions() );
returnInfo.getOperatorExpressions().clear();
} }
return returnInfo; return returnInfo;