mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 21:21:04 +01:00
Explorer: Mixin phase 1 (#2069)
* Replay changes from pre-force-push mixin branch * Base MixinPseudoType off of the new InterfaceType * Add more test cases. Also removed an unnecessary check that would have already been handled by the parser. * WIP detect member clashes during mixing mixins * Implement fuzzer changes * Implement member name clash check when mixing mixins * Modify parser and lexer for experimental mixin feature * Add comments * Update explorer/testdata/mixin/simple-mix-in-mixin.carbon Co-authored-by: josh11b <josh11b@users.noreply.github.com> * Update explorer/testdata/mixin/use-mixin-method-in-class-method.carbon Co-authored-by: josh11b <josh11b@users.noreply.github.com> * Make code review changes Co-authored-by: josh11b <josh11b@users.noreply.github.com>
This commit is contained in:
co-authored by
josh11b
parent
661a3c3907
commit
037c99e2fb
@@ -52,7 +52,22 @@ void Declaration::Print(llvm::raw_ostream& out) const {
|
||||
out << "}\n";
|
||||
break;
|
||||
}
|
||||
|
||||
case DeclarationKind::MixinDeclaration: {
|
||||
const auto& mixin_decl = cast<MixinDeclaration>(*this);
|
||||
PrintID(out);
|
||||
out << "{\n";
|
||||
for (Nonnull<Declaration*> m : mixin_decl.members()) {
|
||||
out << *m;
|
||||
}
|
||||
out << "}\n";
|
||||
break;
|
||||
}
|
||||
case DeclarationKind::MixDeclaration: {
|
||||
const auto& mix_decl = cast<MixDeclaration>(*this);
|
||||
PrintID(out);
|
||||
out << mix_decl.mixin() << ";";
|
||||
break;
|
||||
}
|
||||
case DeclarationKind::ChoiceDeclaration: {
|
||||
const auto& choice = cast<ChoiceDeclaration>(*this);
|
||||
PrintID(out);
|
||||
@@ -122,7 +137,18 @@ void Declaration::PrintID(llvm::raw_ostream& out) const {
|
||||
out << "class " << class_decl.name();
|
||||
break;
|
||||
}
|
||||
|
||||
case DeclarationKind::MixinDeclaration: {
|
||||
const auto& mixin_decl = cast<MixinDeclaration>(*this);
|
||||
out << "__mixin " << mixin_decl.name();
|
||||
if (mixin_decl.self()->type().kind() != ExpressionKind::TypeTypeLiteral) {
|
||||
out << " for " << mixin_decl.self()->type();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case DeclarationKind::MixDeclaration: {
|
||||
out << "__mix ";
|
||||
break;
|
||||
}
|
||||
case DeclarationKind::ChoiceDeclaration: {
|
||||
const auto& choice = cast<ChoiceDeclaration>(*this);
|
||||
out << "choice " << choice.name();
|
||||
@@ -161,6 +187,12 @@ auto GetName(const Declaration& declaration)
|
||||
return cast<FunctionDeclaration>(declaration).name();
|
||||
case DeclarationKind::ClassDeclaration:
|
||||
return cast<ClassDeclaration>(declaration).name();
|
||||
case DeclarationKind::MixinDeclaration: {
|
||||
return cast<MixinDeclaration>(declaration).name();
|
||||
}
|
||||
case DeclarationKind::MixDeclaration: {
|
||||
return std::nullopt;
|
||||
}
|
||||
case DeclarationKind::ChoiceDeclaration:
|
||||
return cast<ChoiceDeclaration>(declaration).name();
|
||||
case DeclarationKind::InterfaceDeclaration:
|
||||
|
||||
Reference in New Issue
Block a user