diff --git a/src/lang/cpp/internal/BindingsResolver.java b/src/lang/cpp/internal/BindingsResolver.java index c9ff4da8..e6ee7175 100644 --- a/src/lang/cpp/internal/BindingsResolver.java +++ b/src/lang/cpp/internal/BindingsResolver.java @@ -183,13 +183,34 @@ private ISourceLocation ownedBinding(IBinding binding, String scheme, String pos String name = binding.getName() + postfix; ISourceLocation ownerLocation = resolveOwner(binding, origin); ISourceLocation location = null; - - if (!isStatic && "cpp+translationUnit".equals(ownerLocation.getScheme())) { - location = URIUtil.correctLocation(scheme, "", name); - ownerLocation = translationUnit; + boolean isAtRoot = "cpp+translationUnit".equals(ownerLocation.getScheme()); + + // * When we are at the root, we want a different parent from |cpp+translationUnit:///| as containment parent; name it should contain the file name from `translationUnit` + // * Also when we are the root, `static` variables and functions need to be prefixed with the file name because they are local to the current translationUnit + + if (isStatic) { + if (isAtRoot) { + // add prefix + location = URIUtil.changeScheme(URIUtil.getChildLocation(translationUnit, name), scheme); + // set long containment parent + ownerLocation = translationUnit; + } + else { + // the owner is the prefix; because we are inside some nested declaration + location = URIUtil.changeScheme(URIUtil.getChildLocation(ownerLocation, name), scheme); + } } else { - location = URIUtil.changeScheme(URIUtil.getChildLocation(ownerLocation, name), scheme); + if (isAtRoot) { + // do not add the prefix, because of global C[++] namespace while linking + location = URIUtil.correctLocation(scheme, "", name); + // set long containment parent + ownerLocation = translationUnit; + } + else { + // the owner is the prefix; because we are inside some nested declaration + location = URIUtil.changeScheme(URIUtil.getChildLocation(ownerLocation, name), scheme); + } } containment.append(vf.tuple(ownerLocation, location)); @@ -618,8 +639,9 @@ private ISourceLocation resolveCFunction(CFunction binding, ISourceLocation orig StringBuilder parameters = new StringBuilder("("); try { for (IParameter parameter : binding.getParameters()) {// getParameters can throw ClassCastException - if (parameters.length() > 1) + if (parameters.length() > 1) { parameters.append(','); + } parameters.append(printType(parameter.getType())); } parameters.append(')'); diff --git a/src/lang/cpp/internal/Parser.java b/src/lang/cpp/internal/Parser.java index 62026f07..d200160f 100644 --- a/src/lang/cpp/internal/Parser.java +++ b/src/lang/cpp/internal/Parser.java @@ -2073,7 +2073,7 @@ private int visit(IASTElaboratedTypeSpecifier declSpec) { private int visit(IASTEnumerationSpecifier declSpec) { at(declSpec); - if (declSpec instanceof ICPPASTEnumerationSpecifier) + if (declSpec instanceof ICPPASTEnumerationSpecifier) visit((ICPPASTEnumerationSpecifier) declSpec); else if (declSpec instanceof ICASTEnumerationSpecifier) visit((ICASTEnumerationSpecifier) declSpec);