当前位置:网站首页>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 !
边栏推荐
- app闪退
- SOC_AHB_SD_IF
- What does the real name free domain name mean?
- Four tips in numpy
- Skillfully use 5 keys to improve office efficiency
- NFS mount
- [datawhale team learning] task02: mathematical operation, string and text, list
- Problems and solutions of creating topic messages in ROS
- Connection Flood攻击原理
- Record one time of Tencent Test Development Engineer's automation interface test practice experience
猜你喜欢
Go常用命令
[my advanced OpenGL learning journey] about the access methods of vector and matrix classification of OpenGL shaders: xyzw/rgba/stpq and array subscripts
MySQL优化:从十几秒优化到三百毫秒
oracle数据库报列表中最大表达式为1000错误
Rising posture series: fancy debugging information
ROS-URDF
MySQL Optimization: from more than ten seconds to 300 milliseconds
ROS system problem: rosdep init
Go项目目录结构介绍
Class template case - encapsulation of array classes
随机推荐
Linux服务器安装Redis
【转】存储器结构、cache、DMA架构分析
Xshell传输文件
Jingwei Hengrun won the 10ppm quality award of paccar group again
【Hot100】15. 三数之和
How to convert XML to JSON
[semidrive source code analysis] [x9 chip startup process] 34 - RTOS side display module SDM_ display_ Init display initialization source code analysis
Write a C program to judge whether the system is large end byte order or small end byte order
oracle
Egret P2 pit encountered by physical engine (1)
sscanf 函数的使用
Keil - the "trace HW not present" appears during download debugging
Running lantern effect JS text rotation effect realization
【模糊神经网络】基于模糊神经网络的移动机器人路径规划
Steps for formulating class or file templates in idea
Essence of signal slot macros signal and slot
[JSON tutorial] Chapter 1 learning notes
CPU到底是怎么识别代码的?
Four tips in numpy
Out of class implementation of member function of class template