Skip to content

Commit

Permalink
Merge pull request #2 from LLNL/cpp_dev
Browse files Browse the repository at this point in the history
C++ Implementation
  • Loading branch information
KennethLamar authored Oct 17, 2024
2 parents 8a7dcb6 + 4b98956 commit ff8d719
Show file tree
Hide file tree
Showing 38 changed files with 1,260 additions and 27 deletions.
30 changes: 18 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ This will download all of the projects in parallel.

Some basic C++ programs.
These were used to verify functionality of the LCOM tool on basic C++ code.
More accurate, comprehensive C++ support is a work in progress.

```bash
git clone https://github.com/amngupta/simple-cpp-programs.git testcases/simple-cpp-programs
Expand Down Expand Up @@ -302,14 +301,14 @@ The parent method is identified by traversing up to parent scopes until a matchi

When a method is called, it is associated to the method that called it by traversing up to parent scopes until a matching method type is seen.

#### Ada renamings
#### Aliases

Attributes and methods can be renamed in Ada, complicating the process of identifying methods that share attributes.
Attributes and methods can be renamed in Ada and C++, complicating the process of identifying methods that share attributes.
When a renaming, pointer, etc. is seen, it is stored in a renaming map, which can be used to look up the root attribute or method associated with the call.

#### Ada records
#### Fields

Record are used to contain fields, allowing multiple attributes to be tied to a single object.
Ada records are used to contain fields, allowing multiple attributes to be tied to a single object.
If a record is accessed, it needs to be seen as overlapping with any access to any underlying fields as well.
Since record fields can themselves be records, it is possible that a field will be created and later accessed several records down.
To accommodate this, we use a tree data structure, where each node is an attribute and children are fields.
Expand Down Expand Up @@ -345,18 +344,16 @@ To determine if our tool produces the correct results, we must first report our
- Attributes that are never accessed do not count toward the attribute count used to calculate LCOM5.
- All methods within a class are considered, even if they have no accessed attributes.
- If an attribute is accessed multiple times within a method, it is seen as only a single access. This can affect LCOM5.
- If an attribute is never accessed, its existence will not be reported by the tool. This can affect LCOM5.
- An array is seen as a single attribute for the purposes of LCOM.
- When DotBehavior is set to LeftOnly, access to a record field counts as an access to the object as a whole. In this situation, we do not track individual fields as unique attributes.
- When DotBehavior is set to Full, access to a record field counts as a single access to the specific field. If a field access overlaps with another (potentially parent) field or record access, it is counted as a shared access.
- Attribute accesses and method calls made outside of a method are ignored.
- Attribute accesses and method calls made outside of a method's scope are ignored.
- Methods outside of a class are ignored.
- Constructors and initializers are not considered valid methods for the purposes of LCOM, much like [related work](https://github.com/potfur/lcom).
- Access to data outside of the currently evaluated file are often inaccessible. What is analyzed by the LCOM tool is limited to the contents of the AST generated by ROSE. For instance, analyzing [point_complex.adb](testcases/other-tests/point_complex.adb) can find the declarations in [gcomplex.ads](testcases/other-tests/gcomplex.ads) but misses the attribute accesses made in the method definitions found in [gcomplex.adb](testcases/other-tests/gcomplex.adb) because they are not in the AST.

## Finding and reporting issues
This tool has been tested for functionality with Ada and, to a lesser extent, C++.
In principle, it should be compatible with all languages that work with ROSE, although coverage of language features have only been thoroughly investigated for Ada.
This tool has been tested for functionality with Ada and C++.
In principle, it should be compatible with all languages that work with ROSE, although coverage of language features have only been thoroughly investigated for Ada and C++.

Issues with the tool are likely to be reported in the form of warning/error/fatal logs, unexpected program termination, or assertion failure.
These can be tracked down in logs using the following RegEx:
Expand All @@ -368,9 +365,10 @@ Issue reports for this tool should include the relevant logs (at trace level) an
## Remaining work

### Support for additional programming languages
While other languages are handled by ROSE, this tool has only been tested extensively on Ada code and found to work with C++ code.
However, languages are complex and this tool may require significant additional work to handle complex language features in a reasonable way.
Work could be done to improve support for other languages.
While other languages are handled by ROSE, this tool has only been tested extensively on Ada and C++ code.
Languages are complex and this tool may require significant additional work to handle complex language features in a reasonable way.
However, the extension of this tool to accommodate C++ was relatively straightforward, suggesting additional language support may be as simple as adding special cases for specialized AST node types.

### Experiment with nested access behavior
Currently, all attribute and called method accesses are associated only with their immediate scope parent class.
Expand Down Expand Up @@ -465,6 +463,14 @@ Running:
~/.local/bin/lcom testcases/paper
```

## Additional tools (untested)
- JavaScript: https://github.com/FujiHaruka/eslint-plugin-lcom
- C#: https://github.com/teo-tsirpanis/lcom-calculator
- PHP: https://github.com/phpmetrics/PhpMetrics/blob/master/doc/metrics.md
- Java: https://github.com/rodhilton/jasome/blob/master/src/main/java/org/jasome/metrics/calculators/LackOfCohesionMethodsCalculator.java
- Java: https://github.com/imgios/DARTS/blob/main/src/main/testSmellDetection/structuralRules/LackOfCohesionOfTestSmellStructural.java
- Java: https://github.com/mauricioaniche/ck

## Running all competing tools

```bash
Expand Down
6 changes: 6 additions & 0 deletions include/define.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ enum class ClassType {
Function,
Class,
ProtectedObject,
Namespace,
All
};
std::ostream& operator<<(std::ostream& os, const ClassType& c) {
Expand All @@ -61,6 +62,9 @@ std::ostream& operator<<(std::ostream& os, const ClassType& c) {
case ClassType::ProtectedObject:
os << "ProtectedObject";
break;
case ClassType::Namespace:
os << "Namespace";
break;
case ClassType::All:
os << "All";
break;
Expand All @@ -73,6 +77,8 @@ std::ostream& operator<<(std::ostream& os, const ClassType& c) {
// Global options set via command line.
AixLog::Severity debug = AixLog::Severity::fatal;
bool anonymous = false;
bool filterUndefinedMethods = false;
bool filterCtorsDtors = false;
DotBehavior dotBehavior = DotBehavior::LeftOnly;

#endif // DEFINE_HPP
Loading

0 comments on commit ff8d719

Please sign in to comment.