1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-09 18:56:02 +02:00

Further DOM/AST fixes.

This commit is contained in:
John Camelon 2005-02-02 18:30:19 +00:00
parent c85f211e0e
commit e269c537e6
7 changed files with 39 additions and 10 deletions

View file

@ -28,7 +28,6 @@ import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTIdExpression; import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTProblem;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression; import org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression;
import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression; import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
@ -122,13 +121,13 @@ public class AST2BaseTest extends TestCase {
if( lang == ParserLanguage.C && expectNoProblems ) if( lang == ParserLanguage.C && expectNoProblems )
{ {
IASTProblem [] problems = CVisitor.getProblems(tu); assertEquals( CVisitor.getProblems(tu).length, 0 );
assertEquals( problems.length, 0 ); assertEquals( tu.getPreprocesorProblems().length, 0 );
} }
else if ( lang == ParserLanguage.CPP && expectNoProblems ) else if ( lang == ParserLanguage.CPP && expectNoProblems )
{ {
IASTProblem [] problems = CPPVisitor.getProblems(tu); assertEquals( CPPVisitor.getProblems(tu).length, 0 );
assertEquals( problems.length, 0 ); assertEquals( tu.getPreprocesorProblems().length, 0 );
} }
return tu; return tu;

View file

@ -2619,4 +2619,17 @@ public class AST2Tests extends AST2BaseTest {
assertInstances( col, e, 2 ); assertInstances( col, e, 2 );
} }
public void testBug84176() throws Exception {
StringBuffer buffer = new StringBuffer( "// example from: C99 6.5.2.5-16\n" ); //$NON-NLS-1$
buffer.append( "struct s { int i; };\n"); //$NON-NLS-1$
buffer.append("void f (void)\n"); //$NON-NLS-1$
buffer.append("{\n"); //$NON-NLS-1$
buffer.append(" struct s *p = 0, *q;\n"); //$NON-NLS-1$
buffer.append("int j = 0;\n"); //$NON-NLS-1$
buffer.append("q = p;\n"); //$NON-NLS-1$
buffer.append("p = &((struct s){ j++ }); \n"); //$NON-NLS-1$
buffer.append("}\n"); //$NON-NLS-1$
parse( buffer.toString(), ParserLanguage.C );
}
} }

View file

