c2compiler icon indicating copy to clipboard operation
c2compiler copied to clipboard

Redundant code in `Builder.applyAttribute`

Open chqrlie opened this issue 6 months ago • 1 comments

There is redundant code in the function Builder.applyAttribute, can it be removed or was there a reason to make a special case for PrintfFormat that was not completed?

fn void Builder.applyAttribute(Builder* b, Decl* d, const Attr* a) {
    DeclKind dk = d.getKind();
    switch (dk) {
    case Function:
        b.actOnFunctionAttr(d, a);
        break;
    case StructType:
        b.actOnStructAttr(d, a);
        break;
    case EnumType:
        b.actOnTypeAttr(d, a);
        break;
    case FunctionType:
        // store in inner type also (for needed for type decl, other for when used)
        // check result of first, otherwise we get the same error twice
        if (!b.actOnTypeAttr(d, a)) return;

        FunctionTypeDecl* ftd = cast<FunctionTypeDecl*>(d);
        if (a.kind == AttrKind.PrintfFormat) {
            b.applyAttribute(cast<Decl*>(ftd.getDecl()), a);
        } else {
            b.applyAttribute(cast<Decl*>(ftd.getDecl()), a);
        }
        break;
    case AliasType:
        b.actOnTypeAttr(d, a);
        break;
    case Variable:
        b.actOnVarAttr(d, a);
        break;
    default:
        assert(0);
        return;
    }
}

chqrlie avatar Jun 16 '25 06:06 chqrlie

must be some leftover from the past..

bvdberg avatar Jun 16 '25 08:06 bvdberg

fixed

bvdberg avatar Jun 21 '25 05:06 bvdberg