Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 10 additions & 0 deletions ast_canopy/ast_canopy/decl.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,11 @@ def __init__(

self.parse_entry_point = parse_entry_point

def __repr__(self) -> str:
name = self.function.name
tparam_names = [t.name for t in self.template_parameters]
return f"{name}<{','.join(tparam_names)}>"

@classmethod
def from_c_obj(
cls, c_obj: bindings.FunctionTemplate, parse_entry_point: str
Expand Down Expand Up @@ -373,6 +378,11 @@ def __init__(

self.parse_entry_point = parse_entry_point

def __repr__(self) -> str:
name = self.record.name
tparam_names = [t.name for t in self.template_parameters]
return f"{name}<{','.join(tparam_names)}>"

@classmethod
def from_c_obj(cls, c_obj: bindings.ClassTemplate, parse_entry_point: str):
return cls(
Expand Down
11 changes: 6 additions & 5 deletions ast_canopy/ast_canopy/instantiations.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def validate(self):
@property
def param_list(self):
return [
self.instantiated_args[tparam.name]
self.instantiated_args.get(tparam.name, None)
for tparam in self.template_parameters
]

Expand All @@ -42,10 +42,11 @@ def get_instantiated_c_stmt(self) -> str:

flatten = []
for param in param_list:
if isinstance(param, BaseInstantiation):
flatten.append(param.get_instantiated_c_stmt())
else:
flatten.append(str(param))
if param is not None:
if isinstance(param, BaseInstantiation):
flatten.append(param.get_instantiated_c_stmt())
else:
flatten.append(str(param))

param_list = ", ".join(flatten)
return f"{name}<{param_list}>"
Expand Down
1 change: 1 addition & 0 deletions ast_canopy/ast_canopy/pylibastcanopy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ PYBIND11_MODULE(pylibastcanopy, m) {
.def_readwrite("name", &TemplateParam::name)
.def_readwrite("type_", &TemplateParam::type)
.def_readwrite("kind", &TemplateParam::kind)
.def_readwrite("is_parameter_pack", &TemplateParam::is_parameter_pack)
.def("__repr__",
[](const TemplateParam &t) {
return "<TemplateParam: " + t.name + " " + t.type.name + ">";
Expand Down
1 change: 1 addition & 0 deletions ast_canopy/cpp/include/ast_canopy/ast_canopy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ struct TemplateParam {
std::string name;
template_param_kind kind;
Type type;
bool is_parameter_pack;
};

struct Function {
Expand Down
2 changes: 2 additions & 0 deletions ast_canopy/cpp/src/template_param.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ TemplateParam::TemplateParam(const clang::TemplateTypeParmDecl *TPD) {
name = TPD->getNameAsString();
type = Type(TPD->getASTContext().getTypeDeclType(TPD), TPD->getASTContext());
kind = template_param_kind::type;
is_parameter_pack = TPD->isParameterPack();
}

TemplateParam::TemplateParam(const clang::NonTypeTemplateParmDecl *TPD) {
name = TPD->getNameAsString();
type = Type(TPD->getType(), TPD->getASTContext());
kind = template_param_kind::non_type;
is_parameter_pack = TPD->isParameterPack();
}

TemplateParam::TemplateParam(const clang::TemplateTemplateParmDecl *TPD) {
Expand Down