rui314 / chibicc

A small C compiler
MIT License
9.57k stars 871 forks source link

Stale comment describing parse rule for `typespec()`. #16

Closed cr1901 closed 3 years ago

cr1901 commented 3 years ago

Consider the following comment:

// typespec = typename typename*
// typename = "void" | "_Bool" | "char" | "short" | "int" | "long"
//            | struct-decl | union-decl | typedef-name

This rule as-is describes (more or less) the type-specifier rule in the C11 standard:

type-specifier:
void
char
short
int
long
float
double
signed
unsigned
_Bool
_Complex
atomic-type-specifier
struct-or-union-specifier
enum-specifier
typedef-name

However, since the typespec function of chibicc also parses storage classes, alignments, etc, I think the comment should mention this. Parsing storage classes, alignments, and the link also makes the "typespec" function more like the declaration_specifiers rule in the C standard:

declaration_specifiers
    : storage_class_specifier declaration_specifiers
    | storage_class_specifier
    | type_specifier declaration_specifiers
    | type_specifier
    | type_qualifier declaration_specifiers
    | type_qualifier
    | function_specifier declaration_specifiers
    | function_specifier
    | alignment_specifier declaration_specifiers
    | alignment_specifier
    ;

So maybe "declspec" might be a better name? I'm not sure.

rui314 commented 3 years ago

I'll update the comment. As to the name of the function, I think "declspec" is a better name as you pointed out.