Fraunhofer-AISEC / cpg

A library to extract Code Property Graphs from C/C++, Java, Go, Python, Ruby and every other language through LLVM-IR.
https://fraunhofer-aisec.github.io/cpg/
Apache License 2.0
290 stars 62 forks source link

Optimized region utils #1822

Closed oxisto closed 3 weeks ago

oxisto commented 3 weeks ago

It seems that region utils (whatever they do) checked for a potential new line character in every call of codeAndLocationFromChildren. But the new line char should stay constant within the file, so we are using the lineSeperator property (in the python frontend) instead.

codecov[bot] commented 3 weeks ago

Codecov Report

Attention: Patch coverage is 94.11765% with 1 line in your changes missing coverage. Please review.

Project coverage is 75.24%. Comparing base (1cad7a4) to head (f42ecd6). Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...lin/de/fraunhofer/aisec/cpg/helpers/RegionUtils.kt 90.90% 1 Missing :warning:
Additional details and impacted files | [Files with missing lines](https://app.codecov.io/gh/Fraunhofer-AISEC/cpg/pull/1822?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Fraunhofer-AISEC) | Coverage Δ | | |---|---|---| | [...otlin/de/fraunhofer/aisec/cpg/graph/NodeBuilder.kt](https://app.codecov.io/gh/Fraunhofer-AISEC/cpg/pull/1822?src=pr&el=tree&filepath=cpg-core%2Fsrc%2Fmain%2Fkotlin%2Fde%2Ffraunhofer%2Faisec%2Fcpg%2Fgraph%2FNodeBuilder.kt&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Fraunhofer-AISEC#diff-Y3BnLWNvcmUvc3JjL21haW4va290bGluL2RlL2ZyYXVuaG9mZXIvYWlzZWMvY3BnL2dyYXBoL05vZGVCdWlsZGVyLmt0) | `70.53% <100.00%> (+0.26%)` | :arrow_up: | | [...er/aisec/cpg/frontends/python/ExpressionHandler.kt](https://app.codecov.io/gh/Fraunhofer-AISEC/cpg/pull/1822?src=pr&el=tree&filepath=cpg-language-python%2Fsrc%2Fmain%2Fkotlin%2Fde%2Ffraunhofer%2Faisec%2Fcpg%2Ffrontends%2Fpython%2FExpressionHandler.kt&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Fraunhofer-AISEC#diff-Y3BnLWxhbmd1YWdlLXB5dGhvbi9zcmMvbWFpbi9rb3RsaW4vZGUvZnJhdW5ob2Zlci9haXNlYy9jcGcvZnJvbnRlbmRzL3B5dGhvbi9FeHByZXNzaW9uSGFuZGxlci5rdA==) | `75.09% <100.00%> (ø)` | | | [...sec/cpg/frontends/python/PythonLanguageFrontend.kt](https://app.codecov.io/gh/Fraunhofer-AISEC/cpg/pull/1822?src=pr&el=tree&filepath=cpg-language-python%2Fsrc%2Fmain%2Fkotlin%2Fde%2Ffraunhofer%2Faisec%2Fcpg%2Ffrontends%2Fpython%2FPythonLanguageFrontend.kt&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Fraunhofer-AISEC#diff-Y3BnLWxhbmd1YWdlLXB5dGhvbi9zcmMvbWFpbi9rb3RsaW4vZGUvZnJhdW5ob2Zlci9haXNlYy9jcGcvZnJvbnRlbmRzL3B5dGhvbi9QeXRob25MYW5ndWFnZUZyb250ZW5kLmt0) | `76.00% <100.00%> (ø)` | | | [...fer/aisec/cpg/frontends/python/StatementHandler.kt](https://app.codecov.io/gh/Fraunhofer-AISEC/cpg/pull/1822?src=pr&el=tree&filepath=cpg-language-python%2Fsrc%2Fmain%2Fkotlin%2Fde%2Ffraunhofer%2Faisec%2Fcpg%2Ffrontends%2Fpython%2FStatementHandler.kt&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Fraunhofer-AISEC#diff-Y3BnLWxhbmd1YWdlLXB5dGhvbi9zcmMvbWFpbi9rb3RsaW4vZGUvZnJhdW5ob2Zlci9haXNlYy9jcGcvZnJvbnRlbmRzL3B5dGhvbi9TdGF0ZW1lbnRIYW5kbGVyLmt0) | `84.06% <100.00%> (ø)` | | | [...lin/de/fraunhofer/aisec/cpg/helpers/RegionUtils.kt](https://app.codecov.io/gh/Fraunhofer-AISEC/cpg/pull/1822?src=pr&el=tree&filepath=cpg-core%2Fsrc%2Fmain%2Fkotlin%2Fde%2Ffraunhofer%2Faisec%2Fcpg%2Fhelpers%2FRegionUtils.kt&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Fraunhofer-AISEC#diff-Y3BnLWNvcmUvc3JjL21haW4va290bGluL2RlL2ZyYXVuaG9mZXIvYWlzZWMvY3BnL2hlbHBlcnMvUmVnaW9uVXRpbHMua3Q=) | `94.73% <90.90%> (+2.73%)` | :arrow_up: | ... and [1 file with indirect coverage changes](https://app.codecov.io/gh/Fraunhofer-AISEC/cpg/pull/1822/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Fraunhofer-AISEC)

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

oxisto commented 3 weeks ago

LGTM. Only problem I see: newLineTpye isn't the best variable name in my book. Maybe something like lineBreakSequence or fileLineSeperator?

I will rename it to newLineChars