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,58 +4096,59 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
if (LT(1) == IToken.tLBRACE) {
consume(IToken.tLBRACE);
memberDeclarationLoop: while (LT(1) != IToken.tRBRACE) {
int checkToken = LA(1).hashCode();
switch (LT(1)) {
case IToken.t_public:
case IToken.t_protected:
case IToken.t_private:
IToken key = consume();
int l = consume(IToken.tCOLON).getEndOffset();
ICPPASTVisiblityLabel label = createVisibilityLabel();
((ASTNode) label).setOffsetAndLength(key.getOffset(), l
- key.getOffset());
label.setVisibility(token2Visibility(key.getType()));
astClassSpecifier.addMemberDeclaration(label);
label.setParent(astClassSpecifier);
label
.setPropertyInParent(ICPPASTCompositeTypeSpecifier.VISIBILITY_LABEL);
break;
case IToken.tRBRACE:
consume(IToken.tRBRACE);
break memberDeclarationLoop;
default:
try {
IASTDeclaration d = declaration();
astClassSpecifier.addMemberDeclaration(d);
d.setParent(astClassSpecifier);
d
.setPropertyInParent(IASTCompositeTypeSpecifier.MEMBER_DECLARATION);
} catch (BacktrackException bt) {
IASTProblem p = failParse(bt);
IASTProblemDeclaration pd = createProblemDeclaration();
pd.setProblem(p);
((CPPASTNode) pd)
.setOffsetAndLength(((CPPASTNode) p));
p.setParent(pd);
p.setPropertyInParent(IASTProblemHolder.PROBLEM);
astClassSpecifier.addMemberDeclaration(pd);
pd.setParent(astClassSpecifier);
pd
.setPropertyInParent(IASTCompositeTypeSpecifier.MEMBER_DECLARATION);
if (checkToken == LA(1).hashCode())
errorHandling();
}
if (checkToken == LA(1).hashCode())
failParseWithErrorHandling();
}
memberDeclarationLoop: while (true) {
int checkToken = LA(1).hashCode();
switch (LT(1)) {
case IToken.t_public:
case IToken.t_protected:
case IToken.t_private: {
IToken key = consume();
int l = consume(IToken.tCOLON).getEndOffset();
ICPPASTVisiblityLabel label = createVisibilityLabel();
((ASTNode) label).setOffsetAndLength(key.getOffset(), l
- key.getOffset());
label.setVisibility(token2Visibility(key.getType()));
astClassSpecifier.addMemberDeclaration(label);
label.setParent(astClassSpecifier);
label
.setPropertyInParent(ICPPASTCompositeTypeSpecifier.VISIBILITY_LABEL);
break;
}
// consume the }
int l = consume(IToken.tRBRACE).getEndOffset();
((ASTNode) astClassSpecifier).setLength(l - classKey.getOffset());
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;
default:
try {
IASTDeclaration d = declaration();
astClassSpecifier.addMemberDeclaration(d);
d.setParent(astClassSpecifier);
d
.setPropertyInParent(IASTCompositeTypeSpecifier.MEMBER_DECLARATION);
} catch (BacktrackException bt) {
IASTProblem p = failParse(bt);
IASTProblemDeclaration pd = createProblemDeclaration();
pd.setProblem(p);
((CPPASTNode) pd).setOffsetAndLength(((CPPASTNode) p));
p.setParent(pd);
p.setPropertyInParent(IASTProblemHolder.PROBLEM);
astClassSpecifier.addMemberDeclaration(pd);
pd.setParent(astClassSpecifier);
pd
.setPropertyInParent(IASTCompositeTypeSpecifier.MEMBER_DECLARATION);
if (checkToken == LA(1).hashCode())
errorHandling();
}
if (checkToken == LA(1).hashCode())
failParseWithErrorHandling();
}
}
}
return astClassSpecifier;

View file

@ -231,18 +231,21 @@ public class InternalASTServiceProvider implements IASTServiceProvider {
IProject project = resource.getProject();
ICFileType type = CCorePlugin.getDefault().getFileType(project, resource.getLocation().lastSegment());
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 {
if( project.hasNature( CCProjectNature.CC_NATURE_ID ))
return ParserLanguage.CPP;
} catch (CoreException e) {
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;
} catch (CoreException e) {
}
// Actually, it probably isn't a C file, but anyway...
return ParserLanguage.C;
}
}

View file

@ -60,7 +60,9 @@ public class DOMCompletionContributor implements ICompletionContributor {
if (bindings != null)
for (int j = 0; j < bindings.length; ++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);
}
}