diff --git a/src/lang/cpp/internal/BindingsResolver.java b/src/lang/cpp/internal/BindingsResolver.java index 2741e110..f0f790f0 100644 --- a/src/lang/cpp/internal/BindingsResolver.java +++ b/src/lang/cpp/internal/BindingsResolver.java @@ -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()); @@ -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; @@ -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"; } @@ -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); } diff --git a/src/lang/cpp/internal/Parser.java b/src/lang/cpp/internal/Parser.java index 2feeb442..81f23c64 100644 --- a/src/lang/cpp/internal/Parser.java +++ b/src/lang/cpp/internal/Parser.java @@ -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 -> { @@ -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);