Skip to content

Commit ff8456e

Browse files
Cleanups: doc comments, debugging, fix type name collision (#10)
* docs: Add some doc comments + fix typo. * debug: Make LocalOccurrence debug output clearer * cleanup: Fix accidental type name collision
1 parent 01c89b3 commit ff8456e

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

cfg/Instructions.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,8 @@ string TAbsurd::showRaw(const core::GlobalState &gs, const CFG &cfg, int tabs) c
310310
this->what.showRaw(gs, cfg, tabs + 1));
311311
}
312312

313-
string LocalOccurrence::toString(const core::GlobalState &gs, core::FileRef file, const CFG &cfg) const {
314-
return fmt::format("local_occ {} @ {}", this->variable.toString(gs, cfg), core::Loc(file, this->loc).toString(gs));
313+
string LocalOccurrence::showRaw(const core::GlobalState &gs, core::FileRef file, const CFG &cfg) const {
314+
return fmt::format("local_occ {} @ {}", this->variable.toString(gs, cfg), core::Loc(file, this->loc).showRaw(gs));
315315
}
316316

317317
string VariableUseSite::toString(const core::GlobalState &gs, const CFG &cfg) const {

cfg/Instructions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ struct LocalOccurrence final {
2424
return {variable, core::LocOffsets::none()};
2525
}
2626

27-
std::string toString(const core::GlobalState &gs, core::FileRef file, const CFG &cfg) const;
27+
std::string showRaw(const core::GlobalState &gs, core::FileRef file, const CFG &cfg) const;
2828
};
2929

3030
class VariableUseSite final {

scip_indexer/SCIPIndexer.cc

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ static bool isTemporary(const core::GlobalState &gs, const core::LocalVariable &
115115
n == Names::unconditional();
116116
}
117117

118-
struct LocalOccurrence {
118+
struct OwnedLocal {
119119
/// Parent method.
120120
const core::SymbolRef owner;
121121
/// Counter corresponding to the local's definition, unique within a method.
@@ -272,7 +272,7 @@ class SCIPState {
272272
}
273273

274274
public:
275-
absl::Status saveDefinition(const core::GlobalState &gs, core::FileRef file, LocalOccurrence occ) {
275+
absl::Status saveDefinition(const core::GlobalState &gs, core::FileRef file, OwnedLocal occ) {
276276
return this->saveDefinitionImpl(gs, file, occ.toString(gs, file), core::Loc(file, occ.offsets));
277277
}
278278

@@ -296,8 +296,7 @@ class SCIPState {
296296
return this->saveDefinitionImpl(gs, file, symbolString, occLocStatus.value());
297297
}
298298

299-
absl::Status saveReference(const core::GlobalState &gs, core::FileRef file, LocalOccurrence occ,
300-
int32_t symbol_roles) {
299+
absl::Status saveReference(const core::GlobalState &gs, core::FileRef file, OwnedLocal occ, int32_t symbol_roles) {
301300
return this->saveReferenceImpl(gs, file, occ.toString(gs, file), occ.offsets, symbol_roles);
302301
}
303302

@@ -361,6 +360,7 @@ class CFGTraversal final {
361360
UnorderedMap<const cfg::BasicBlock *, UnorderedMap<cfg::LocalRef, core::Loc>> blockLocals;
362361
UnorderedMap<cfg::LocalRef, uint32_t> functionLocals;
363362

363+
// Local variable counter that is reset for every function.
364364
uint32_t counter = 0;
365365
SCIPState &scipState;
366366
core::Context ctx;
@@ -387,6 +387,9 @@ class CFGTraversal final {
387387
RValue,
388388
};
389389

390+
// Emit an occurrence for a local variable if applicable.
391+
//
392+
// Returns true if an occurrence was emitted.
390393
bool emitLocalOccurrence(const cfg::CFG &cfg, const cfg::BasicBlock *bb, cfg::LocalOccurrence local,
391394
ValueCategory category) {
392395
auto localRef = local.variable;
@@ -436,10 +439,10 @@ class CFGTraversal final {
436439
absl::Status status;
437440
if (isDefinition) {
438441
status = this->scipState.saveDefinition(this->ctx.state, this->ctx.file,
439-
LocalOccurrence{this->ctx.owner, localId, local.loc});
442+
OwnedLocal{this->ctx.owner, localId, local.loc});
440443
} else {
441444
status = this->scipState.saveReference(this->ctx.state, this->ctx.file,
442-
LocalOccurrence{this->ctx.owner, localId, local.loc}, referenceRole);
445+
OwnedLocal{this->ctx.owner, localId, local.loc}, referenceRole);
443446
}
444447
ENFORCE_NO_TIMER(status.ok());
445448
return true;
@@ -550,7 +553,7 @@ class CFGTraversal final {
550553
// Emit references for arguments
551554
for (auto &arg : send->args) {
552555
// NOTE: For constructs like a += b, the instruction sequence ends up being:
553-
// $tmp = $b
556+
// $tmp = $a
554557
// $a = $tmp.+($b)
555558
// The location for $tmp will point to $a in the source. However, the second one is a read,
556559
// and the first one is a write. Instead of emitting two occurrences, it'd be nice to emit

0 commit comments

Comments
 (0)