target_list 中的 list_make1 的含义

本文深入探讨了PostgreSQL源码中宏定义的使用方法,特别是list_make1等宏的作用及其实现原理。通过具体示例target_list的定义,展示了如何在语法分析过程中构造列表。
看 gram.y 中的 target_list 的定义:

target_list:                                    
            target_el                { $$ = list_make1($1); }        
            | target_list ',' target_el                { $$ = lappend($1, $3); }        
        ;                            
而list_make1 到底是什么呢?

#define list_make1(x1)              lcons(x1, NIL)
#define list_make2(x1,x2)           lcons(x1, list_make1(x2))
#define list_make3(x1,x2,x3)        lcons(x1, list_make2(x2, x3))
#define list_make4(x1,x2,x3,x4)     lcons(x1, list_make3(x2, x3, x4))
PostgreSQL 中对宏的使用,是否有些随心所欲了。

本文转自健哥的数据花园博客园博客,原文链接:http://www.cnblogs.com/gaojian/archive/2012/09/10/2678215.html,如需转载请自行联系原作者
```cmake #newlib库的裁剪链接 function(add_library_extract_lib_objects target_name source_lib include_object_files exclude_object_files) # 临时工作目录,用于解压和操作目标文件 set(tmp_output_dir ${CMAKE_EXTRACT_LIB_DIR}/ar_extract_objects_tmp/${target_name}) # 最终输出目录,存放生成的新库文件 set(target_output_dir ${CMAKE_EXTRACT_LIB_DIR}/ar_extract_objects_libs/${target_name}) # 新生成的库文件名(格式为lib[target_name].a) set(target_file lib${target_name}.a) set(ar_flags qc) file(MAKE_DIRECTORY ${target_output_dir}) file(MAKE_DIRECTORY ${tmp_output_dir}) set(${target_name}_dependency_list ${source_lib}) add_custom_target(${target_name}_ar_tmp_source ALL COMMAND ${CMAKE_AR} xo "${source_lib}" WORKING_DIRECTORY ${tmp_output_dir}) list(APPEND ${target_name}_dependency_list ${target_name}_ar_tmp_source) list(LENGTH exclude_object_files exclude_object_files_length) if(${exclude_object_files_length} GREATER 0) add_custom_target(${target_name}_exclude_target ALL DEPENDS ${target_name}_ar_tmp_source COMMAND rm -f ${exclude_object_files} WORKING_DIRECTORY ${tmp_output_dir} ) list(APPEND ${target_name}_dependency_list ${target_name}_exclude_target) endif() list(LENGTH include_object_files include_object_files_length) if(${include_object_files_length} GREATER 0) add_custom_target(${target_name}_include_target ALL DEPENDS ${target_name}_ar_tmp_source COMMAND mkdir -p include COMMAND mv ${include_object_files} include/ COMMAND rm -f *.o COMMAND mv include/* . WORKING_DIRECTORY ${tmp_output_dir} ) list(APPEND ${target_name}_dependency_list ${target_name}_include_target) endif() add_custom_command(OUTPUT ${target_output_dir}/${target_file} DEPENDS ${${target_name}_dependency_list} COMMAND rm -f ${target_output_dir}/${target_file} COMMAND ${CMAKE_AR} ${ar_flags} ${target_output_dir}/${target_file} ${tmp_output_dir}/*.o COMMAND rm -f ${tmp_output_dir}/*.o WORKING_DIRECTORY ${target_output_dir} ) add_custom_target(CUSTOM_${target_name} ALL DEPENDS ${target_output_dir}/${target_file}) set_target_properties(CUSTOM_${target_name} PROPERTIES TARGET_FILE ${target_output_dir}/${target_file}) add_library(${target_name} STATIC IMPORTED GLOBAL) set_target_properties(${target_name} PROPERTIES IMPORTED_LOCATION ${target_output_dir}/${target_file} ) add_dependencies(${target_name} CUSTOM_${target_name}) endfunction() 将以上代码添加注释 ```
最新发布
08-23
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值