当前位置:网站首页>1285_ Expand macros defined by AUTOSAR functions and variables with scripts to improve readability
1285_ Expand macros defined by AUTOSAR functions and variables with scripts to improve readability
2022-06-30 07:03:00 【grey_ csdn】
All learning summary : https://github.com/GreyZhang/hack_autosar
AUTOSAR Code to read , Get used to non AUTOSAR People with a code style may feel uncomfortable . One of the big reasons may be that the compiler requires some abstract processing .

such as , The above is a typical representative of some definitions .
Actually , I think if the semantic analysis of the code reading tool or code writing tool we use is very strong or weak , None of this is a problem . If it is strong enough, it can automatically process all for us , In fact, our problem today has been solved . But semantic analysis is weak , Even grammar hints are not enough , You may get more information to help you understand the code .
I Believe , Many people don't even have to Source Insight You can also write code with Source Insight Look at the code . But unfortunately , Most of the time, such an analysis will put Source Insight Baffled . and , Sometimes in the face of such definition information, sometimes our brain has to constantly translate , After all, it's a little different from straightforward code expression .
When I do code debugging, I sometimes get confused because of this part , A simple process I have done is to simplify this part directly to ensure that its semantics remain unchanged . and , After the change, you can compare it through compilation hex Is there a change . natural , We hope that our modified presentation will not change the semantics of the code , That is to say hex unchanged .
Similar deployment is actually easy , We only need to do a regular expression matching process to achieve semantic expression .
#!/usr/bin/perl -w
use File::Find;
find(\&process_c_code_file, '.');
sub process_c_code_file
{
if(/\.c$|\.h$/)
{
if($_ ne "Compiler.h")
{
open(CODE, "<$_");
my @code = ;
close CODE;
my $code = join '',@code;
$code =~ s/CONSTP2FUNC\((\w+)\s*,\s*\w+\)/$1 (* const )/g;
$code =~ s/P2FUNC\((\w+)\s*,\s*\w+\)/$1 (*fctname)/g;
$code =~ s/FUNC\((\w+)\s*,\s*\w+\)/$1/g;
$code =~ s/CONSTP2VAR\((\w+)\s*,\s*\w+,\s*\w+\)/$1 * const/g;
$code =~ s/CONSTP2CONST\((\w+)\s*,\s*\w+,\s*\w+\)/const $1 * const/g;
$code =~ s/P2CONST\((\w+)\s*,\s*\w+,\s*\w+\)/const $1 */g;
$code =~ s/P2VAR\((\w+)\s*,\s*\w+,\s*\w+\)/$1 */g;
open(CODE, ">$_");
print CODE "$code";
close CODE;
}
}
}
It's for me to use perl Implementation of a simple small script , The specific script source file can be found in github Link . For the above definition , This script can do some processing .
however , You need to pay attention to different versions of AUTOSAR The abstract representation of this compiler may differ . therefore , Regular expression processing may require some attention , Make some corresponding modifications .
When you use it , Put this script in the code root directory ,cmd In the implementation of perl autosar2common.pl that will do .

The above is the effect of modification , There should be some improvement in readability .
Easy to write , It may not be considerate , If there is bug Welcome to release the fixed version !
边栏推荐
- NFS mount
- It turns out that you are such an array. You have finally learned
- memcpy内存重叠的解决
- 【已实现】服务器jar包启动脚本、shell脚本
- [datawhale team learning] task02: mathematical operation, string and text, list
- Connection Flood攻击原理
- JS null judgment operators | and? Usage of
- [fuzzy neural network] mobile robot path planning based on Fuzzy Neural Network
- 安装Go语言开发工具
- Determine whether the picture is in JPG picture format
猜你喜欢

Deploying web projects using idea

Record one time of Tencent Test Development Engineer's automation interface test practice experience

ROS system problem: rosdep init

RT thread migration to s5p4418 (IV): thread synchronization

Steps for formulating class or file templates in idea

Graphic octet, really top
![[datawhale team learning] task02: mathematical operation, string and text, list](/img/3e/c9c984d7576a2e410da7f81a8c0aa6.jpg)
[datawhale team learning] task02: mathematical operation, string and text, list

vs2019和sql

ROS service communication programming

RT thread Kernel Implementation (II): critical area, object container
随机推荐
SOC project AHB_ SD_ Host controller design
[Hot100]回文子串 与 最长回文子串
[mask RCNN] target detection and recognition based on mask RCNN
ROS-URDF
[semidrive source code analysis] [x9 chip startup process] 34 - RTOS side display module SDM_ display_ Init display initialization source code analysis
Record one time of Tencent Test Development Engineer's automation interface test practice experience
oracle
JS null judgment operators | and? Usage of
Browser downloads files as attachments
成品升级程序
Solr search
[datawhale team learning] task02: mathematical operation, string and text, list
Which securities company is good for opening a mobile account? Also, is it safe to open an account online?
Qdebug small details
Daemon and user threads
【Hot100】11. 盛最多水的容器
[Hot100]10. 正则表达式匹配
[Hot100]10. Regular Expression Matching
Rising posture series: fancy debugging information
Egret engine P2 physics engine (2) - Funny physical phenomenon of small balls hitting the ground