mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 14:42:11 +02:00
Fix for Bug 173637 - [Scanner] Function macro location wrong if name is substituted by another macro
This commit is contained in:
parent
55426596b4
commit
88be86e730
3 changed files with 59 additions and 6 deletions
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004, 2006 IBM Corporation and others.
|
||||
* Copyright (c) 2004, 2007 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -8,12 +8,15 @@
|
|||
* Contributors:
|
||||
* IBM - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
* Anton Leherbauer (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.parser.tests.ast2;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTInitializerExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTMacroExpansion;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
|
||||
|
@ -344,4 +347,29 @@ public class DOMLocationMacroTests extends AST2BaseTest {
|
|||
assertNotNull( f.getFileLocation() );
|
||||
}
|
||||
}
|
||||
|
||||
public void testFunctionMacroExpansionWithNameSubstitution_Bug173637() throws Exception
|
||||
{
|
||||
StringBuffer buffer = new StringBuffer( "#define PLUS5(x) (x+5)\n"); //$NON-NLS-1$
|
||||
buffer.append( "#define FUNCTION PLUS5 \n"); //$NON-NLS-1$
|
||||
buffer.append( "int var= FUNCTION(1);"); //$NON-NLS-1$
|
||||
String code = buffer.toString();
|
||||
|
||||
for (ParserLanguage p = ParserLanguage.C; p != null; p = (p == ParserLanguage.C) ? ParserLanguage.CPP
|
||||
: null) {
|
||||
IASTTranslationUnit tu = parse(code, p);
|
||||
IASTSimpleDeclaration var = (IASTSimpleDeclaration) tu.getDeclarations()[0];
|
||||
IASTInitializerExpression initializer= (IASTInitializerExpression)var.getDeclarators()[0].getInitializer();
|
||||
IASTExpression expr= initializer.getExpression();
|
||||
assertNotNull(expr.getFileLocation());
|
||||
IASTNodeLocation [] locations = expr.getNodeLocations();
|
||||
assertEquals(1, locations.length);
|
||||
IASTMacroExpansion macroExpansion = (IASTMacroExpansion) locations[0];
|
||||
IASTNodeLocation[] expLocations= macroExpansion.getExpansionLocations();
|
||||
assertEquals(1, expLocations.length);
|
||||
assertEquals(code.indexOf("FUNCTION(1)"), expLocations[0].getNodeOffset());
|
||||
assertEquals("FUNCTION(1)".length(), expLocations[0].getNodeLength());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4026,9 +4026,13 @@ abstract class BaseScanner implements IScanner {
|
|||
return null;
|
||||
}
|
||||
|
||||
MacroData data = (MacroData) bufferData[stackpPos + 1];
|
||||
for (int i = bufferStackPos; i > stackpPos; i--)
|
||||
popContext();
|
||||
MacroData data;
|
||||
IMacro popMacro= macro;
|
||||
do {
|
||||
data= (MacroData) bufferData[bufferStackPos];
|
||||
popContextForFunctionMacroName(popMacro);
|
||||
popMacro= data.macro;
|
||||
} while (bufferStackPos > stackpPos);
|
||||
|
||||
bufferPos[bufferStackPos] = idx;
|
||||
buffer = bufferStack[bufferStackPos];
|
||||
|
@ -4158,7 +4162,18 @@ abstract class BaseScanner implements IScanner {
|
|||
return result;
|
||||
}
|
||||
|
||||
protected char[] replaceArgumentMacros(char[] arg) {
|
||||
/**
|
||||
* Called when the buffer limit is reached while expanding a function style macro.
|
||||
* This special case might be handled differently by subclasses.
|
||||
*
|
||||
* @param macro
|
||||
*/
|
||||
protected void popContextForFunctionMacroName(IMacro macro) {
|
||||
// do the default
|
||||
popContext();
|
||||
}
|
||||
|
||||
protected char[] replaceArgumentMacros(char[] arg) {
|
||||
int limit = arg.length;
|
||||
int start = -1, end = -1;
|
||||
Object expObject = null;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004, 2006 IBM Corporation and others.
|
||||
* Copyright (c) 2004, 2007 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -8,6 +8,7 @@
|
|||
* Contributors:
|
||||
* IBM - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
* Anton Leherbauer (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.parser.scanner2;
|
||||
|
||||
|
@ -250,6 +251,15 @@ public class DOMScanner extends BaseScanner {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#popContextForFunctionMacroName(org.eclipse.cdt.core.parser.IMacro)
|
||||
*/
|
||||
protected void popContextForFunctionMacroName(IMacro macro) {
|
||||
// fix the delta before popping
|
||||
bufferDelta[bufferStackPos] -= macro.getName().length;
|
||||
popContext();
|
||||
}
|
||||
|
||||
protected int fsmCount = 0;
|
||||
|
||||
/*
|
||||
|
|
Loading…
Add table
Reference in a new issue