Skip to content

Commit

Permalink
Update comments in TBRAnalyzer.h.
Browse files Browse the repository at this point in the history
  • Loading branch information
PetroZarytskyi committed Nov 6, 2023
1 parent fe7310f commit 3cbf1f6
Showing 1 changed file with 10 additions and 19 deletions.
29 changes: 10 additions & 19 deletions include/clad/Differentiator/TBRAnalyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,25 +83,14 @@ class TBRAnalyzer : public clang::ConstStmtVisitor<TBRAnalyzer> {

/// Stores all the necessary information about one variable. Fundamental type
/// variables need only one bit. An object/array needs a separate VarData for
/// every its field/element. Reference type variables have their own type for
/// convenience reasons and just point to the corresponding VarData.
/// UNDEFINED is used whenever the type of a node cannot be determined.
/// each field/element. Reference type variables store the clang::Expr* they
/// refer to. UNDEFINED is used whenever the type of a node cannot be determined.

/// FIXME: Pointers to objects are considered OBJ_TYPE for simplicity. This
/// approach might cause problems when the support for pointers is added.

/// FIXME: Only References to concrete variables are supported. Using
/// 'double& x = (cond ? a : b);' or 'double& x = arr[n*k]' (non-const index)
/// will lead to unpredictable behavior.

/// FIXME: Different array elements are considered different variables
/// which makes the analysis way more complicated (both in terms of
/// readability and performance) when non-constant indices are used. Moreover,
/// in such cases we start assuming 'arr[k]' could be any element of arr.
/// The only scenario where analysing elements separately would make sense is
/// when an element with the same constant index is changed multiple times in
/// a row, which seems uncommon. It's worth considering analysing arrays as
/// whole structures instead (just one VarData for the whole array).
/// FIXME: Add support for references to call expression results.
/// 'double& x = f(b);' is not supported.

struct VarData;
using ObjMap = std::unordered_map<const clang::FieldDecl*, VarData>;
Expand All @@ -125,7 +114,7 @@ class TBRAnalyzer : public clang::ConstStmtVisitor<TBRAnalyzer> {
VarData() = default;

/// Builds a VarData object (and its children) based on the provided type.
VarData(QualType QT);
VarData(const QualType QT);

/// Erases all children VarData's of this VarData.
void erase() {
Expand Down Expand Up @@ -275,7 +264,7 @@ class TBRAnalyzer : public clang::ConstStmtVisitor<TBRAnalyzer> {

/// Stores modes in a stack (used to retrieve the old mode after entering
/// a new one).
std::vector<int> modeStack;
std::vector<short> modeStack;

ASTContext& m_Context;

Expand Down Expand Up @@ -312,7 +301,7 @@ class TBRAnalyzer : public clang::ConstStmtVisitor<TBRAnalyzer> {
void setIsRequired(const clang::Expr* E, bool isReq = true);

/// Returns the VarsData of the CFG block being visited.
VarsData& getCurBlockVarsData() { return *blockData[curBlockID]; }
VarsData& getCurBranch() { return *blockData[curBlockID]; }

//// Modes Setters
/// Sets the mode manually
Expand All @@ -337,7 +326,9 @@ class TBRAnalyzer : public clang::ConstStmtVisitor<TBRAnalyzer> {
/// Destructor
~TBRAnalyzer() {
for (auto varsData : blockData) {
delete varsData;
if (varsData) {
delete varsData;
}
}
}

Expand Down

0 comments on commit 3cbf1f6

Please sign in to comment.