mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
This commit is contained in:
parent
3f2cd224a1
commit
bf8c96a8b1
12 changed files with 109 additions and 7 deletions
|
@ -28,7 +28,6 @@ import org.eclipse.cdt.core.parser.ast.IASTElaboratedTypeSpecifier;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier;
|
import org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTEnumerator;
|
import org.eclipse.cdt.core.parser.ast.IASTEnumerator;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTField;
|
import org.eclipse.cdt.core.parser.ast.IASTField;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTFieldReference;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTFunction;
|
import org.eclipse.cdt.core.parser.ast.IASTFunction;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification;
|
import org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTMethod;
|
import org.eclipse.cdt.core.parser.ast.IASTMethod;
|
||||||
|
@ -1875,4 +1874,21 @@ public class CompleteParseASTTest extends CompleteParseBaseTest
|
||||||
|
|
||||||
IASTFunction f = (IASTFunction) d.next();
|
IASTFunction f = (IASTFunction) d.next();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testBug64271() throws Exception
|
||||||
|
{
|
||||||
|
Writer writer = new StringWriter();
|
||||||
|
writer.write( "typedef int DWORD;\n" ); //$NON-NLS-1$
|
||||||
|
writer.write( "typedef char BYTE;\n"); //$NON-NLS-1$
|
||||||
|
writer.write( "#define MAKEFOURCC(ch0, ch1, ch2, ch3) \\n"); //$NON-NLS-1$
|
||||||
|
writer.write( "((DWORD)(BYTE)(ch0) | ((DWORD)(BYTE)(ch1) << 8) | \\n"); //$NON-NLS-1$
|
||||||
|
writer.write( "((DWORD)(BYTE)(ch2) << 16) | ((DWORD)(BYTE)(ch3) << 24 ))\n"); //$NON-NLS-1$
|
||||||
|
writer.write( "enum e {\n"); //$NON-NLS-1$
|
||||||
|
writer.write( "blah1 = 5,\n"); //$NON-NLS-1$
|
||||||
|
writer.write( "blah2 = MAKEFOURCC('a', 'b', 'c', 'd'),\n"); //$NON-NLS-1$
|
||||||
|
writer.write( "blah3\n"); //$NON-NLS-1$
|
||||||
|
writer.write( "};\n"); //$NON-NLS-1$
|
||||||
|
writer.write( "e mye = blah;\n"); //$NON-NLS-1$
|
||||||
|
parse( writer.toString().toString() );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1117,4 +1117,33 @@ public class CompletionParseTest extends CompletionParseBaseTest {
|
||||||
assertTrue( ((IASTFunction)node.getCompletionScope()).getName().equals( "f" ) ); //$NON-NLS-1$
|
assertTrue( ((IASTFunction)node.getCompletionScope()).getName().equals( "f" ) ); //$NON-NLS-1$
|
||||||
assertNotNull( node.getCompletionContext() );
|
assertNotNull( node.getCompletionContext() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testBug64271() throws Exception
|
||||||
|
{
|
||||||
|
Writer writer = new StringWriter();
|
||||||
|
writer.write( "typedef int DWORD;\n" ); //$NON-NLS-1$
|
||||||
|
writer.write( "typedef char BYTE;\n"); //$NON-NLS-1$
|
||||||
|
writer.write( "#define MAKEFOURCC(ch0, ch1, ch2, ch3) \\n"); //$NON-NLS-1$
|
||||||
|
writer.write( "((DWORD)(BYTE)(ch0) | ((DWORD)(BYTE)(ch1) << 8) | \\n"); //$NON-NLS-1$
|
||||||
|
writer.write( "((DWORD)(BYTE)(ch2) << 16) | ((DWORD)(BYTE)(ch3) << 24 ))\n"); //$NON-NLS-1$
|
||||||
|
writer.write( "enum e {\n"); //$NON-NLS-1$
|
||||||
|
writer.write( "blah1 = 5,\n"); //$NON-NLS-1$
|
||||||
|
writer.write( "blah2 = MAKEFOURCC('a', 'b', 'c', 'd'),\n"); //$NON-NLS-1$
|
||||||
|
writer.write( "blah3\n"); //$NON-NLS-1$
|
||||||
|
writer.write( "};\n"); //$NON-NLS-1$
|
||||||
|
writer.write( "e mye = bl\n"); //$NON-NLS-1$
|
||||||
|
String code = writer.toString();
|
||||||
|
IASTCompletionNode node = parse( code, code.indexOf( "= bl") + 4); //$NON-NLS-1$
|
||||||
|
assertNotNull( node );
|
||||||
|
assertEquals( node.getCompletionKind(), IASTCompletionNode.CompletionKind.SINGLE_NAME_REFERENCE );
|
||||||
|
assertEquals( node.getCompletionPrefix(), "bl"); //$NON-NLS-1$
|
||||||
|
assertNull( node.getCompletionContext() );
|
||||||
|
assertFalse( node.getKeywords().hasNext() );
|
||||||
|
|
||||||
|
LookupKind[] kind = new LookupKind[1];
|
||||||
|
kind[0] = LookupKind.ENUMERATORS;
|
||||||
|
ILookupResult result = node.getCompletionScope().lookup( node.getCompletionPrefix(), kind, null, null );
|
||||||
|
assertNotNull( result );
|
||||||
|
assertEquals( result.getResultsSize(), 3 );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,4 +21,9 @@ import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate;
|
||||||
public interface IASTEnumerationSpecifier extends ISourceElementCallbackDelegate, IASTScopedTypeSpecifier, IASTOffsetableNamedElement {
|
public interface IASTEnumerationSpecifier extends ISourceElementCallbackDelegate, IASTScopedTypeSpecifier, IASTOffsetableNamedElement {
|
||||||
|
|
||||||
public Iterator getEnumerators();
|
public Iterator getEnumerators();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param referenceManager
|
||||||
|
*/
|
||||||
|
public void freeReferences(IReferenceManager referenceManager);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,4 +20,8 @@ public interface IASTEnumerator extends IASTOffsetableNamedElement, IASTNode, IS
|
||||||
|
|
||||||
public IASTEnumerationSpecifier getOwnerEnumerationSpecifier();
|
public IASTEnumerationSpecifier getOwnerEnumerationSpecifier();
|
||||||
public IASTExpression getInitialValue();
|
public IASTExpression getInitialValue();
|
||||||
|
/**
|
||||||
|
* @param referenceManager
|
||||||
|
*/
|
||||||
|
public void freeReferences(IReferenceManager referenceManager);
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,4 +84,5 @@ public class CompleteParser extends Parser {
|
||||||
return ((CompleteParseASTFactory)astFactory).validateCaches();
|
return ((CompleteParseASTFactory)astFactory).validateCaches();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2983,4 +2983,12 @@ public class ExpressionParser implements IExpressionParser, IParserData {
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see java.lang.Object#toString()
|
||||||
|
*/
|
||||||
|
public String toString() {
|
||||||
|
return scanner.toString(); //$NON-NLS-1$
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2533,12 +2533,12 @@ public abstract class Parser extends ExpressionParser implements IParser
|
||||||
consume(IToken.tASSIGN);
|
consume(IToken.tASSIGN);
|
||||||
initialValue = constantExpression(sdw.getScope(), CompletionKind.SINGLE_NAME_REFERENCE, Key.EXPRESSION);
|
initialValue = constantExpression(sdw.getScope(), CompletionKind.SINGLE_NAME_REFERENCE, Key.EXPRESSION);
|
||||||
}
|
}
|
||||||
|
IASTEnumerator enumerator = null;
|
||||||
if (LT(1) == IToken.tRBRACE)
|
if (LT(1) == IToken.tRBRACE)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
IASTEnumerator enumerator = astFactory.addEnumerator(
|
enumerator = astFactory.addEnumerator(
|
||||||
enumeration,
|
enumeration,
|
||||||
enumeratorIdentifier.getImage(),
|
enumeratorIdentifier.getImage(),
|
||||||
enumeratorIdentifier.getOffset(),
|
enumeratorIdentifier.getOffset(),
|
||||||
|
@ -2560,11 +2560,14 @@ public abstract class Parser extends ExpressionParser implements IParser
|
||||||
}
|
}
|
||||||
if (LT(1) != IToken.tCOMMA)
|
if (LT(1) != IToken.tCOMMA)
|
||||||
{
|
{
|
||||||
|
enumeration.freeReferences( astFactory.getReferenceManager() );
|
||||||
|
if( enumerator != null )
|
||||||
|
enumerator.freeReferences( astFactory.getReferenceManager() );
|
||||||
throw backtrack;
|
throw backtrack;
|
||||||
}
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
IASTEnumerator enumerator = astFactory.addEnumerator(
|
enumerator = astFactory.addEnumerator(
|
||||||
enumeration,
|
enumeration,
|
||||||
enumeratorIdentifier.getImage(),
|
enumeratorIdentifier.getImage(),
|
||||||
enumeratorIdentifier.getOffset(),
|
enumeratorIdentifier.getOffset(),
|
||||||
|
@ -3275,4 +3278,5 @@ public abstract class Parser extends ExpressionParser implements IParser
|
||||||
*/
|
*/
|
||||||
protected void handleOffsetableNamedElement(IASTOffsetableNamedElement node ) {
|
protected void handleOffsetableNamedElement(IASTOffsetableNamedElement node ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,6 +72,13 @@ public class ASTEnumerationSpecifier
|
||||||
{
|
{
|
||||||
/* do nothing */
|
/* do nothing */
|
||||||
}
|
}
|
||||||
|
if( enumerators.isEmpty() ) return;
|
||||||
|
for( int i = 0; i < enumerators.size(); ++i )
|
||||||
|
{
|
||||||
|
IASTEnumerator enumerator = (IASTEnumerator) enumerators.get(i);
|
||||||
|
if( enumerator.getInitialValue() != null )
|
||||||
|
enumerator.getInitialValue().acceptElement(requestor, manager );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor)
|
* @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor)
|
||||||
|
@ -176,4 +183,13 @@ public class ASTEnumerationSpecifier
|
||||||
public int getNameLineNumber() {
|
public int getNameLineNumber() {
|
||||||
return offsets.getNameLineNumber();
|
return offsets.getNameLineNumber();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier#freeReferences(org.eclipse.cdt.core.parser.ast.IReferenceManager)
|
||||||
|
*/
|
||||||
|
public void freeReferences(IReferenceManager referenceManager) {
|
||||||
|
if( enumerators.isEmpty() ) return;
|
||||||
|
for( int i = 0; i < enumerators.size(); ++i )
|
||||||
|
((IASTEnumerator) enumerators.get(i)).freeReferences(referenceManager);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -159,4 +159,11 @@ public class ASTEnumerator extends ASTSymbol implements IASTEnumerator
|
||||||
public int getNameLineNumber() {
|
public int getNameLineNumber() {
|
||||||
return offsets.getNameLineNumber();
|
return offsets.getNameLineNumber();
|
||||||
}
|
}
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.parser.ast.IASTEnumerator#freeReferences(org.eclipse.cdt.core.parser.ast.IReferenceManager)
|
||||||
|
*/
|
||||||
|
public void freeReferences(IReferenceManager referenceManager) {
|
||||||
|
if( initialValue != null )
|
||||||
|
initialValue.freeReferences(referenceManager);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3412,7 +3412,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
|
||||||
if( result.getType() == TypeInfo.t_type )
|
if( result.getType() == TypeInfo.t_type )
|
||||||
{
|
{
|
||||||
ISymbol typeSymbol = lookupQualifiedName( scopeToSymbol(scope), typeId.getTokenDuple(), refs, true );
|
ISymbol typeSymbol = lookupQualifiedName( scopeToSymbol(scope), typeId.getTokenDuple(), refs, true );
|
||||||
if( typeSymbol == null || typeSymbol.getType() == TypeInfo.t_type )
|
if( typeSymbol == null /*|| typeSymbol.getType() == TypeInfo.t_type*/ )
|
||||||
{
|
{
|
||||||
freeReferences( refs );
|
freeReferences( refs );
|
||||||
handleProblem( scope, IProblem.SEMANTIC_INVALID_TYPE, id.getTypeOrClassName() );
|
handleProblem( scope, IProblem.SEMANTIC_INVALID_TYPE, id.getTypeOrClassName() );
|
||||||
|
|
|
@ -168,4 +168,10 @@ public class ASTEnumerationSpecifier extends ASTScopedTypeSpecifier
|
||||||
public int getNameLineNumber() {
|
public int getNameLineNumber() {
|
||||||
return offsets.getNameLineNumber();
|
return offsets.getNameLineNumber();
|
||||||
}
|
}
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier#freeReferences(org.eclipse.cdt.core.parser.ast.IReferenceManager)
|
||||||
|
*/
|
||||||
|
public void freeReferences(IReferenceManager referenceManager) {
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -163,4 +163,10 @@ public class ASTEnumerator extends ASTNode
|
||||||
public int getNameLineNumber() {
|
public int getNameLineNumber() {
|
||||||
return offsets.getNameLineNumber();
|
return offsets.getNameLineNumber();
|
||||||
}
|
}
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.parser.ast.IASTEnumerator#freeReferences(org.eclipse.cdt.core.parser.ast.IReferenceManager)
|
||||||
|
*/
|
||||||
|
public void freeReferences(IReferenceManager referenceManager) {
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue