1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Force the parser to treat header file translation units as C++ if they are in C++ projects. Fixed completion in class definitions. Removed my duplicate binding removal code since it depended on equals comparing the bindings (which is not the case for types).

This commit is contained in:
Doug Schaefer 2005-04-15 18:59:23 +00:00
parent 847c9e8064
commit fbc97ffbf6
3 changed files with 68 additions and 62 deletions

View file

@ -4096,13 +4096,12 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
if (LT(1) == IToken.tLBRACE) { if (LT(1) == IToken.tLBRACE) {
consume(IToken.tLBRACE); consume(IToken.tLBRACE);
memberDeclarationLoop: while (true) {
memberDeclarationLoop: while (LT(1) != IToken.tRBRACE) {
int checkToken = LA(1).hashCode(); int checkToken = LA(1).hashCode();
switch (LT(1)) { switch (LT(1)) {
case IToken.t_public: case IToken.t_public:
case IToken.t_protected: case IToken.t_protected:
case IToken.t_private: case IToken.t_private: {
IToken key = consume(); IToken key = consume();
int l = consume(IToken.tCOLON).getEndOffset(); int l = consume(IToken.tCOLON).getEndOffset();
ICPPASTVisiblityLabel label = createVisibilityLabel(); ICPPASTVisiblityLabel label = createVisibilityLabel();
@ -4114,8 +4113,15 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
label label
.setPropertyInParent(ICPPASTCompositeTypeSpecifier.VISIBILITY_LABEL); .setPropertyInParent(ICPPASTCompositeTypeSpecifier.VISIBILITY_LABEL);
break; break;
case IToken.tRBRACE: }
consume(IToken.tRBRACE); case IToken.tRBRACE: {
int l = consume(IToken.tRBRACE).getEndOffset();
((ASTNode) astClassSpecifier).setLength(l
- classKey.getOffset());
break memberDeclarationLoop;
}
case IToken.tEOC:
// Don't care about the offsets
break memberDeclarationLoop; break memberDeclarationLoop;
default: default:
try { try {
@ -4128,8 +4134,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
IASTProblem p = failParse(bt); IASTProblem p = failParse(bt);
IASTProblemDeclaration pd = createProblemDeclaration(); IASTProblemDeclaration pd = createProblemDeclaration();
pd.setProblem(p); pd.setProblem(p);
((CPPASTNode) pd) ((CPPASTNode) pd).setOffsetAndLength(((CPPASTNode) p));
.setOffsetAndLength(((CPPASTNode) p));
p.setParent(pd); p.setParent(pd);
p.setPropertyInParent(IASTProblemHolder.PROBLEM); p.setPropertyInParent(IASTProblemHolder.PROBLEM);
astClassSpecifier.addMemberDeclaration(pd); astClassSpecifier.addMemberDeclaration(pd);
@ -4145,10 +4150,6 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
} }
} }
// consume the }
int l = consume(IToken.tRBRACE).getEndOffset();
((ASTNode) astClassSpecifier).setLength(l - classKey.getOffset());
} }
return astClassSpecifier; return astClassSpecifier;
} }

View file

@ -231,18 +231,21 @@ public class InternalASTServiceProvider implements IASTServiceProvider {
IProject project = resource.getProject(); IProject project = resource.getProject();
ICFileType type = CCorePlugin.getDefault().getFileType(project, resource.getLocation().lastSegment()); ICFileType type = CCorePlugin.getDefault().getFileType(project, resource.getLocation().lastSegment());
String lid = type.getLanguage().getId(); String lid = type.getLanguage().getId();
if( lid != null )
{
if( lid.equals(ICFileTypeConstants.LANG_C ))
return ParserLanguage.C;
if( lid.equals(ICFileTypeConstants.LANG_CXX))
return ParserLanguage.CPP;
}
try { try {
if( project.hasNature( CCProjectNature.CC_NATURE_ID )) if( lid != null ) {
if( lid.equals(ICFileTypeConstants.LANG_C )) {
if (type.isHeader() && project.hasNature(CCProjectNature.CC_NATURE_ID))
return ParserLanguage.CPP;
else
return ParserLanguage.C;
} else if( lid.equals(ICFileTypeConstants.LANG_CXX))
return ParserLanguage.CPP;
} else if( project.hasNature( CCProjectNature.CC_NATURE_ID ))
return ParserLanguage.CPP; return ParserLanguage.CPP;
} catch (CoreException e) { } catch (CoreException e) {
} }
// Actually, it probably isn't a C file, but anyway...
return ParserLanguage.C; return ParserLanguage.C;
} }
} }

View file

@ -60,7 +60,9 @@ public class DOMCompletionContributor implements ICompletionContributor {
if (bindings != null) if (bindings != null)
for (int j = 0; j < bindings.length; ++j) { for (int j = 0; j < bindings.length; ++j) {
IBinding binding = bindings[j]; IBinding binding = bindings[j];
if (!allBindings.contains(binding)) //if (!allBindings.contains(binding))
// TODO I removed this check since equals in the IBinding tree is currently broken
// It is returning true at times when I don't think it should (Bug 91577)
allBindings.add(binding); allBindings.add(binding);
} }
} }