当前位置:网站首页>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 !
边栏推荐
- 【SemiDrive源码分析】【X9芯片启动流程】34 - RTOS侧 Display模块 sdm_display_init 显示初始化源码分析
- SOC_AHB_SD_IF
- Four tips in numpy
- oracle
- Install the components corresponding to setup
- Rising posture series: fancy debugging information
- RT thread Kernel Implementation (V): timer
- [transfer] analysis of memory structure, cache and DMA architecture
- 踩坑记录:supervisor 日志返回信息:redis扩展未安装
- SOC_SD_CLK
猜你喜欢

Daemon and user threads

ROS system problem: rosdep init

leetcode:98. Validate binary search tree

SOC_SD_CLK

Assembly language learning I (with stack co process, 32-bit registers and related instructions, to be continued 06/29)

社招两年半10个公司28轮面试面经
![[hot100] palindrome substring and longest palindrome substring](/img/a5/10dec640f02023c4d55cb42e6309fb.png)
[hot100] palindrome substring and longest palindrome substring
![[fuzzy neural network] mobile robot path planning based on Fuzzy Neural Network](/img/39/c9bf235828b6d50e7931876fa4a918.png)
[fuzzy neural network] mobile robot path planning based on Fuzzy Neural Network

Win10踩坑-开机0xc0000225

Rising posture series: fancy debugging information
随机推荐
Deploying web projects using idea
tomorrow! "Mobile cloud Cup" competition air publicity will start!
Out of class implementation of member function of class template
Write a C program to judge whether the system is large end byte order or small end byte order
【已解决】ERROR 1290 (HY000): Unknown error 1290
Starting MySQL ERROR! Couldn‘t find MySQL server (/usr/local/mysql/bin/mysqld_safe)
Finished product upgrade procedure
[mask RCNN] target detection and recognition based on mask RCNN
免实名域名是什么意思?
No module named 'pyqt5 QtMultimedia‘
Go项目目录结构介绍
First line of code (Third Edition) learning notes
[datawhale team learning] task02: mathematical operation, string and text, list
Traverse map
【Hot100】11. 盛最多水的容器
How to set the hot deployment of idea web project
【转】存储器结构、cache、DMA架构分析
对占用多字节和位的报文信号解析详解
Assembly language learning I (with stack co process, 32-bit registers and related instructions, to be continued 06/29)
MySQL优化:从十几秒优化到三百毫秒