Skip to content

Commit

Permalink
[analyzer][NFC] Turn NodeBuilderContext into a class (#84638)
Browse files Browse the repository at this point in the history
From issue #73088. I changed `NodeBuilderContext` into a class.
Additionally, there were some other mentions of the former being a
struct which I also changed into a class. This is my first time working
with an issue so I will be open to hearing any advice or changes that
need to be done.
  • Loading branch information
diego-est committed Mar 12, 2024
1 parent 683a9ac commit 7bee91f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion clang/include/clang/StaticAnalyzer/Core/CheckerManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class ExplodedNodeSet;
class ExprEngine;
struct EvalCallOptions;
class MemRegion;
struct NodeBuilderContext;
class NodeBuilderContext;
class ObjCMethodCall;
class RegionAndSymbolInvalidationTraits;
class SVal;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class CoreEngine {
friend class ExprEngine;
friend class IndirectGotoNodeBuilder;
friend class NodeBuilder;
friend struct NodeBuilderContext;
friend class NodeBuilderContext;
friend class SwitchNodeBuilder;

public:
Expand Down Expand Up @@ -193,12 +193,12 @@ class CoreEngine {
DataTag::Factory &getDataTags() { return DataTags; }
};

// TODO: Turn into a class.
struct NodeBuilderContext {
class NodeBuilderContext {
const CoreEngine &Eng;
const CFGBlock *Block;
const LocationContext *LC;

public:
NodeBuilderContext(const CoreEngine &E, const CFGBlock *B,
const LocationContext *L)
: Eng(E), Block(B), LC(L) {
Expand All @@ -208,9 +208,15 @@ struct NodeBuilderContext {
NodeBuilderContext(const CoreEngine &E, const CFGBlock *B, ExplodedNode *N)
: NodeBuilderContext(E, B, N->getLocationContext()) {}

/// Return the CoreEngine associated with this builder.
const CoreEngine &getEngine() const { return Eng; }

/// Return the CFGBlock associated with this builder.
const CFGBlock *getBlock() const { return Block; }

/// Return the location context associated with this builder.
const LocationContext *getLocationContext() const { return LC; }

/// Returns the number of times the current basic block has been
/// visited on the exploded graph path.
unsigned blockCount() const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class ExplodedNodeSet;
class ExplodedNode;
class IndirectGotoNodeBuilder;
class MemRegion;
struct NodeBuilderContext;
class NodeBuilderContext;
class NodeBuilderWithSinks;
class ProgramState;
class ProgramStateManager;
Expand Down
6 changes: 3 additions & 3 deletions clang/lib/StaticAnalyzer/Core/CoreEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -625,8 +625,8 @@ ExplodedNode* NodeBuilder::generateNodeImpl(const ProgramPoint &Loc,
bool MarkAsSink) {
HasGeneratedNodes = true;
bool IsNew;
ExplodedNode *N = C.Eng.G.getNode(Loc, State, MarkAsSink, &IsNew);
N->addPredecessor(FromN, C.Eng.G);
ExplodedNode *N = C.getEngine().G.getNode(Loc, State, MarkAsSink, &IsNew);
N->addPredecessor(FromN, C.getEngine().G);
Frontier.erase(FromN);

if (!IsNew)
Expand Down Expand Up @@ -655,7 +655,7 @@ ExplodedNode *BranchNodeBuilder::generateNode(ProgramStateRef State,
if (!isFeasible(branch))
return nullptr;

ProgramPoint Loc = BlockEdge(C.Block, branch ? DstT:DstF,
ProgramPoint Loc = BlockEdge(C.getBlock(), branch ? DstT : DstF,
NodePred->getLocationContext());
ExplodedNode *Succ = generateNodeImpl(Loc, State, NodePred);
return Succ;
Expand Down

0 comments on commit 7bee91f

Please sign in to comment.