Skip to content

Commit

Permalink
Syntactically distinguish explicitly and implicitly declared pattern …
Browse files Browse the repository at this point in the history
…vars.
  • Loading branch information
toinehartman committed Jun 11, 2024
1 parent 596c313 commit 1d87cf1
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions rascal-lsp/src/main/rascal/lang/rascal/lsp/Rename.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -86,24 +86,31 @@ bool renameCausesDoubleDeclaration(TModel tm, set[loc] defLocs, set[loc] useLocs
return any(loc dS <- newNameScopes, loc l <- (useLocs + defLocs), isContainedIn(l, dS));
}
bool isImplicitDefinition(map[loc, loc] useDef, Define def) = size(def.id) == def.defined.length
when def.idRole is variableId
&& def.defined in useDef; // use of name at implicit declaration loc
bool isImplicitDefinition(start[Module] _, map[loc, loc] useDef, Define _: <_, _, _, variableId(), defined, _>) = defined in useDef; // use of name at implicit declaration loc
bool isImplicitDefinition(map[loc, loc] _, Define def) = size(def.id) == def.defined.length
when def.idRole is patternVariableId;
// How can we distinguish (explicit) `int bar = 9;` from (implicit) `bar := 0;` and `<bar, _> := <9, 99>;`?
// The following condition correctly distuishes the first and second case, but will incorrectly flag the third as being an explicit declaration
// !beginsBefore(def.scope, def.defined); // no type in front of name
// TODO Fix
bool isImplicitDefinition(start[Module] m, map[loc, loc] _, Define _: <_, _, _, patternVariableId(), defined, _>) {
visit (m) {
case qualifiedName(qn): {
if (findNameLocation(qn) == defined) return true;
}
case multiVariable(qn): {
if (findNameLocation(qn) == defined) return true;
}
case variableBecomes(n, _): {
if (findNameLocation(n) == defined) return true;
}
}
return false;
}
default bool isImplicitDefinition(map[loc, loc] _, Define _) = false;
default bool isImplicitDefinition(start[Module] _, map[loc, loc] _, Define _) = false;
bool renameCausesCapture(TModel tm, start[Module] m, set[loc] currentNameDefLocs, str newName) {
// Is newName implicitly declared in a scope from where <current-name> can be resolved?
set[loc] currentNameScopes = {tm.definitions[dL].scope | loc dL <- currentNameDefLocs};
map[loc, loc] useDef = toMapUnique(tm.useDef);
set[loc] newNameImplicitDeclLocs = {def.defined | def <- tm.defines, def.id == newName, isImplicitDefinition(useDef, def)};
set[loc] newNameImplicitDeclLocs = {def.defined | def <- tm.defines, def.id == newName, isImplicitDefinition(m, useDef, def)};
return any(loc iD <- newNameImplicitDeclLocs, loc dS <- currentNameScopes, isContainedIn(iD, dS));
}
Expand Down

0 comments on commit 1d87cf1

Please sign in to comment.