mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 18:26:01 +02:00
Bug 412463 - Code completion stops working in the presence of
preprocessor-provided macros Change-Id: Ifc5621133ac1ad55276e3d0c1ea8f99d9101938a Signed-off-by: Nathan Ridge <zeratul976@hotmail.com> Reviewed-on: https://git.eclipse.org/r/14354 Reviewed-by: Sergey Prigogin <eclipse.sprigogin@gmail.com> IP-Clean: Sergey Prigogin <eclipse.sprigogin@gmail.com> Tested-by: Sergey Prigogin <eclipse.sprigogin@gmail.com>
This commit is contained in:
parent
20a079bafa
commit
652d4f7bc0
3 changed files with 47 additions and 11 deletions
|
@ -1951,5 +1951,16 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
|
||||||
return fMacroExpander;
|
return fMacroExpander;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return whether 'name' is a macro whose definition is provided by the
|
||||||
|
* preprocessor, like __LINE__, __FILE__, __DATE__ or __TIME__.
|
||||||
|
*/
|
||||||
|
public static boolean isPreprocessorProvidedMacro(char[] name) {
|
||||||
|
return CharArrayUtils.equals(__LINE__.getNameCharArray(), name)
|
||||||
|
|| CharArrayUtils.equals(__FILE__.getNameCharArray(), name)
|
||||||
|
|| CharArrayUtils.equals(__DATE__.getNameCharArray(), name)
|
||||||
|
|| CharArrayUtils.equals(__TIME__.getNameCharArray(), name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -356,7 +356,7 @@ final class ScannerContext {
|
||||||
if (fInternalModifications != null && !fInternalModifications.containsKey(macroName)) {
|
if (fInternalModifications != null && !fInternalModifications.containsKey(macroName)) {
|
||||||
final char[] expansion = macro.getExpansion();
|
final char[] expansion = macro.getExpansion();
|
||||||
if (expansion != null)
|
if (expansion != null)
|
||||||
fSignificantMacros.put(macroName, SignificantMacros.shortenValue(expansion));
|
addSignificantMacro(macroName, SignificantMacros.shortenValue(expansion));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -367,16 +367,16 @@ final class ScannerContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addSignificantMacroDefined(char[] macroName) {
|
private void addSignificantMacroDefined(char[] macroName) {
|
||||||
char[] old= fSignificantMacros.put(macroName, SignificantMacros.DEFINED);
|
char[] old= addSignificantMacro(macroName, SignificantMacros.DEFINED);
|
||||||
if (old != null && old != SignificantMacros.DEFINED) {
|
if (old != null && old != SignificantMacros.DEFINED) {
|
||||||
// Put back more detailed condition
|
// Put back more detailed condition
|
||||||
fSignificantMacros.put(macroName, old);
|
addSignificantMacro(macroName, old);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void significantMacroUndefined(char[] macroName) {
|
public void significantMacroUndefined(char[] macroName) {
|
||||||
if (fInternalModifications != null && !fInternalModifications.containsKey(macroName)) {
|
if (fInternalModifications != null && !fInternalModifications.containsKey(macroName)) {
|
||||||
fSignificantMacros.put(macroName, SignificantMacros.UNDEFINED);
|
addSignificantMacro(macroName, SignificantMacros.UNDEFINED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -396,7 +396,6 @@ final class ScannerContext {
|
||||||
|
|
||||||
// Propagate significant macros to direct parent, if it is interested.
|
// Propagate significant macros to direct parent, if it is interested.
|
||||||
if (collector == fParent.fInternalModifications) {
|
if (collector == fParent.fInternalModifications) {
|
||||||
final CharArrayObjectMap<char[]> significant = fParent.fSignificantMacros;
|
|
||||||
for (int i= 0; i < fSignificantMacros.size(); i++) {
|
for (int i= 0; i < fSignificantMacros.size(); i++) {
|
||||||
final char[] name = fSignificantMacros.keyAt(i);
|
final char[] name = fSignificantMacros.keyAt(i);
|
||||||
if (!collector.containsKey(name)) {
|
if (!collector.containsKey(name)) {
|
||||||
|
@ -406,7 +405,7 @@ final class ScannerContext {
|
||||||
fParent.addSignificantMacroDefined(name);
|
fParent.addSignificantMacroDefined(name);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
significant.put(name, value);
|
fParent.addSignificantMacro(name, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -425,7 +424,7 @@ final class ScannerContext {
|
||||||
@Override
|
@Override
|
||||||
public boolean visitValue(char[] macro, char[] value) {
|
public boolean visitValue(char[] macro, char[] value) {
|
||||||
if (!fInternalModifications.containsKey(macro)) {
|
if (!fInternalModifications.containsKey(macro)) {
|
||||||
fSignificantMacros.put(macro, value);
|
addSignificantMacro(macro, value);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -433,7 +432,7 @@ final class ScannerContext {
|
||||||
@Override
|
@Override
|
||||||
public boolean visitUndefined(char[] macro) {
|
public boolean visitUndefined(char[] macro) {
|
||||||
if (!fInternalModifications.containsKey(macro)) {
|
if (!fInternalModifications.containsKey(macro)) {
|
||||||
fSignificantMacros.put(macro, SignificantMacros.UNDEFINED);
|
addSignificantMacro(macro, SignificantMacros.UNDEFINED);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -441,13 +440,19 @@ final class ScannerContext {
|
||||||
@Override
|
@Override
|
||||||
public boolean visitDefined(char[] macro) {
|
public boolean visitDefined(char[] macro) {
|
||||||
if (!fInternalModifications.containsKey(macro)) {
|
if (!fInternalModifications.containsKey(macro)) {
|
||||||
fSignificantMacros.put(macro, SignificantMacros.DEFINED);
|
addSignificantMacro(macro, SignificantMacros.DEFINED);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private char[] addSignificantMacro(char[] macro, char[] value) {
|
||||||
|
if (CPreprocessor.isPreprocessorProvidedMacro(macro))
|
||||||
|
return null;
|
||||||
|
return fSignificantMacros.put(macro, value);
|
||||||
|
}
|
||||||
|
|
||||||
public int getLoadedVersionCount() {
|
public int getLoadedVersionCount() {
|
||||||
return fLoadedVersionCount;
|
return fLoadedVersionCount;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1292,4 +1292,24 @@ public class CompletionTests extends AbstractContentAssistTest {
|
||||||
final String[] expected = { "Cat", "meow(void)" };
|
final String[] expected = { "Cat", "meow(void)" };
|
||||||
assertContentAssistResults(fCursorOffset, expected, true, COMPARE_ID_STRINGS);
|
assertContentAssistResults(fCursorOffset, expected, true, COMPARE_ID_STRINGS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// struct Cat {
|
||||||
|
// void meow();
|
||||||
|
// };
|
||||||
|
//
|
||||||
|
// struct Waldo {
|
||||||
|
// void bar() {
|
||||||
|
// c./*cursor*/
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// Cat c;
|
||||||
|
// };
|
||||||
|
//
|
||||||
|
// void foo() {
|
||||||
|
// __LINE__;
|
||||||
|
// }
|
||||||
|
public void testLineMacro_Bug412463() throws Exception {
|
||||||
|
final String[] expected = { "Cat", "meow(void)" };
|
||||||
|
assertContentAssistResults(fCursorOffset, expected, true, COMPARE_ID_STRINGS);
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue