Skip to content

Commit

Permalink
refactored ownedBinding to implement semantics of static for all occu…
Browse files Browse the repository at this point in the history
…rrences
  • Loading branch information
jurgenvinju committed Dec 22, 2023
1 parent 0d64bab commit 1bab119
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
34 changes: 28 additions & 6 deletions src/lang/cpp/internal/BindingsResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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(')');
Expand Down
2 changes: 1 addition & 1 deletion src/lang/cpp/internal/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 1bab119

Please sign in to comment.