Skip to content

Commit

Permalink
better fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jurgenvinju committed Feb 27, 2024
1 parent efd0967 commit 103084c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
25 changes: 19 additions & 6 deletions src/lang/cpp/internal/BindingsResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ private ISourceLocation ownedBinding(IBinding binding, String scheme, ISourceLoc
}

private ISourceLocation ownedBinding(IBinding binding, String scheme, String postfix, ISourceLocation origin, boolean isStatic) throws URISyntaxException {
String name = renameOperators(binding.getName(), scheme) + postfix;
String name = renameOperators(binding.getName()) + postfix;
ISourceLocation ownerLocation = resolveOwner(binding, origin);
ISourceLocation location = null;
boolean isAtRoot = "cpp+translationUnit".equals(ownerLocation.getScheme());
Expand Down Expand Up @@ -217,10 +217,12 @@ private ISourceLocation ownedBinding(IBinding binding, String scheme, String pos
return location;
}

private String renameOperators(String name, String scheme) {
if ("cpp+operatorMethod".equals(scheme)) {
private String renameOperators(String name) {
if (isOperatorName(name)) {
// remove the additional spaces to avoid accidental synonyms
name = name.replaceAll(" ", "");
// wrap the operator in braces to disambiguate from possible methods with names like "operatordelete"
name = "operator(" + name.substring("operator".length()) + ")";
}

return name;
Expand Down Expand Up @@ -690,9 +692,6 @@ else if (binding instanceof ICPPMethod) {
else if (binding.getName().startsWith("~")) {
scheme = "cpp+destructor";
}
else if (binding.getName().startsWith("operator") && binding.getName().contains("[<>\\-+*/=%!&\\|\\^\\?\\.]")) {
scheme = "cpp+operatorMethod";
}
else {
scheme = "cpp+method";
}
Expand All @@ -712,6 +711,20 @@ else if (binding.getName().startsWith("operator") && binding.getName().contains(
return ownedBinding(binding, scheme, parameters.toString(), origin, binding.isStatic());
}

private boolean isOperatorName(String name) {
if (name.startsWith("operator")) {
if (name.contains("[<>\\-+*/=%!&\\|\\^\\?\\.\\[\\]]")) {
return true;
}

if (name.endsWith(" delete") || name.endsWith(" new")) {
return true;
}
}

return false;
}

private ISourceLocation resolveCEnumeration(CEnumeration binding, ISourceLocation origin) throws URISyntaxException {
return ownedBinding(binding, "c+enum", origin);
}
Expand Down
20 changes: 14 additions & 6 deletions src/lang/cpp/internal/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -1225,16 +1225,22 @@ private int visit(IASTFunctionDefinition definition) {
memberInitializers.append(stack.pop());
});

if (isDefaulted && isDeleted)
if (isDefaulted && isDeleted) {
err("WARNING: IASTFunctionDefinition both deleted and defaulted");
if ((isDefaulted || isDeleted) && definition instanceof ICPPASTFunctionWithTryBlock)
}

if ((isDefaulted || isDeleted) && definition instanceof ICPPASTFunctionWithTryBlock) {
throw new RuntimeException("IASTFunctionDefinition defaulted/deleted and with try? at " + loc);
if (isDefaulted)
}

if (isDefaulted) {
stack.push(builder.Declaration_defaultedFunctionDefinition(declSpecifier, memberInitializers.done(),
declarator, attributes, loc, isMacroExpansion));
else if (isDeleted)
}
else if (isDeleted) {
stack.push(builder.Declaration_deletedFunctionDefinition(declSpecifier, memberInitializers.done(),
declarator, attributes, loc, isMacroExpansion));
}
else if (definition instanceof ICPPASTFunctionWithTryBlock) {
IListWriter catchHandlers = vf.listWriter();
Stream.of(((ICPPASTFunctionWithTryBlock) definition).getCatchHandlers()).forEach(it -> {
Expand All @@ -1245,12 +1251,14 @@ else if (definition instanceof ICPPASTFunctionWithTryBlock) {
stack.push(builder.Declaration_functionWithTryBlockDefinition(declSpecifier, declarator,
memberInitializers.done(), stack.pop(), catchHandlers.done(), attributes, loc,
isMacroExpansion));
} else {
}
else {
definition.getBody().accept(this);
stack.push(builder.Declaration_functionDefinition(declSpecifier, declarator, memberInitializers.done(),
stack.pop(), attributes, loc, isMacroExpansion));
}
} else { // C Function definition
}
else { // C Function definition
// TODO: add separate AST entry and remove fixed empty memberinitializers and
// attributes
definition.getDeclSpecifier().accept(this);
Expand Down

0 comments on commit 103084c

Please sign in to comment.