zeek / spicy

C++ parser generator for dissecting protocols & files.
https://docs.zeek.org/projects/spicy
Other
243 stars 37 forks source link

C++ codegen emits definitions where declarations would have been sufficient #1800

Closed bbannier closed 3 weeks ago

bbannier commented 1 month ago

When importing other modules we define full definitions (i.e., function bodies) where declarations would have been sufficient. In fact these definitions are marked inline so we end up having to compile the same body again and again. We do this transitively for all imported modules, so the issue gets worse the longer the import chain and the more types become visible.

# @TEST-EXEC-FAIL: TMPDIR=$PWD spicyc -dj x?.spicy -T # Fail to keep generated files around.

# @TEST-START-FILE x1.spicy
module x1;

public type X1 = unit {
    x1: uint8;
};
# @TEST-END-FILE

# @TEST-START-FILE x2.spicy
module x2;

import x1;

public type X2 = unit {
    x2: uint8;
};
# @TEST-END-FILE

The C++ files emitted for each module contain

It should be possible to drop these definitions for the declarations we already emit.