1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-04 23:05:47 +02:00

Store macro-expansion image in index, needed for bug 23540.

This commit is contained in:
Markus Schorn 2008-01-21 15:46:10 +00:00
parent 4cc8dfd7b5
commit 63dfbb48df
3 changed files with 13 additions and 14 deletions

View file

@ -143,8 +143,8 @@ public class MacroDefinitionParser {
/** /**
* Parses a macro definition basically checking for var-args. * Parses a macro definition basically checking for var-args.
*/ */
public PreprocessorMacro parseMacroDefinition(final char[] name, char[][] paramList, final char[] replacement) { public static PreprocessorMacro parseMacroDefinition(final char[] name, char[][] paramList, final char[] replacement) {
fHasVarArgs= 0; int hasVarargs= 0;
if (paramList != null) { if (paramList != null) {
final int length = paramList.length; final int length = paramList.length;
if (length > 0) { if (length > 0) {
@ -155,7 +155,7 @@ public class MacroDefinitionParser {
break; break;
case 3: case 3:
if (CharArrayUtils.equals(lastParam, Keywords.cpELLIPSIS)) { if (CharArrayUtils.equals(lastParam, Keywords.cpELLIPSIS)) {
fHasVarArgs= FunctionStyleMacro.VAARGS; hasVarargs= FunctionStyleMacro.VAARGS;
char[][] copy= new char[length][]; char[][] copy= new char[length][];
System.arraycopy(paramList, 0, copy, 0, length-1); System.arraycopy(paramList, 0, copy, 0, length-1);
copy[length-1]= Keywords.cVA_ARGS; copy[length-1]= Keywords.cVA_ARGS;
@ -164,7 +164,7 @@ public class MacroDefinitionParser {
break; break;
default: default:
if (CharArrayUtils.equals(lastParam, lpl-3, 3, Keywords.cpELLIPSIS)) { if (CharArrayUtils.equals(lastParam, lpl-3, 3, Keywords.cpELLIPSIS)) {
fHasVarArgs= FunctionStyleMacro.NAMED_VAARGS; hasVarargs= FunctionStyleMacro.NAMED_VAARGS;
char[][] copy= new char[length][]; char[][] copy= new char[length][];
System.arraycopy(paramList, 0, copy, 0, length-1); System.arraycopy(paramList, 0, copy, 0, length-1);
copy[length-1]= CharArrayUtils.subarray(lastParam, 0, lpl-3); copy[length-1]= CharArrayUtils.subarray(lastParam, 0, lpl-3);
@ -178,7 +178,7 @@ public class MacroDefinitionParser {
if (paramList == null) { if (paramList == null) {
return new ObjectStyleMacro(name, replacement); return new ObjectStyleMacro(name, replacement);
} }
return new FunctionStyleMacro(name, paramList, fHasVarArgs, replacement); return new FunctionStyleMacro(name, paramList, hasVarargs, replacement);
} }
private Token parseName(final Lexer lexer) throws OffsetLimitReachedException, InvalidMacroDefinitionException { private Token parseName(final Lexer lexer) throws OffsetLimitReachedException, InvalidMacroDefinitionException {

View file

@ -21,10 +21,9 @@ import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ILinkage; import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation; import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IASTFunctionStyleMacroParameter;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorFunctionStyleMacroDefinition;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition; import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
import org.eclipse.cdt.core.dom.ast.IMacroBinding;
import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.index.IIndexFile; import org.eclipse.cdt.core.index.IIndexFile;
import org.eclipse.cdt.core.index.IIndexMacro; import org.eclipse.cdt.core.index.IIndexMacro;
@ -77,23 +76,23 @@ public class PDOMMacro implements IIndexMacro, IASTFileLocation {
Database db = pdom.getDB(); Database db = pdom.getDB();
this.record = db.malloc(RECORD_SIZE); this.record = db.malloc(RECORD_SIZE);
IASTName name = macro.getName(); IASTName name = macro.getName();
IMacroBinding binding= (IMacroBinding) name.getBinding();
db.putInt(record + NAME, db.newString(name.toCharArray()).getRecord()); db.putInt(record + NAME, db.newString(name.toCharArray()).getRecord());
db.putInt(record + FILE, file.getRecord()); db.putInt(record + FILE, file.getRecord());
IASTFileLocation fileloc = name.getFileLocation(); IASTFileLocation fileloc = name.getFileLocation();
db.putInt(record + NAME_OFFSET, fileloc.getNodeOffset()); db.putInt(record + NAME_OFFSET, fileloc.getNodeOffset());
db.putShort(record + NAME_LENGTH, (short) fileloc.getNodeLength()); db.putShort(record + NAME_LENGTH, (short) fileloc.getNodeLength());
db.putInt(record + EXPANSION, db.newString(macro.getExpansion()).getRecord()); db.putInt(record + EXPANSION, db.newString(binding.getExpansionImage()).getRecord());
setNextMacro(0); setNextMacro(0);
byte macroStyle= MACROSTYLE_OBJECT; byte macroStyle= MACROSTYLE_OBJECT;
PDOMMacroParameter last = null; PDOMMacroParameter last = null;
if (macro instanceof IASTPreprocessorFunctionStyleMacroDefinition) { char[][] params= binding.getParameterList();
if (params != null) {
macroStyle= MACROSTYLE_FUNCTION; macroStyle= MACROSTYLE_FUNCTION;
IASTPreprocessorFunctionStyleMacroDefinition func = (IASTPreprocessorFunctionStyleMacroDefinition)macro;
IASTFunctionStyleMacroParameter[] params = func.getParameters();
for (int i = params.length - 1; i >= 0; --i) { for (int i = params.length - 1; i >= 0; --i) {
IASTFunctionStyleMacroParameter param = params[i]; PDOMMacroParameter pdomParam = new PDOMMacroParameter(pdom, params[i]);
PDOMMacroParameter pdomParam = new PDOMMacroParameter(pdom, param.getParameter());
if (last != null) if (last != null)
pdomParam.setNextParameter(last); pdomParam.setNextParameter(last);
last = pdomParam; last = pdomParam;

View file

@ -35,7 +35,7 @@ public class PDOMMacroParameter {
this.record = record; this.record = record;
} }
public PDOMMacroParameter(PDOM pdom, String name) throws CoreException { public PDOMMacroParameter(PDOM pdom, char[] name) throws CoreException {
Database db = pdom.getDB(); Database db = pdom.getDB();
this.pdom = pdom; this.pdom = pdom;