当前位置:网站首页>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 !
边栏推荐
- 1285_把AUTOSAR函数以及变量等定义的宏用脚本展开以提高可读性
- RT thread migration to s5p4418 (IV): thread synchronization
- How to convert XML to JSON
- Egret engine P2 physics engine (2) - Funny physical phenomenon of small balls hitting the ground
- ROS service communication programming
- oracle数据库报列表中最大表达式为1000错误
- Linu foundation - zoning planning and use
- Porting RT thread to s5p4418 (V): thread communication
- June 29, 2022 -- take the first step with C # -- add decision logic to the code using the "if", "else" and "else if" statements in C #
- leetcode:98. Validate binary search tree
猜你喜欢
随机推荐
memcpy内存重叠的解决
6、 Shopping ⻋ and orders
June 29, 2022 -- take the first step with C # -- add decision logic to the code using the "if", "else" and "else if" statements in C #
What does the real name free domain name mean?
Class templates and friends
RT thread migration to s5p4418 (III): static memory pool management
1285_把AUTOSAR函数以及变量等定义的宏用脚本展开以提高可读性
ftplib+ tqdm 上传下载进度条
IDEA import导入的类明明存在,却飘红?
app闪退
MySQL优化:从十几秒优化到三百毫秒
Cmake post makefile:32: * * * missing separator Stop.
我开户后把账号忘记了咋办?股票在网上开户安全吗?
Browser downloads files as attachments
Go语言指针介绍
【已实现】服务器jar包启动脚本、shell脚本
【Hot100】11. 盛最多水的容器
Qdebug small details
Four great happenings on earth
RT thread Kernel Implementation (III): implementation of idle threads and blocking delay








