mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
This commit is contained in:
parent
4c8e461e23
commit
809934b921
7 changed files with 87 additions and 8 deletions
|
@ -26,6 +26,7 @@ import org.eclipse.cdt.core.parser.ParserFactoryError;
|
|||
import org.eclipse.cdt.core.parser.ParserMode;
|
||||
import org.eclipse.cdt.core.parser.ScannerException;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTInclusion;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTMacro;
|
||||
import org.eclipse.cdt.internal.core.parser.token.SimpleToken;
|
||||
|
||||
/**
|
||||
|
@ -1542,4 +1543,13 @@ public class ScannerTestCase extends BaseScannerTest
|
|||
validateToken( IGCCToken.tMAX );
|
||||
validateEOF();
|
||||
}
|
||||
|
||||
public void testBug59768() throws Exception
|
||||
{
|
||||
initializeScanner( "#define A A\nA");
|
||||
validateIdentifier( "A");
|
||||
validateEOF();
|
||||
IMacroDescriptor d = scanner.getDefinition( "A");
|
||||
assertTrue( d.isCircular() );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,4 +58,9 @@ public interface IMacroDescriptor {
|
|||
|
||||
// similar to equals() but according to the C99 & C++98
|
||||
public boolean compatible(IMacroDescriptor descriptor);
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public boolean isCircular();
|
||||
}
|
|
@ -180,4 +180,10 @@ public class ASTMacro implements IASTMacro {
|
|||
public int getNameLineNumber() {
|
||||
return nameLineNumber;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.IMacroDescriptor#isCircular()
|
||||
*/
|
||||
public boolean isCircular() {
|
||||
return innerMacro.isCircular();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -82,5 +82,11 @@ public class DynamicMacroDescriptor implements IMacroDescriptor {
|
|||
if( !name.equals( descriptor.getName() )) return false;
|
||||
return true;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.IMacroDescriptor#isCircular()
|
||||
*/
|
||||
public boolean isCircular() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -38,7 +38,8 @@ public class FunctionMacroDescriptor implements IMacroDescriptor {
|
|||
private String name;
|
||||
private List identifierParameters;
|
||||
private List tokenizedExpansion;
|
||||
private String expansionSignature;
|
||||
private String expansionSignature;
|
||||
private Boolean isCircular = null;
|
||||
/**
|
||||
* Returns the identifiers.
|
||||
* @return List
|
||||
|
@ -147,4 +148,27 @@ public class FunctionMacroDescriptor implements IMacroDescriptor {
|
|||
return expansionSignature;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.IMacroDescriptor#isCircular()
|
||||
*/
|
||||
public boolean isCircular() {
|
||||
if( isCircular == null )
|
||||
isCircular = new Boolean( checkIsCircular() );
|
||||
return isCircular.booleanValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
protected boolean checkIsCircular() {
|
||||
Iterator i = getTokenizedExpansion().iterator();
|
||||
while( i.hasNext() )
|
||||
{
|
||||
IToken t = (IToken) i.next();
|
||||
if( t.getType() == IToken.tIDENTIFIER && t.getImage().equals(getName()))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
package org.eclipse.cdt.internal.core.parser.scanner;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.parser.IMacroDescriptor;
|
||||
|
@ -25,6 +26,8 @@ public class ObjectMacroDescriptor implements IMacroDescriptor {
|
|||
private final String expansionSignature;
|
||||
private final String name;
|
||||
private final IToken token;
|
||||
private Boolean isCircular = null;
|
||||
private List tokenizedExpansion = null;
|
||||
|
||||
public ObjectMacroDescriptor( String name, String expansionSignature )
|
||||
{
|
||||
|
@ -58,9 +61,13 @@ public class ObjectMacroDescriptor implements IMacroDescriptor {
|
|||
* @see org.eclipse.cdt.core.parser.IMacroDescriptor#getTokenizedExpansion()
|
||||
*/
|
||||
public List getTokenizedExpansion() {
|
||||
ArrayList x = new ArrayList();
|
||||
x.add(token);
|
||||
return x;
|
||||
if( token == null ) return EMPTY_LIST;
|
||||
if( tokenizedExpansion == null )
|
||||
{
|
||||
tokenizedExpansion = new ArrayList(1);
|
||||
tokenizedExpansion.add(token);
|
||||
}
|
||||
return tokenizedExpansion;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -105,4 +112,26 @@ public class ObjectMacroDescriptor implements IMacroDescriptor {
|
|||
return expansionSignature;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.IMacroDescriptor#isCircular()
|
||||
*/
|
||||
public boolean isCircular() {
|
||||
if( isCircular == null )
|
||||
isCircular = new Boolean( checkIsCircular() );
|
||||
return isCircular.booleanValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
protected boolean checkIsCircular() {
|
||||
Iterator i = getTokenizedExpansion().iterator();
|
||||
while( i.hasNext() )
|
||||
{
|
||||
IToken t = (IToken) i.next();
|
||||
if( t.getType() == IToken.tIDENTIFIER && t.getImage().equals(getName()))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -144,6 +144,7 @@ public class Scanner implements IScanner {
|
|||
Object value = m.get( symbolName );
|
||||
if( value instanceof String )
|
||||
{
|
||||
//TODO add in check here for '(' and ')'
|
||||
addDefinition( symbolName, scannerExtension.initializeMacroValue(scannerData, (String) value));
|
||||
TraceUtil.outputTrace(log, "\t\tNAME = ", symbolName, " VALUE = ", value.toString() ); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
++numberOfSymbolsLogged;
|
||||
|
@ -327,9 +328,7 @@ public class Scanner implements IScanner {
|
|||
}
|
||||
|
||||
public void addDefinition(String key, String value) {
|
||||
addDefinition(key,
|
||||
new ObjectMacroDescriptor( key,
|
||||
value ));
|
||||
addDefinition(key, new ObjectMacroDescriptor( key, value ));
|
||||
}
|
||||
|
||||
public final IMacroDescriptor getDefinition(String key) {
|
||||
|
@ -1520,7 +1519,7 @@ public class Scanner implements IScanner {
|
|||
|
||||
IMacroDescriptor mapping = getDefinition(ident);
|
||||
|
||||
if (mapping != null && !isLimitReached())
|
||||
if (mapping != null && !isLimitReached() && !mapping.isCircular() )
|
||||
if( scannerData.getContextStack().shouldExpandDefinition( ident ) ) {
|
||||
expandDefinition(ident, mapping, baseOffset);
|
||||
return null;
|
||||
|
|
Loading…
Add table
Reference in a new issue