Skip to content

Commit

Permalink
Merge pull request #27 from sourceryinstitute/revert-26-implement-mul…
Browse files Browse the repository at this point in the history
…ti-var-decls

Revert "(Fortran) Implement multi variable declarations"
  • Loading branch information
ktras committed Apr 22, 2021
2 parents ddcb941 + cb9be73 commit bddec76
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 51 deletions.
19 changes: 8 additions & 11 deletions src/frontend/Experimental_Flang_ROSE_Connection/sage-build.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1040,13 +1040,16 @@ void Build(const parser::TypeDeclarationStmt &x, T* scope)
SgExpression* init = nullptr;
std::list<LanguageTranslation::ExpressionKind> modifier_enum_list;
std::string name{};
std::list<EntityDeclTuple> init_info;

Build(std::get<0>(x.t), base_type); // DeclarationTypeSpec
Build(std::get<1>(x.t), modifier_enum_list); // std::list<AttrSpec>
Build(std::get<2>(x.t), init_info, base_type); // std::list<EntityDecl>
Build(std::get<2>(x.t), name, init, type, base_type); // std::list<EntityDecl>

builder.Enter(var_decl, base_type, init_info);
if (!type) {
type = base_type;
}

builder.Enter(var_decl, name, type, init);
builder.Leave(var_decl, modifier_enum_list);
}

Expand Down Expand Up @@ -1336,21 +1339,15 @@ void Build(const parser::TypeParamValue &x, SgExpression* &expr)
},
x.u);
}
void Build(const std::list<Fortran::parser::EntityDecl> &x, std::list<EntityDeclTuple> &entity_decls, SgType* base_type)

void Build(const std::list<Fortran::parser::EntityDecl> &x, std::string &name, SgExpression* &init, SgType* &type, SgType* base_type)
{
#if PRINT_FLANG_TRAVERSAL
std::cout << "Rose::builder::Build(std::list) for EntityDecl\n";
#endif

for (const auto &elem : x) {
EntityDeclTuple entity_decl;
std::string name;
SgType* type = nullptr;
SgExpression* init = nullptr;

Build(elem, name, init, type, base_type);
entity_decl = std::make_tuple(name, type, init);
entity_decls.push_back(entity_decl);
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/frontend/Experimental_Flang_ROSE_Connection/sage-build.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ class SgType;

#define PRINT_FLANG_TRAVERSAL 0

typedef std::tuple<std::string, SgType*, SgExpression*> EntityDeclTuple;

namespace Rose::builder {

// Converts parsed program to ROSE Sage nodes
Expand Down Expand Up @@ -107,7 +105,7 @@ void Build(const Fortran::parser::DeclarationTypeSpec:: Record&x, SgType* &);

void Build(const Fortran::parser:: DerivedTypeSpec &x, SgType* &);
void Build(const Fortran::parser:: EntityDecl &x, std::string &, SgExpression* &, SgType* &, SgType *);
void Build(const std::list<Fortran::parser::EntityDecl> &x, std::list<EntityDeclTuple> &entity_decls, SgType* base_type);
void Build(const std::list<Fortran::parser:: EntityDecl> &x, std::string &, SgExpression* &, SgType* &, SgType *);
void Build(const Fortran::parser:: AttrSpec &x, LanguageTranslation::ExpressionKind &modifier_enum);
void Build(const Fortran::parser:: ArraySpec &x, SgType* &type, SgType* base_type);
template<typename T> void Build(const Fortran::parser:: CoarraySpec &x, T* scope);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1527,43 +1527,6 @@ Enter(SgVariableDeclaration* &var_decl, const std::string &name, SgType* type, S
SgInitializedName* var_defn = var_def->get_vardefn();
ROSE_ASSERT(var_defn);
ROSE_ASSERT(var_defn == init_name);
}

void SageTreeBuilder::
Enter(SgVariableDeclaration* &var_decl, SgType* base_type, std::list<std::tuple<std::string, SgType*, SgExpression*>> &init_info)
{
mlog[TRACE] << "SageTreeBuilder::Enter(SgVariableDeclaration* &, std::tuple<...>, ...) \n";

// Step through list of tuples to create the multi variable declaration
for (std::list<std::tuple<std::string, SgType*, SgExpression*>>::iterator it = init_info.begin(); it != init_info.end(); ++it) {
std::string name;
SgType* type;
SgExpression* init_expr;
std::tie(name, type, init_expr) = *it;

if (!type) {
type = base_type;
}

if (it == init_info.begin()) { // On first pass, call Enter() to create variable declaration
Enter(var_decl, name, type, init_expr);
} else { // On later passes, create new initialized name and append to the var decl
SgAssignInitializer* init = nullptr;
if (init_expr) {
init = SageBuilder::buildAssignInitializer_nfi(init_expr, type);
}

SgInitializedName* init_name = SageBuilder::buildInitializedName(name, type, init);
var_decl->append_variable(init_name, init);
init_name->set_declptr(var_decl);
}
}
}

void SageTreeBuilder::
Leave(SgVariableDeclaration* var_decl)
{
mlog[TRACE] << "SageTreeBuilder::Leave(SgVariableDeclaration*) \n";

SageInterface::appendStatement(var_decl, SageBuilder::topScopeStack());

Expand Down

0 comments on commit bddec76

Please sign in to comment.