Skip to content

Commit

Permalink
Updated bootstrap with Lambda invoke and coversion class methods (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
kumarak authored Mar 11, 2024
1 parent 2a3ec2f commit f6e0e9f
Show file tree
Hide file tree
Showing 8 changed files with 176 additions and 126 deletions.
244 changes: 123 additions & 121 deletions bin/BootstrapTypes/Generated.h

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion bin/BootstrapTypes/Globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ std::unordered_map<std::string, std::string> gRetTypeMap{
{"(llvm::ArrayRef<clang::QualType>)", "std::vector<::pasta::Type>"},

// TODO(pag): Better C++ support.
{"(llvm::iterator_range<clang::CXXCtorInitializer *const *>)", "std::vector<pasta::CXXCtorInitializer>"},
{"(llvm::iterator_range<clang::CXXCtorInitializer *const *>)", "std::vector<::pasta::CXXCtorInitializer>"},
{"(llvm::iterator_range<clang::UnresolvedSetIterator>)", "std::vector<::pasta::NamedDecl>"},

{"(llvm::iterator_range<clang::DeclContext::decl_iterator>)", "std::vector<::pasta::Decl>"},
{"(llvm::iterator_range<clang::Decl::redecl_iterator>)", "std::vector<::pasta::Decl>"},
Expand Down Expand Up @@ -1236,6 +1237,7 @@ std::set<std::pair<std::string, std::string>> kCanReturnNullptr{
{"PredefinedExpr", "FunctionName"},
{"OpaqueValueExpr", "SourceExpression"},
{"DependentSizedArrayType", "SizeExpression"},
{"CXXRecordDecl", "LambdaStaticInvoker"},

// {"FunctionProtoType", "EllipsisToken"},
// {"FunctionDecl", "EllipsisToken"},
Expand Down Expand Up @@ -1929,6 +1931,10 @@ std::map<std::pair<std::string, std::string>, std::string> kConditionalNullptr{
" return std::nullopt;\n"
" }\n"
" }\n"},
{{"CXXRecordDecl", "LambdaStaticInvoker"},
" if (!self.getLambdaCallOperator()) {\n"
" return std::nullopt;\n"
" }\n"},
};

std::unordered_map<std::string, uint32_t> gClassIDs;
Expand Down
1 change: 1 addition & 0 deletions bindings/python/src/AST/CXXRecordDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ void RegisterCXXRecordDecl(nb::module_ &m) {
.def_prop_ro("lambda_explicit_template_parameters", &CXXRecordDecl::LambdaExplicitTemplateParameters)
.def_prop_ro("lambda_index_in_context", &CXXRecordDecl::LambdaIndexInContext)
.def_prop_ro("lambda_mangling_number", &CXXRecordDecl::LambdaManglingNumber)
.def_prop_ro("lambda_static_invoker", &CXXRecordDecl::LambdaStaticInvoker)
.def_prop_ro("ms_inheritance_model", &CXXRecordDecl::MSInheritanceModel)
.def_prop_ro("ms_vtor_disp_mode", &CXXRecordDecl::MSVtorDispMode)
.def_prop_ro("most_recent_declaration", &CXXRecordDecl::MostRecentDeclaration)
Expand Down
8 changes: 5 additions & 3 deletions include/pasta/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,7 @@ class ObjCImplementationDecl : public ObjCImplDecl {
::pasta::Token SuperClassToken(void) const;
bool HasDestructors(void) const;
bool HasNonZeroConstructors(void) const;
std::vector<pasta::CXXCtorInitializer> Initializers(void) const;
std::vector<::pasta::CXXCtorInitializer> Initializers(void) const;
std::vector<::pasta::ObjCIvarDecl> InstanceVariables(void) const;
protected:
PASTA_DEFINE_DEFAULT_DECL_CONSTRUCTOR(ObjCImplementationDecl)
Expand Down Expand Up @@ -2900,7 +2900,7 @@ class CXXConstructorDecl : public CXXMethodDecl {
// InheritedConstructor: (clang::InheritedConstructor)
uint32_t NumConstructorInitializers(void) const;
std::optional<::pasta::CXXConstructorDecl> TargetConstructor(void) const;
std::vector<pasta::CXXCtorInitializer> Initializers(void) const;
std::vector<::pasta::CXXCtorInitializer> Initializers(void) const;
bool IsConvertingConstructor(bool) const;
bool IsDefaultConstructor(void) const;
bool IsDelegatingConstructor(void) const;
Expand Down Expand Up @@ -3005,6 +3005,8 @@ class CXXRecordDecl : public RecordDecl {
uint32_t LambdaIndexInContext(void) const;
std::optional<uint32_t> LambdaManglingNumber(void) const;
// LambdaNumbering: (clang::CXXRecordDecl::LambdaNumbering)
std::optional<::pasta::CXXMethodDecl> LambdaStaticInvoker(void) const;
// LambdaStaticInvokerByCC: (clang::CXXMethodDecl *)
std::optional<enum MSInheritanceModel> MSInheritanceModel(void) const;
enum MSVtorDispMode MSVtorDispMode(void) const;
// MemberSpecializationInfo: (clang::MemberSpecializationInfo *)
Expand All @@ -3015,7 +3017,7 @@ class CXXRecordDecl : public RecordDecl {
std::optional<::pasta::CXXRecordDecl> PreviousDeclaration(void) const;
std::optional<::pasta::CXXRecordDecl> TemplateInstantiationPattern(void) const;
enum TemplateSpecializationKind TemplateSpecializationKind(void) const;
// VisibleConversionFunctions: (llvm::iterator_range<clang::UnresolvedSetIterator>)
std::vector<::pasta::NamedDecl> VisibleConversionFunctions(void) const;
std::optional<bool> HasAnyDependentBases(void) const;
std::optional<bool> HasConstexprDefaultConstructor(void) const;
std::optional<bool> HasConstexprDestructor(void) const;
Expand Down
2 changes: 1 addition & 1 deletion include/pasta/AST/Stmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -4022,7 +4022,7 @@ class OverloadExpr : public Expr {
PASTA_DECLARE_BASE_OPERATORS(ValueStmt, OverloadExpr)
PASTA_DECLARE_DERIVED_OPERATORS(OverloadExpr, UnresolvedLookupExpr)
PASTA_DECLARE_DERIVED_OPERATORS(OverloadExpr, UnresolvedMemberExpr)
// Declarations: (llvm::iterator_range<clang::UnresolvedSetIterator>)
std::vector<::pasta::NamedDecl> Declarations(void) const;
::pasta::Token LAngleToken(void) const;
// Name: (clang::DeclarationName)
// NameInfo: (const clang::DeclarationNameInfo &)
Expand Down
15 changes: 15 additions & 0 deletions lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8778,6 +8778,21 @@ std::optional<uint32_t> CXXRecordDecl::LambdaManglingNumber(void) const {
}

// 0: CXXRecordDecl::LambdaNumbering
std::optional<::pasta::CXXMethodDecl> CXXRecordDecl::LambdaStaticInvoker(void) const {
auto &self = *const_cast<clang::CXXRecordDecl *>(u.CXXRecordDecl);
if (!self.getLambdaCallOperator()) {
return std::nullopt;
}
decltype(auto) val = self.getLambdaStaticInvoker();
if (!val) {
return std::nullopt;
}
if (val) {
return DeclBuilder::Create<::pasta::CXXMethodDecl>(ast, val);
}
}

// 1: CXXRecordDecl::LambdaStaticInvokerByCC
// 0: CXXRecordDecl::
std::optional<enum MSInheritanceModel> CXXRecordDecl::MSInheritanceModel(void) const {
auto &self = *const_cast<clang::CXXRecordDecl *>(u.CXXRecordDecl);
Expand Down
13 changes: 13 additions & 0 deletions lib/AST/DeclHead.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,19 @@ std::vector<::pasta::CXXCtorInitializer> CXXConstructorDecl::Initializers(void)
return ret;
}

std::vector<::pasta::NamedDecl> CXXRecordDecl::VisibleConversionFunctions(void) const {
auto &self = *const_cast<clang::CXXRecordDecl *>(u.CXXRecordDecl);
if (!self.hasDefinition()) {
return {};
}
decltype(auto) conversion_functions = self.getVisibleConversionFunctions();
std::vector<::pasta::NamedDecl> ret;
for (auto cf : conversion_functions) {
ret.emplace_back(::pasta::NamedDecl(ast, cf));
}
return ret;
}

#endif // PASTA_IN_BOOTSTRAP

} // namespace pasta
11 changes: 11 additions & 0 deletions lib/AST/StmtManual.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#pragma clang diagnostic ignored "-Wshorten-64-to-32"
#pragma clang diagnostic ignored "-Wbitfield-enum-conversion"
#include <clang/AST/Expr.h>
#include <clang/AST/ExprCXX.h>
#pragma clang diagnostic pop

#include "AST.h"
Expand Down Expand Up @@ -135,6 +136,16 @@ ::pasta::Token Designator::EllipsisToken(void) const noexcept {
return ast->TokenAt(design->getEllipsisLoc());
}

std::vector<::pasta::NamedDecl> OverloadExpr::Declarations(void) const {
auto &self = *const_cast<clang::OverloadExpr *>(u.OverloadExpr);
std::vector<::pasta::NamedDecl> ret;
decltype(auto) declarations = self.decls();
for (auto decl : declarations) {
ret.emplace_back(DeclBuilder::Create<::pasta::NamedDecl>(ast, decl));
}
return ret;
}

#endif // PASTA_IN_BOOTSTRAP

} // namespace pasta

0 comments on commit f6e0e9f

Please sign in to comment.