feat(parse): implement # and ## operator handling in macro expansion
- Add support for # (stringify) and ## (concatenation) operators in macro replacement lists - Implement scc_pp_expand_string_unsafe() to process operator tokens during macro expansion - Add helper macros to identify blank, stringify, and concatenation tokens in replacement lists - Include missing headers (ctype.h, string.h) for character handling functions - Update object macro expansion to use new string expansion function instead of simple concatenation - Improve whitespace handling in macro replacement parsing to prevent interference with operator processing
This commit is contained in:
@@ -608,7 +608,7 @@ class GccCompiler(Compiler):
|
||||
flags = {
|
||||
BuildMode.TEST: [
|
||||
"-DTEST_MODE",
|
||||
"-O2",
|
||||
"-O0",
|
||||
"-g",
|
||||
"--coverage",
|
||||
"-fprofile-update=atomic",
|
||||
@@ -648,7 +648,7 @@ class ClangCompiler(Compiler):
|
||||
flags = {
|
||||
BuildMode.TEST: [
|
||||
"-DTEST_MODE",
|
||||
"-O2",
|
||||
"-O0",
|
||||
"-g",
|
||||
"--coverage",
|
||||
"-fprofile-update=atomic",
|
||||
@@ -863,7 +863,7 @@ class PackageBuilder:
|
||||
"""打印依赖树"""
|
||||
self.context.resolver.print_tree()
|
||||
|
||||
def tests(self, filter_str: str = ""):
|
||||
def tests(self, filter_str: str = "", timeout: int = 30):
|
||||
"""运行测试"""
|
||||
targets = [
|
||||
t for t in self.context.get_targets() if t.type == TargetType.TEST_EXEC
|
||||
@@ -890,7 +890,7 @@ class PackageBuilder:
|
||||
for target in targets:
|
||||
logger.info("运行测试: %s", target.name)
|
||||
try:
|
||||
result = subprocess.run(target.output, check=True, timeout=30)
|
||||
result = subprocess.run(target.output, check=True, timeout=timeout)
|
||||
if result.returncode == 0:
|
||||
print(f" ✓ 测试 {target.name} 通过")
|
||||
passed += 1
|
||||
@@ -1066,6 +1066,7 @@ def create_parser():
|
||||
# test 命令
|
||||
test_parser = subparsers.add_parser("test", help="运行测试")
|
||||
add_common_args(test_parser)
|
||||
test_parser.add_argument("--timeout", "-t", type=int, default=3, help="测试时间")
|
||||
test_parser.add_argument("--filter", default="", help="过滤测试")
|
||||
test_parser.set_defaults(mode=BuildMode.TEST)
|
||||
|
||||
@@ -1135,7 +1136,7 @@ def main():
|
||||
builder.run()
|
||||
elif args.command == "test":
|
||||
builder.build([TargetType.TEST_EXEC])
|
||||
builder.tests(getattr(args, "filter", ""))
|
||||
builder.tests(args.filter, args.timeout)
|
||||
elif args.command == "clean":
|
||||
if hasattr(args, "all") and args.all:
|
||||
# 清理所有模式
|
||||
|
||||
53
tools/wc.py
Normal file
53
tools/wc.py
Normal file
@@ -0,0 +1,53 @@
|
||||
"""统计目录下C/C++文件的行数(write by AI)"""
|
||||
|
||||
import os
|
||||
|
||||
|
||||
def count_lines(file_path):
|
||||
"""统计单个文件的代码行数"""
|
||||
try:
|
||||
with open(file_path, "rb") as f: # 二进制模式读取避免编码问题
|
||||
return sum(1 for _ in f)
|
||||
except UnicodeDecodeError:
|
||||
print(f"警告:无法解码文件 {file_path}(可能不是文本文件)")
|
||||
return 0
|
||||
except Exception as e:
|
||||
print(f"读取 {file_path} 出错: {str(e)}")
|
||||
return 0
|
||||
|
||||
|
||||
def scan_files(directory, exclude_dirs=None):
|
||||
"""扫描目录获取所有C/C++文件"""
|
||||
if exclude_dirs is None:
|
||||
exclude_dirs = [".git", "venv", "__pycache__", ".old"] # 默认排除的目录
|
||||
|
||||
c_files = []
|
||||
for root, dirs, files in os.walk(directory):
|
||||
# 跳过排除目录
|
||||
dirs[:] = [d for d in dirs if d not in exclude_dirs]
|
||||
|
||||
for file in files:
|
||||
if file.endswith((".c", ".h")):
|
||||
full_path = os.path.join(root, file)
|
||||
c_files.append(full_path)
|
||||
return c_files
|
||||
|
||||
|
||||
def main():
|
||||
"""main function"""
|
||||
target_dir = input("请输入要扫描的目录路径(留空为当前目录): ") or "."
|
||||
|
||||
files = scan_files(target_dir)
|
||||
total_lines = 0
|
||||
|
||||
print("\n统计结果:")
|
||||
for idx, file in enumerate(files, 1):
|
||||
lines = count_lines(file)
|
||||
total_lines += lines
|
||||
print(f"{idx:4d}. {file} ({lines} 行)")
|
||||
|
||||
print(f"\n总计: {len(files)} 个C/C++文件,共 {total_lines} 行代码")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user