Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pag/cxx support #130

Merged
merged 56 commits into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
fbe5350
Make it possible to get at the macro token index.
Apr 7, 2024
ad7814e
Rebase with master llvm18 changes
May 6, 2024
119fd8c
Make it possible to convert from a TemplateArgument to an AST.
Apr 9, 2024
5186e69
Fix an issue in bounds with functions declared with typedefs. Fix iss…
Apr 10, 2024
d94420e
Token alignment improvements. Whitespace splitting for trailing inden…
Apr 10, 2024
ffc6328
Finally get rid of a trailing comma in a template argument list.
Apr 10, 2024
d4bda01
Change some return types to .
Apr 11, 2024
ceb2b51
Merge changes to pag/cxx_support (#122)
kumarak Apr 12, 2024
017d330
Rename some methods to make them a bit more regular
Apr 12, 2024
f174c57
Fix python bindings
Apr 12, 2024
7214cfd
Better tracking of token context index for trailing semicolons.
Apr 17, 2024
b3dc36a
Lambda printing and bounds fiddling.
Apr 18, 2024
b529002
Improvements to printing.
Apr 18, 2024
def8b97
Add Macro::ExpansionRange, which provides a slightly more precise Tok…
Apr 18, 2024
7b40509
Commented out tweaks trying to handle deferred expansions differently
Apr 19, 2024
869ad17
Fix a change to an underlying api
Apr 21, 2024
186b1cf
Improvements to lambda handling with bounds and printing.
Apr 23, 2024
e08b502
Add missing builtins from llvm 18 (#123)
kumarak Apr 25, 2024
6417942
Improves bounds for other methods in lambdas. The other methods in la…
Apr 27, 2024
dcbcbbe
Bounds and API improvements.
Apr 28, 2024
4ab20b6
Bounds improvements, especially for constructors/destructors. Improve…
Apr 28, 2024
edde7c1
Improvements to printing. When there's an operator call in a member e…
Apr 29, 2024
ffcfecc
Fix finding balanced locations
May 2, 2024
5cd1bd9
LLVM18 Support (#124)
kumarak May 3, 2024
47b33cf
Upgrade to LLVM18
May 6, 2024
af88c26
Bump LLVM. Only compile vendored with assets when the build config is…
May 6, 2024
7ddafcc
Don't use a generator expression in th eexecute_process
May 7, 2024
c44c5c8
Mark CXXRecordDecl::IsTriviallyCopyConstructible as nullable.
May 7, 2024
c441eb1
Improvements to pretty-printing and bounds.
May 8, 2024
ead7c62
Add FunctionDecl::TemplateArguments. Add more methods to TemplateArgu…
May 9, 2024
3dee887
Fix script.
May 9, 2024
3237a63
Fix nullptr access on getting template specialization (#125)
kumarak May 9, 2024
3c56184
Add back TArgAsWritten getting used to print template arguments
kumarak May 9, 2024
03be0cd
Don't print commas when they're not needed.
May 9, 2024
551b73b
Whitespace injection into type printing.
May 9, 2024
f7a26d9
Minor fixes to improve whitespace injection.
May 9, 2024
5df96a5
Token printer improvements. Fix to checking trailing tokens.
May 10, 2024
8ab4578
General improvements. Fixes some issues related to token contexts.
May 10, 2024
a75eeb6
Add checks for lambda static invoker and other implicit methods (#126)
kumarak May 10, 2024
194f530
Fix source range for Argument pack (#127)
kumarak May 10, 2024
0c91a1a
Handle bounds for explicit specialization (#128)
kumarak May 13, 2024
b30df3f
Fix bounds for friend decls.
May 14, 2024
fb1ac8f
Don't use deprecated FileEntry api. Add DeclContext::operator==.
May 14, 2024
46cc916
Add PrintedTokenRange::Create for a vector of decls.
May 15, 2024
9882844
Sort of but not really fixes for cxx deduction guide bounds. Made it …
May 17, 2024
c989f4d
Don't visit function type locs.
May 17, 2024
39f4b6f
Remapping tweaks in bounds.
May 17, 2024
5d7f022
Expand backwards through ::.
May 17, 2024
f5f8b7a
Bounds fixes for function template specializations.
May 17, 2024
48e2163
Sort of but not quite fix an assertion. Really, for parameters of spe…
May 17, 2024
36673a7
Bug fix.
May 17, 2024
753c3b9
Bounds improvements.
May 17, 2024
6cd6368
Bug fix
May 18, 2024
e18aa92
Re-bootstrap for nullable return type.
May 18, 2024
9870a01
Bump LLVM
May 18, 2024
8f00601
Bump PASTA.
May 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ add_library(pasta_compiler STATIC
"lib/Compile/Diagnostic.cpp"
"lib/Compile/FileSystem.cpp"
"lib/Compile/Job.cpp"
"lib/Compile/ParsedFileTracker.cpp"
"lib/Compile/PatchedMacroTracker.cpp"
"lib/Compile/Preprocess.cpp"
"lib/Compile/Run.cpp"
Expand Down
18 changes: 9 additions & 9 deletions bin/BootstrapTypes/DeclareCppMethods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ static std::unordered_multimap<std::string, std::tuple<llvm::StringRef, llvm::St

static void CollectGetNumMethod(const std::string &class_name,
llvm::StringRef rt) {
if (meth_name_ref.startswith("get") && meth_name_ref.contains("Num") &&
if (meth_name_ref.starts_with("get") && meth_name_ref.contains("Num") &&
rt == "(unsigned int)") {
std::tuple<llvm::StringRef, llvm::StringRef> t{meth_name_ref, rt};
class_methods0.emplace(class_name, std::move(t));

if (meth_name_ref.startswith("getNum")) {
if (meth_name_ref.endswith("s")) {
if (meth_name_ref.starts_with("getNum")) {
if (meth_name_ref.ends_with("s")) {
get_num_method.emplace(
meth_name_ref.substr(6, meth_name_ref.size() - 7).str(),
meth_name_ref);
Expand All @@ -54,7 +54,7 @@ static void CollectGetNumMethod(const std::string &class_name,
ss << meth_name_ref[i];
}
auto len = meth_name_ref.size();
if (meth_name_ref.endswith("s")) {
if (meth_name_ref.ends_with("s")) {
len -= 1;
}
for (auto i = max_i + 3; i < len; ++i) {
Expand All @@ -65,9 +65,9 @@ static void CollectGetNumMethod(const std::string &class_name,
}

// List form, returns an array of pointers.
} else if (rt.endswith(" *const *)") &&
meth_name_ref.startswith("get") &&
meth_name_ref.endswith("s")) {
} else if (rt.ends_with(" *const *)") &&
meth_name_ref.starts_with("get") &&
meth_name_ref.ends_with("s")) {

std::tuple<llvm::StringRef, llvm::StringRef> t{meth_name_ref, rt};
class_methods0.emplace(class_name, std::move(t));
Expand All @@ -85,7 +85,7 @@ static void CollectGetNumMethod(const std::string &class_name,

static void CollectGetNthMethod(const std::string &class_name,
llvm::StringRef p0, llvm::StringRef rt) {
if (p0 == "(unsigned int)" && meth_name_ref.startswith("get")) {
if (p0 == "(unsigned int)" && meth_name_ref.starts_with("get")) {
std::tuple<llvm::StringRef, llvm::StringRef, llvm::StringRef> t{meth_name_ref, p0, rt};
class_methods1.emplace(class_name, std::move(t));

Expand All @@ -105,7 +105,7 @@ static void CollectGetNthMethod(const std::string &class_name,
static void DeclareCppMethod0(std::ostream &os, const std::string &class_name,
const char *meth, const char *rt) {
meth_name_ref = meth;
if (meth_name_ref.endswith("Unsafe")) {
if (meth_name_ref.ends_with("Unsafe")) {
return;
}
// `NamedDecl::getName` has an assertion in it where `getNameAsString` does
Expand Down
64 changes: 32 additions & 32 deletions bin/BootstrapTypes/DeclareEnums.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ static llvm::StringRef enumerator_name;
static std::string RenameEnum(llvm::StringRef name) {
if (name == "AttrKind") {
return name.str();
} else if (name.endswith("_t")) {
} else if (name.ends_with("_t")) {
return RenameEnum(name.substr(0, name.size() - 2));
} else if (name == "Nonce_ObjCInterface") {
return "NonceObjCInterface";
Expand All @@ -34,11 +34,11 @@ static std::string RenameEnum(llvm::StringRef name) {

static bool AcceptEnumerator(const std::string &name) {
return !enumerator_name.empty() &&
!enumerator_name.startswith("first") &&
!enumerator_name.startswith("last") &&
!enumerator_name.startswith("First") &&
!enumerator_name.startswith("Last") &&
!enumerator_name.endswith("Last") &&
!enumerator_name.starts_with("first") &&
!enumerator_name.starts_with("last") &&
!enumerator_name.starts_with("First") &&
!enumerator_name.starts_with("Last") &&
!enumerator_name.ends_with("Last") &&
enumerator_name != "NoStmtClass" &&
enumerator_name != "NUM_TOKENS" &&
enumerator_name != "NUM_PP_KEYWORDS" &&
Expand All @@ -59,99 +59,99 @@ static std::string RenameEnumeratorInternal(const std::string &name) {
} else if (enumerator_name == "C23_Noreturn") {
return "C23_Noreturn";

} else if (enumerator_name.endswith("less")) {
} else if (enumerator_name.ends_with("less")) {
enumerator_name = enumerator_name.substr(0, enumerator_name.size() - 4);
return RenameEnumeratorInternal(name) + "Less";

} else if (enumerator_name.endswith("greater")) {
} else if (enumerator_name.ends_with("greater")) {
enumerator_name = enumerator_name.substr(0, enumerator_name.size() - 7);
return RenameEnumeratorInternal(name) + "Greater";

} else if (enumerator_name.endswith("equal")) {
} else if (enumerator_name.ends_with("equal")) {
enumerator_name = enumerator_name.substr(0, enumerator_name.size() - 5);
return RenameEnumeratorInternal(name) + "Equal";

} else if (enumerator_name.endswith("pipe")) {
} else if (enumerator_name.ends_with("pipe")) {
enumerator_name = enumerator_name.substr(0, enumerator_name.size() - 4);
return RenameEnumeratorInternal(name) + "Pipe";

} else if (enumerator_name.endswith("colon")) {
} else if (enumerator_name.ends_with("colon")) {
enumerator_name = enumerator_name.substr(0, enumerator_name.size() - 5);
return RenameEnumeratorInternal(name)+ "Colon";

} else if (enumerator_name.endswith("plus")) {
} else if (enumerator_name.ends_with("plus")) {
enumerator_name = enumerator_name.substr(0, enumerator_name.size() - 4);
return RenameEnumeratorInternal(name) + "Plus";

} else if (enumerator_name.endswith("minus")) {
} else if (enumerator_name.ends_with("minus")) {
enumerator_name = enumerator_name.substr(0, enumerator_name.size() - 5);
return RenameEnumeratorInternal(name) + "Minus";

} else if (enumerator_name.endswith("hash")) {
} else if (enumerator_name.ends_with("hash")) {
enumerator_name = enumerator_name.substr(0, enumerator_name.size() - 4);
return RenameEnumeratorInternal(name) + "Hash";

} else if (enumerator_name.endswith("amp")) {
} else if (enumerator_name.ends_with("amp")) {
enumerator_name = enumerator_name.substr(0, enumerator_name.size() - 3);
return RenameEnumeratorInternal(name) + "Amp";

} else if (enumerator_name.endswith("star")) {
} else if (enumerator_name.ends_with("star")) {
enumerator_name = enumerator_name.substr(0, enumerator_name.size() - 4);
return RenameEnumeratorInternal(name) + "Star";

} else if (enumerator_name.endswith("_begin")) {
} else if (enumerator_name.ends_with("_begin")) {
enumerator_name = enumerator_name.substr(0, enumerator_name.size() - 6);
return RenameEnumeratorInternal(name) + "Begin";

} else if (enumerator_name.endswith("_end")) {
} else if (enumerator_name.ends_with("_end")) {
enumerator_name = enumerator_name.substr(0, enumerator_name.size() - 4);
return RenameEnumeratorInternal(name) + "End";

} else if (enumerator_name.endswith("_size")) {
} else if (enumerator_name.ends_with("_size")) {
enumerator_name = enumerator_name.substr(0, enumerator_name.size() - 5);
return RenameEnumeratorInternal(name) + "Size";

} else if (enumerator_name.endswith("_alloc")) {
} else if (enumerator_name.ends_with("_alloc")) {
enumerator_name = enumerator_name.substr(0, enumerator_name.size() - 6);
return RenameEnumeratorInternal(name) + "Alloc";

} else if (enumerator_name.endswith("_Alignas")) {
} else if (enumerator_name.ends_with("_Alignas")) {
enumerator_name = enumerator_name.substr(0, enumerator_name.size() - 8);
return RenameEnumeratorInternal(name) + "_Alignas";

} else if (enumerator_name.startswith("kw_")) {
} else if (enumerator_name.starts_with("kw_")) {
enumerator_name = enumerator_name.substr(3);
return "Keyword" + RenameEnumeratorInternal(name);

} else if (enumerator_name.startswith("pp_") && name == "PPKeywordKind") {
} else if (enumerator_name.starts_with("pp_") && name == "PPKeywordKind") {
enumerator_name = enumerator_name.substr(3);
return RenameEnumeratorInternal(name);

} else if (enumerator_name.startswith("objc_") && name == "ObjCKeywordKind") {
} else if (enumerator_name.starts_with("objc_") && name == "ObjCKeywordKind") {
enumerator_name = enumerator_name.substr(5);
return RenameEnumeratorInternal(name);

} else if (enumerator_name.startswith("is_")) {
} else if (enumerator_name.starts_with("is_")) {
enumerator_name = enumerator_name.substr(3);
return "Is" + RenameEnumeratorInternal(name);

} else if (enumerator_name.startswith("has_")) {
} else if (enumerator_name.starts_with("has_")) {
enumerator_name = enumerator_name.substr(4);
return "Has" + RenameEnumeratorInternal(name);

} else if (enumerator_name.startswith("_is_")) {
} else if (enumerator_name.starts_with("_is_")) {
enumerator_name = enumerator_name.substr(4);
return "_Is" + RenameEnumeratorInternal(name);

} else if (enumerator_name.startswith("_has_")) {
} else if (enumerator_name.starts_with("_has_")) {
enumerator_name = enumerator_name.substr(5);
return "_Has" + RenameEnumeratorInternal(name);

} else if (enumerator_name.startswith("__is_")) {
} else if (enumerator_name.starts_with("__is_")) {
enumerator_name = enumerator_name.substr(5);
return "__Is" + RenameEnumeratorInternal(name);

} else if (enumerator_name.startswith("__has_")) {
} else if (enumerator_name.starts_with("__has_")) {
enumerator_name = enumerator_name.substr(6);
return "__Has" + RenameEnumeratorInternal(name);

Expand All @@ -163,7 +163,7 @@ static std::string RenameEnumeratorInternal(const std::string &name) {
return "Empty";
}

if (name == "StmtKind" && enumerator_name.endswith("Class")) {
if (name == "StmtKind" && enumerator_name.ends_with("Class")) {
return Capitalize(enumerator_name.substr(
0, enumerator_name.size() - 5));

Expand Down Expand Up @@ -222,7 +222,7 @@ static std::string RenameEnumerator(const std::string &name) {
#define PASTA_NAMED_ENUMERATOR(enumerator_name_, underlying_type, val) \
enumerator_name = #enumerator_name_; \
for (auto prefix : kEnumPrefixesToStrip) { \
if (enumerator_name.startswith(prefix)) { \
if (enumerator_name.starts_with(prefix)) { \
enumerator_name = enumerator_name.substr(prefix.size()); \
break; \
} \
Expand Down
19 changes: 11 additions & 8 deletions bin/BootstrapTypes/DefineCppMethods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ static void DefineCppMethod0(std::ostream &os, const std::string &class_name,
llvm::StringRef meth_name_ref,
llvm::StringRef rt_ref, std::ostream &os_py) {

if (meth_name_ref.endswith("Unsafe")) {
if (meth_name_ref.ends_with("Unsafe")) {
return;
}

Expand Down Expand Up @@ -123,7 +123,7 @@ static void DefineCppMethod0(std::ostream &os, const std::string &class_name,
handled_null_ret = true;
}
os << " decltype(auto) val = self." << meth_name_ref.str() << "();\n";
if (rt_ref.endswith("QualType)")) {
if (rt_ref.ends_with("QualType)")) {
if (can_ret_null) {
os
<< " if (val.isNull()) {\n"
Expand All @@ -132,10 +132,13 @@ static void DefineCppMethod0(std::ostream &os, const std::string &class_name,
<< rt_val;
} else {
os
<< " assert(!val.isNull());\n"
<< " if (val.isNull()) {\n"
<< " assert(false);\n"
<< " val = ast->ci->getASTContext().UnresolvedTy;\n"
<< " }\n"
<< rt_val;
}
} else if (rt_ref.endswith(" *)")) {
} else if (rt_ref.ends_with(" *)")) {
if (can_ret_null) {
os
<< " if (!val) {\n"
Expand Down Expand Up @@ -202,7 +205,7 @@ static void DefineCppMethod1(std::ostream &os, const std::string &class_name,
handled_null_ret = true;
}
os << " decltype(auto) val = self." << meth_name_ref.str() << "(ast->ci->getASTContext());\n";
if (rt_ref.endswith("QualType)")) {
if (rt_ref.ends_with("QualType)")) {
if (can_ret_null) {
os
<< " if (val.isNull()) {\n"
Expand All @@ -213,7 +216,7 @@ static void DefineCppMethod1(std::ostream &os, const std::string &class_name,
os << " assert(!val.isNull());\n"
<< rt_val;
}
} else if (rt_ref.endswith(" *)")) {
} else if (rt_ref.ends_with(" *)")) {
if (can_ret_null) {
os
<< " if (!val) {\n"
Expand Down Expand Up @@ -248,7 +251,7 @@ static void DefineCppMethod1(std::ostream &os, const std::string &class_name,
os << " auto &self = *(u." << class_name << ");\n";
}
os << " decltype(auto) val = self." << meth_name_ref.str() << "(b);\n";
if (rt_ref.endswith("QualType)")) {
if (rt_ref.ends_with("QualType)")) {
if (can_ret_null) {
os
<< " if (val.isNull()) {\n"
Expand All @@ -259,7 +262,7 @@ static void DefineCppMethod1(std::ostream &os, const std::string &class_name,
os << " assert(!val.isNull());\n"
<< rt_val;
}
} else if (rt_ref.endswith(" *)")) {
} else if (rt_ref.ends_with(" *)")) {
if (can_ret_null) {
os
<< " if (!val) {\n"
Expand Down
6 changes: 3 additions & 3 deletions bin/BootstrapTypes/GenerateAttrH.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ void GenerateAttrH(void) {
// Make sure all of the `::From` methods inherited from the parent class
// are private, so that this class "overrides" them with more derived
// versions.
if (name_ref.endswith("Attr")) {
if (name_ref.ends_with("Attr")) {
os
<< " private:\n";
for (const auto &parent_class : gBaseClasses[name]) {
Expand All @@ -147,7 +147,7 @@ void GenerateAttrH(void) {
<< " PASTA_DECLARE_DEFAULT_CONSTRUCTORS(" << name << ")\n";

// Constructors from derived class -> base class.
if (name_ref.endswith("Attr")) {
if (name_ref.ends_with("Attr")) {
for (const auto &base_class : gTransitiveBaseClasses[name]) {
os << " PASTA_DECLARE_BASE_OPERATORS(" << base_class << ", "
<< name << ")\n";
Expand All @@ -168,7 +168,7 @@ void GenerateAttrH(void) {

// Requiring that all derivations have the same size as the base class
// will let us do fun sketchy things.
if (name != "Attr" && name_ref.endswith("Attr")) {
if (name != "Attr" && name_ref.ends_with("Attr")) {
os << "static_assert(sizeof(Attr) == sizeof(" << name << "));\n\n";
}
}
Expand Down
16 changes: 14 additions & 2 deletions bin/BootstrapTypes/GenerateDeclCpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ void Register)" << name << "(nb::module_ &m) {\n"
}

// Constructors from derived class -> base class.
if (name_ref.endswith("Decl")) {
if (name_ref.ends_with("Decl")) {

if (derived_from_decl_context.count(name)) {
os << "PASTA_DEFINE_BASE_OPERATORS(DeclContext, "
Expand Down Expand Up @@ -412,9 +412,21 @@ void Register)" << name << "(nb::module_ &m) {\n"
<< " } else {\n"
<< " return std::nullopt;\n"
<< " }\n"
<< "}\n\n"
<< "std::vector<::pasta::TemplateArgument> FunctionDecl::TemplateArguments(void) const noexcept {\n"
<< " const clang::FunctionDecl *decl = u.FunctionDecl;\n"
<< " std::vector<::pasta::TemplateArgument> ret;\n"
<< " if (auto args = decl->getTemplateSpecializationArgs()) {\n"
<< " for (auto &arg : args->asArray()) {\n"
<< " ret.emplace_back(ast, &arg);\n"
<< " }\n"
<< " }\n"
<< " return ret;\n"
<< "}\n\n";

os_py << "\n .def_prop_ro(\"body\", &" << name << "::Body)";
os_py
<< "\n .def_prop_ro(\"body\", &" << name << "::Body)"
<< "\n .def_prop_ro(\"template_arguments\", &" << name << "::TemplateArguments)";
}
os_py << ";\n"
<< "}\n"
Expand Down
Loading
Loading