@ -32,16 +32,19 @@ public abstract class ASTNode implements IASTNode {
public void setOffset( int offset ) public void setOffset( int offset )
{ {
this.offset = offset; this.offset = offset;
this.locations = null;
} }
public void setLength( int length ) public void setLength( int length )
{ {
this.length = length; this.length = length;
this.locations = null;
} }
public void setOffsetAndLength(int offset, int length) { public void setOffsetAndLength(int offset, int length) {
this.offset = offset; this.offset = offset;
this.length = length; this.length = length;
this.locations = null;
} }
public void setOffsetAndLength( ASTNode node ) public void setOffsetAndLength( ASTNode node )
@ -49,12 +52,15 @@ public abstract class ASTNode implements IASTNode {
setOffsetAndLength( node.getOffset(), node.getLength() ); setOffsetAndLength( node.getOffset(), node.getLength() );
} }
private IASTNodeLocation [] locations = null;
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTNode#getNodeLocations() * @see org.eclipse.cdt.core.dom.ast.IASTNode#getNodeLocations()
*/ */
public IASTNodeLocation[] getNodeLocations() { public IASTNodeLocation[] getNodeLocations() {
if( locations != null ) return locations;
if( length == 0 ) return EMPTY_LOCATION_ARRAY; if( length == 0 ) return EMPTY_LOCATION_ARRAY;
return getTranslationUnit().getLocationInfo( offset, length ); locations = getTranslationUnit().getLocationInfo( offset, length );
return locations;
} }
/* (non-Javadoc) /* (non-Javadoc)

View file

@ -34,6 +34,7 @@ import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTExpressionList; import org.eclipse.cdt.core.dom.ast.IASTExpressionList;
import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement; import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement;
import org.eclipse.cdt.core.dom.ast.IASTFieldDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTFieldReference; import org.eclipse.cdt.core.dom.ast.IASTFieldReference;
import org.eclipse.cdt.core.dom.ast.IASTForStatement; import org.eclipse.cdt.core.dom.ast.IASTForStatement;
import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression; import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
@ -1385,6 +1386,9 @@ public class CVisitor {
if( mods[i].getConstantExpression() != null && if( mods[i].getConstantExpression() != null &&
!visitExpression( mods[i].getConstantExpression(), action ) ) return false; !visitExpression( mods[i].getConstantExpression(), action ) ) return false;
} }
else if( declarator instanceof IASTFieldDeclarator )
if( ! visitExpression( ((IASTFieldDeclarator) declarator).getBitFieldSize(), action ) ) return false;
return true; return true;
} }

View file

@ -1938,6 +1938,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
} else if (bitField != null) { } else if (bitField != null) {
IASTFieldDeclarator fl = createFieldDeclarator(); IASTFieldDeclarator fl = createFieldDeclarator();
fl.setBitFieldSize(bitField); fl.setBitFieldSize(bitField);
bitField.setParent( fl );
bitField.setPropertyInParent( IASTFieldDeclarator.FIELD_SIZE );
d = fl; d = fl;
} else { } else {
d = createDeclarator(); d = createDeclarator();

View file

@ -36,6 +36,7 @@ import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTExpressionList; import org.eclipse.cdt.core.dom.ast.IASTExpressionList;
import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement; import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement;
import org.eclipse.cdt.core.dom.ast.IASTFieldDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTFieldReference; import org.eclipse.cdt.core.dom.ast.IASTFieldReference;
import org.eclipse.cdt.core.dom.ast.IASTForStatement; import org.eclipse.cdt.core.dom.ast.IASTForStatement;
import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression; import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
@ -938,6 +939,9 @@ public class CPPVisitor {
if( declarator.getInitializer() != null ) if( declarator.getInitializer() != null )
if( !visitInitializer( declarator.getInitializer(), action ) ) return false; if( !visitInitializer( declarator.getInitializer(), action ) ) return false;
if( declarator instanceof IASTFieldDeclarator )
if( ! visitExpression( ((IASTFieldDeclarator) declarator).getBitFieldSize(), action ) ) return false;
return true; return true;
} }

View file

@ -19,6 +19,7 @@ import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTInitializer; import org.eclipse.cdt.core.dom.ast.IASTInitializer;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration; import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTPointerOperator; import org.eclipse.cdt.core.dom.ast.IASTPointerOperator;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement; import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
@ -30,7 +31,6 @@ import org.eclipse.cdt.core.dom.ast.IASTTypeId;
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator; import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
import org.eclipse.cdt.core.dom.ast.c.ICASTDesignatedInitializer; import org.eclipse.cdt.core.dom.ast.c.ICASTDesignatedInitializer;
import org.eclipse.cdt.core.dom.ast.c.ICASTDesignator; import org.eclipse.cdt.core.dom.ast.c.ICASTDesignator;
import org.eclipse.cdt.core.parser.ast.IASTDesignator;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction; import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction;
@ -59,9 +59,10 @@ public class CPopulateASTViewAction extends CBaseVisitorAction implements IPopul
} }
private void addRoot(IASTNode node) { private void addRoot(IASTNode node) {
if (!(node.getNodeLocations().length > 0 && IASTNodeLocation[] nodeLocations = node.getNodeLocations();
node.getNodeLocations()[0].getNodeOffset() >= 0 && if (!(nodeLocations.length > 0 &&
node.getNodeLocations()[0].getNodeLength() > 0)) nodeLocations[0].getNodeOffset() >= 0 &&
nodeLocations[0].getNodeLength() > 0))
return; return;
TreeParent parent = root.findParentOfNode(node); TreeParent parent = root.findParentOfNode(node);