Closed lucaswerkmeister closed 10 years ago
I’ll almost certainly not use RegularCompilationUnit
. It’s far too long, considering that “regular” really doesn’t mean anything.
@lucaswerkmeister I'm not sure I would do it like this. The current restriction that you can't mix descriptors and declarations might not last forever. I don't see why you need to distinguish between the different kinds of compilation unit.
So you would rather have CompilationUnit(Declaration[] declarations, ModuleDescriptor? mod, PackageDescriptor? dec)
? I don’t like that… it would mean that at the moment, we’d have to assert
that e. g. a module descriptor doesn’t also have declarations. So far, I’ve only used very few assert
s in the node initializers, and instead represented almost every restriction through the type system.
If the language changes, then ceylon.ast
will have to change as well… I wouldn’t try to anticipate every possible language change. Unless there are concrete plans for this change?
We could still have a single class CompilationUnit(Import[] imports, Declaration[]|ModuleDescriptor|PackageDescriptor content)
. But that doesn’t feel good to me either – at least at the moment, the three kinds of compilation units are completely separate, so I don’t see why they should be mashed together like this.
I’m going to implement
AnyCompilationUnit
CompilationUnit
ModuleCompilationUnit
PackageCompilationUnit
now.
Done. The abstract AnyCompilationUnit
has separate fields for declarations and descriptors; this way, AST consumers can use them in such a way that they won’t break when it’s allowed to put mix compilation unit contents freely (they can just ignore that subtypes of AnyCompilationUnit
exist).
The following approach would seem natural, I think:
CompilationUnit
RegularCompilationUnit
, or perhapsCodeCompilationUnit
?ModuleCompilationUnit
PackageCompilationUnit
However, since regular compilation unit is probably going to be the most used type by far, and it’s also probably what most people think of when they hear “compilation unit”, I’m considering something like this instead:
AnyCompilationUnit
CompilationUnit
ModuleCompilationUnit
PackageCompilationUnit