mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 02:06:01 +02:00
Fix for 171708, obtaining macros from index via AST.
This commit is contained in:
parent
9ffa39148a
commit
85b13d4c52
7 changed files with 66 additions and 10 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
|
||||
|
@ -139,6 +139,14 @@ public interface IASTTranslationUnit extends IASTNode {
|
|||
*/
|
||||
public IASTPreprocessorMacroDefinition[] getMacroDefinitions();
|
||||
|
||||
/**
|
||||
* Get builtin macro definitions used when parsing this translation unit.
|
||||
* This includes macros obtained from the index.
|
||||
*
|
||||
* @return <code>IASTPreprocessorMacroDefinition[]</code>
|
||||
*/
|
||||
public IASTPreprocessorMacroDefinition[] getBuiltinMacroDefinitions();
|
||||
|
||||
/**
|
||||
* Get the #include directives encountered in parsing this translation unit.
|
||||
* @return <code>IASTPreprocessorIncludeStatement[]</code>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2002, 2006 IBM Corporation and others.
|
||||
* Copyright (c) 2002, 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
|
||||
|
@ -427,6 +427,19 @@ public class CASTTranslationUnit extends CASTNode implements
|
|||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getMacroDefinitions()
|
||||
*/
|
||||
public IASTPreprocessorMacroDefinition[] getBuiltinMacroDefinitions() {
|
||||
if (resolver == null)
|
||||
return EMPTY_PREPROCESSOR_MACRODEF_ARRAY;
|
||||
IASTPreprocessorMacroDefinition[] result = resolver
|
||||
.getBuiltinMacroDefinitions();
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
|
|
|
@ -464,6 +464,17 @@ public class CPPASTTranslationUnit extends CPPASTNode implements
|
|||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getMacroDefinitions()
|
||||
*/
|
||||
public IASTPreprocessorMacroDefinition[] getBuiltinMacroDefinitions() {
|
||||
if( resolver == null ) return EMPTY_PREPROCESSOR_MACRODEF_ARRAY;
|
||||
IASTPreprocessorMacroDefinition [] result = resolver.getBuiltinMacroDefinitions();
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004, 2005 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
|
||||
|
@ -7,6 +7,7 @@
|
|||
*
|
||||
* Contributors:
|
||||
* IBM - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.parser.scanner2;
|
||||
|
||||
|
@ -28,6 +29,7 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTPreprocessorSelectionResult;
|
|||
public interface ILocationResolver {
|
||||
|
||||
public IASTPreprocessorMacroDefinition [] getMacroDefinitions();
|
||||
public IASTPreprocessorMacroDefinition [] getBuiltinMacroDefinitions();
|
||||
public IASTPreprocessorIncludeStatement [] getIncludeDirectives();
|
||||
public IASTPreprocessorStatement [] getAllPreprocessorStatements();
|
||||
|
||||
|
|
|
@ -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
|
||||
|
@ -12,6 +12,8 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.parser.scanner2;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ILinkage;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionStyleMacroParameter;
|
||||
|
@ -1452,6 +1454,20 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
|||
return result;
|
||||
}
|
||||
|
||||
public IASTPreprocessorMacroDefinition[] getBuiltinMacroDefinitions() {
|
||||
IMacroDefinition[] mdefs= tu.getBuiltinMacroDefinitions();
|
||||
if (mdefs.length == 0)
|
||||
return EMPTY_MACRO_DEFINITIONS_ARRAY;
|
||||
ArrayList result= new ArrayList(mdefs.length);
|
||||
for (int i = 0; i < mdefs.length; i++) {
|
||||
IMacroDefinition mdef = mdefs[i];
|
||||
if (mdef instanceof _MacroDefinition) {
|
||||
result.add(createASTMacroDefinition((_MacroDefinition) mdef));
|
||||
}
|
||||
}
|
||||
return (IASTPreprocessorMacroDefinition[]) result.toArray(new IASTPreprocessorMacroDefinition[result.size()]);
|
||||
}
|
||||
|
||||
public IMacroBinding resolveBindingForMacro(char[] name, int offset ) {
|
||||
_Context search = findContextForOffset( offset );
|
||||
IMacroDefinition macroDefinition = null;
|
||||
|
@ -1478,9 +1494,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
|||
private IASTPreprocessorMacroDefinition createASTMacroDefinition(
|
||||
_MacroDefinition d) {
|
||||
IASTPreprocessorMacroDefinition r = null;
|
||||
if (d instanceof _ObjectMacroDefinition)
|
||||
r = new ASTObjectMacro();
|
||||
else if (d instanceof _FunctionMacroDefinition) {
|
||||
if (d instanceof _FunctionMacroDefinition) {
|
||||
IASTPreprocessorFunctionStyleMacroDefinition f = new ASTFunctionMacro();
|
||||
char[][] parms = ((_FunctionMacroDefinition) d).getParms();
|
||||
for (int j = 0; j < parms.length; ++j) {
|
||||
|
@ -1493,7 +1507,10 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
|||
}
|
||||
r = f;
|
||||
}
|
||||
|
||||
else {
|
||||
r = new ASTObjectMacro();
|
||||
}
|
||||
|
||||
IASTName name = new ASTMacroName(d.name);
|
||||
name.setPropertyInParent(IASTPreprocessorMacroDefinition.MACRO_NAME);
|
||||
name.setParent(r);
|
||||
|
|
|
@ -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
|
||||
|
@ -32,7 +32,6 @@ public class CompletionTest_SingleName_Prefix extends CompletionProposalsBaseTe
|
|||
public CompletionTest_SingleName_Prefix(String name) {
|
||||
super(name);
|
||||
// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=171708
|
||||
setExpectFailure(171708);
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
* IBM Corporation - initial API and implementation
|
||||
* Anton Leherbauer (Wind River Systems)
|
||||
* Bryan Wilkinson (QNX)
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.text.contentassist;
|
||||
|
||||
|
@ -103,6 +104,11 @@ public class DOMCompletionContributor implements ICompletionContributor {
|
|||
for (int i = 0; i < macros.length; ++i)
|
||||
if (CharArrayUtils.equals(macros[i].getName().toCharArray(), 0, prefix.length(), prefix.toCharArray(), false))
|
||||
handleMacro(macros[i], completionNode, offset, viewer, proposals);
|
||||
macros = completionNode.getTranslationUnit().getBuiltinMacroDefinitions();
|
||||
if (macros != null)
|
||||
for (int i = 0; i < macros.length; ++i)
|
||||
if (CharArrayUtils.equals(macros[i].getName().toCharArray(), 0, prefix.length(), prefix.toCharArray(), false))
|
||||
handleMacro(macros[i], completionNode, offset, viewer, proposals);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue