1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Patch for John Camelon:

CORE
		 Fixed Bug 36243 DomBuilder Offsetable List
This commit is contained in:
Doug Schaefer 2003-04-11 21:14:34 +00:00
parent 45705e3e38
commit 080e040924
3 changed files with 110 additions and 12 deletions

View file

@ -2,8 +2,10 @@ package org.eclipse.cdt.internal.core.dom;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.NoSuchElementException;
/**
@ -13,11 +15,9 @@ public class TranslationUnit implements IScope {
private List declarations = new LinkedList();
private List macros = new ArrayList();
private List inclusions = new ArrayList();
private List offsetables = new ArrayList();
public void addDeclaration(Declaration declaration) {
declarations.add(declaration);
offsetables.add(declaration);
}
public List getDeclarations() {
@ -40,21 +40,117 @@ public class TranslationUnit implements IScope {
public void addMacro(Macro macro) {
macros.add(macro);
offsetables.add(macro);
}
public void addInclusion(Inclusion inclusion) {
inclusions.add(inclusion);
offsetables.add(inclusion);
}
/**
* Returns the offsetables.
* @return List
public Iterator iterateOffsetableElements()
{
return new OffsetableIterator();
}
public class OffsetableIterator implements Iterator
{
private final Iterator declarationIter;
private final Iterator inclusionIter;
private final Iterator macroIter;
private IOffsetable currentMacro = null, currentInclusion= null, currentDeclaration= null;
public OffsetableIterator()
{
declarationIter = getDeclarations().iterator();
inclusionIter = getInclusions().iterator();
macroIter = getMacros().iterator();
updateInclusionIterator();
updateDeclarationIterator();
updateMacroIterator();
}
private Object updateDeclarationIterator()
{
Object offsetable = currentDeclaration;
currentDeclaration = ( declarationIter.hasNext() ) ? (IOffsetable)declarationIter.next() : null;
return offsetable;
}
private Object updateMacroIterator()
{
Object offsetable = currentMacro;
currentMacro = ( macroIter.hasNext() ) ? (IOffsetable)macroIter.next() : null;
return offsetable;
}
private Object updateInclusionIterator()
{
Object offsetable = currentInclusion;
currentInclusion = ( inclusionIter.hasNext() ) ? (IOffsetable)inclusionIter.next() : null;
return offsetable;
}
/* (non-Javadoc)
* @see java.util.Iterator#hasNext()
*/
public List getOffsetables() {
return Collections.unmodifiableList( offsetables );
public boolean hasNext() {
return (( currentMacro == null && currentInclusion == null && currentDeclaration == null ) ?
false : true);
}
/* (non-Javadoc)
* @see java.util.Iterator#next()
*/
public Object next() {
// case 1: all are null
if( ! hasNext() )
throw new NoSuchElementException();
// case 2: two of three are null
if( currentMacro == null && currentInclusion == null )
return updateDeclarationIterator();
if( currentDeclaration == null && currentInclusion == null )
return updateMacroIterator();
if( currentMacro == null && currentDeclaration == null )
return updateInclusionIterator();
// case 3: 1 is null
if( currentMacro == null )
if( currentDeclaration.getStartingOffset() < currentInclusion.getStartingOffset() )
return updateDeclarationIterator();
else
return updateInclusionIterator();
if( currentInclusion == null )
if( currentDeclaration.getStartingOffset() < currentMacro.getStartingOffset() )
return updateDeclarationIterator();
else
return updateMacroIterator();
if( currentDeclaration == null )
if( currentInclusion.getStartingOffset() < currentMacro.getStartingOffset() )
return updateInclusionIterator();
else
return updateMacroIterator();
// case 4: none are null
if( currentInclusion.getStartingOffset() < currentMacro.getStartingOffset() &&
currentInclusion.getStartingOffset() < currentDeclaration.getStartingOffset() )
return updateInclusionIterator();
if( currentMacro.getStartingOffset() < currentInclusion.getStartingOffset() &&
currentMacro.getStartingOffset() < currentDeclaration.getStartingOffset() )
return updateMacroIterator();
// only remaining case
return updateDeclarationIterator();
}
/* (non-Javadoc)
* @see java.util.Iterator#remove()
*/
public void remove() {
throw new UnsupportedOperationException( "OffsetableIterator is a const iterator");
}
}
}

View file

@ -1,3 +1,6 @@
2003-04-11 John Camelon
Fixed Bug 36243 DomBuilder Offsetable List
2003-04-10 John Camelon
Fixed Bug36237 Parser fails on casts in ctor initializer.
Added AccessSpecifier to TemplateDeclaration.

View file

@ -65,8 +65,7 @@ public class CModelBuilder {
}
protected void generateModelElements(TranslationUnit tu){
List offsetables = tu.getOffsetables();
Iterator i = offsetables.iterator();
Iterator i = tu.iterateOffsetableElements();
while (i.hasNext()){
IOffsetable offsetable = (IOffsetable)i.next();
if(offsetable instanceof Inclusion){