#include "cangjie/CHIR/AST2CHIR/TranslateASTNode/Translator.h"
#include "cangjie/CHIR/AST2CHIR/Utils.h"
#include "cangjie/CHIR/Utils/Utils.h"
#include "cangjie/Modules/ModulesUtils.h"
using namespace Cangjie::CHIR;
using namespace Cangjie;
Ptr<Value> Translator::Visit(const AST::StructDecl& decl)
{
auto def = GetNominalSymbolTable(decl);
CJC_ASSERT(def->GetCustomKind() == CustomDefKind::TYPE_STRUCT);
auto structDef = StaticCast<StructDef*>(def.get());
CreateAnnotationInfo<StructDef>(decl, *structDef, structDef);
auto chirType = StaticCast<StructType*>(chirTy.TranslateType(*decl.GetTy()));
structDef->SetType(*chirType);
structDef->Set<LinkTypeInfo>(decl.TestAttr(AST::Attribute::GENERIC_INSTANTIATED)
? Linkage::INTERNAL
: decl.linkage);
const auto& memberDecl = decl.GetMemberDeclPtrs();
for (auto& member : memberDecl) {
if (!ShouldTranslateMember(decl, *member)) {
continue;
}
if (member->astKind == AST::ASTKind::VAR_DECL) {
AddMemberVarDecl(*structDef, *RawStaticCast<const AST::VarDecl*>(member));
} else if (member->astKind == AST::ASTKind::FUNC_DECL) {
auto funcDecl = StaticCast<AST::FuncDecl*>(member);
AddMemberMethodToCustomTypeDef(*funcDecl, *structDef);
} else if (member->astKind == AST::ASTKind::PROP_DECL) {
AddMemberPropDecl(*structDef, *RawStaticCast<const AST::PropDecl*>(member));
} else if (member->astKind == AST::ASTKind::PRIMARY_CTOR_DECL) {
} else {
CJC_ABORT();
}
}
for (auto& superInterfaceTy : decl.GetStableSuperInterfaceTys()) {
auto astType = TranslateType(*superInterfaceTy);
CJC_ASSERT(astType->IsRef());
auto realType = StaticCast<ClassType*>(StaticCast<RefType*>(astType)->GetBaseType());
structDef->AddImplementedInterfaceTy(*realType);
}
return nullptr;
}