Artifact 4511780717360fbd7501d14e69e16440d06e63aa4228efbbeb53e2f9567ceb73:
- File
test/pic/amalgam-names.awk
— part of check-in
[9dabe49948]
at
2026-11-21 19:00:33
on branch amalgam
— Amalgamation: pic as one pic.c beside the vendored sources, built by one cc line
make amalgamation writes pic-amalgamation-VERSION/ and its tarball; make test-amal builds it from the README's own line and runs crash, print and tools against that binary, and is part of make test-pic. About 60 file-local names that collided in one translation unit take their file's prefix; test/pic/amalgam.sh fails on a new collision. (user: dmestas, size: 2422) [annotate] [blame] [check-ins using] [more...]
# Prints "NAME KIND FILE" for each name a pic source file defines at file scope that two files # could not both define in one translation unit: static functions and variables, typedefs, and # struct, union and enum tags and enumerators. Works on pic's style (definitions start in column # 0, one declaration per line, a struct body's closing "}" in column 0). # Usage: awk -f amalgam-names.awk FILE.c... function out(name, kind) { if (name == "" || name in done) return done[name] = 1 print name, kind, FILENAME } FNR == 1 { delete done; depth = 0; inenum = 0; intd = 0 } { line = $0 sub(/\/\*.*\*\//, "", line) sub(/\/\/.*$/, "", line) } /^#/ { next } inenum { if (line ~ /^[ \t]*[A-Za-z_][A-Za-z0-9_]*/) { e = line; sub(/^[ \t]*/, "", e); sub(/[^A-Za-z0-9_].*$/, "", e) if (e != "") out(e, "enumerator") } if (line ~ /^}/) { inenum = 0 if (intd) { t = line; gsub(/[};, \t]/, "", t); out(t, "typedef") } } next } line ~ /^typedef enum/ || line ~ /^(static )?(const )?enum [A-Za-z_0-9]* *\{/ { if (match(line, /enum [A-Za-z_0-9]+/)) out(substr(line, RSTART + 5, RLENGTH - 5), "tag") intd = (line ~ /^typedef/) if (line ~ /\}/) next inenum = 1; next } line ~ /^typedef struct [A-Za-z_0-9]+ [A-Za-z_0-9]+;/ { n = line; sub(/;.*/, "", n); sub(/^.* /, "", n); out(n, "typedef"); next } line ~ /^typedef .*;$/ { n = line; sub(/;.*$/, "", n) if (n ~ /\(\*/) { sub(/^.*\(\*/, "", n); sub(/\).*$/, "", n) } else { sub(/\[.*$/, "", n); sub(/^.*[ \*]/, "", n) } out(n, "typedef"); next } line ~ /^typedef (struct|union)/ { if (match(line, /(struct|union) [A-Za-z_0-9]+/)) { t = substr(line, RSTART, RLENGTH); sub(/^[a-z]+ /, "", t); out(t, "tag") } td = 1; next } line ~ /^(struct|union) [A-Za-z_0-9]+ *\{/ { t = line; sub(/^[a-z]+ /, "", t); sub(/ *\{.*$/, "", t); out(t, "tag"); next } td && line ~ /^} *[A-Za-z_][A-Za-z0-9_]*;/ { t = line; gsub(/[};, \t]/, "", t); out(t, "typedef"); td = 0; next } line ~ /^static / { if (line ~ /^static (const )?(struct|union|enum) *\{/ || line ~ /^static (const )?struct [A-Za-z_0-9]+ *\{/) { sbody = 1; next } n = line if (n ~ /\(/ && n !~ /^[^(]*=/) { sub(/\(.*$/, "", n); sub(/^.*[ \*]/, "", n); out(n, "static") ; next } sub(/[=;\[].*$/, "", n); sub(/[ \t]+$/, "", n); sub(/^.*[ \*]/, "", n); out(n, "static"); next } sbody && line ~ /^} *[A-Za-z_][A-Za-z0-9_]*[\[;= ]/ { t = line; sub(/^} */, "", t); sub(/[\[;= ].*$/, "", t); out(t, "static"); sbody = 0 }