Skip to content

Commit

Permalink
factored in owner semantics for ICPPFunction and ICFunction in the bi…
Browse files Browse the repository at this point in the history
…ndings resolver, and that allowed us to implement the semantics of `static` in one place
  • Loading branch information
jurgenvinju committed Dec 22, 2023
1 parent 4f4763e commit 0d64bab
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
30 changes: 13 additions & 17 deletions src/lang/cpp/internal/BindingsResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,20 @@ public BindingsResolver(IValueFactory vf, PrintWriter stdOut, PrintWriter stdErr
}

private ISourceLocation ownedBinding(IBinding binding, String scheme, ISourceLocation origin) throws URISyntaxException {
return ownedBinding(binding, scheme, "", origin, false);
}

private ISourceLocation ownedBinding(IBinding binding, String scheme, String postfix, ISourceLocation origin, boolean isStatic) throws URISyntaxException {
String name = binding.getName() + postfix;
ISourceLocation ownerLocation = resolveOwner(binding, origin);
ISourceLocation location = null;

if ("cpp+translationUnit".equals(ownerLocation.getScheme())) {
location = URIUtil.correctLocation(scheme, "", binding.getName());
if (!isStatic && "cpp+translationUnit".equals(ownerLocation.getScheme())) {
location = URIUtil.correctLocation(scheme, "", name);
ownerLocation = translationUnit;
}
else {
location = URIUtil.changeScheme(URIUtil.getChildLocation(ownerLocation, binding.getName()), scheme);
location = URIUtil.changeScheme(URIUtil.getChildLocation(ownerLocation, name), scheme);
}

containment.append(vf.tuple(ownerLocation, location));
Expand Down Expand Up @@ -444,7 +449,7 @@ private ISourceLocation resolveIParameter(IParameter binding, ISourceLocation or
}

private ISourceLocation resolveCVariable(CVariable binding, ISourceLocation origin) throws URISyntaxException {
return ownedBinding(binding, "c+variable", origin);
return ownedBinding(binding, "c+variable", "", origin, binding.isStatic());
}

private ISourceLocation resolveICPPVariable(ICPPVariable binding, ISourceLocation origin) throws URISyntaxException {
Expand Down Expand Up @@ -479,7 +484,7 @@ else if (binding instanceof ICPPVariableTemplatePartialSpecialization) {
scheme = "cpp+variable";
}

return ownedBinding(binding, scheme, origin);
return ownedBinding(binding, scheme, "", origin, binding.isStatic());
}

private ISourceLocation resolveICPPUsingDeclaration(ICPPUsingDeclaration binding, ISourceLocation origin) throws URISyntaxException {
Expand Down Expand Up @@ -624,12 +629,7 @@ private ISourceLocation resolveCFunction(CFunction binding, ISourceLocation orig
parameters = new StringBuilder("($$internalError)");
}

ISourceLocation owner = resolveOwner(binding, origin);
ISourceLocation decl = URIUtil.changeScheme(URIUtil.getChildLocation(owner, binding.getName()), scheme);
decl = URIUtil.changePath(decl, decl.getPath() + parameters.toString());

containment.append(vf.tuple(owner.getScheme().equals("cpp+translationUnit") ? translationUnit : owner, decl));
return decl;
return ownedBinding(binding, scheme, parameters.toString(), origin, binding.isStatic());
}

private ISourceLocation resolveICPPFunction(ICPPFunction binding, ISourceLocation origin) throws URISyntaxException {
Expand Down Expand Up @@ -675,11 +675,7 @@ else if (binding.getName().startsWith("~")) {
}
parameters.append(')');

ISourceLocation parentDecl = resolveOwner(binding, origin);
ISourceLocation decl = URIUtil.changeScheme(URIUtil.getChildLocation(parentDecl, binding.getName()), scheme);
decl = URIUtil.changePath(decl, decl.getPath() + parameters.toString());
containment.append(vf.tuple(parentDecl, decl));
return decl;
return ownedBinding(binding, scheme, parameters.toString(), origin, binding.isStatic());
}

private ISourceLocation resolveCEnumeration(CEnumeration binding, ISourceLocation origin) throws URISyntaxException {
Expand Down
2 changes: 1 addition & 1 deletion src/test/fac.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

int fac(int n) {
static int fac(int n) {
if (n <= 0) {
return 1;
}
Expand Down

0 comments on commit 0d64bab

Please sign in to comment.