"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/frontend/Experimental_Ada_ROSE_Connection/AdaExpression.C" between
rose-0.11.35.0.tar.gz and rose-0.11.36.0.tar.gz

About: ROSE is a compiler infrastructure to build source-to-source program transformation and analysis tools for large-scale C (C89 and C98), C++ (C++98 and C++11), UPC, Fortran (77/95/2003), OpenMP, Java, Python and PHP applications.

AdaExpression.C  (rose-0.11.35.0):AdaExpression.C  (rose-0.11.36.0)
skipping to change at line 34 skipping to change at line 34
// \todo move to AdaType file and include that // \todo move to AdaType file and include that
SgType& SgType&
getDeclTypeID(Element_ID id, AstContext ctx); getDeclTypeID(Element_ID id, AstContext ctx);
namespace namespace
{ {
SgExpression& SgExpression&
getArg(Element_Struct& elem, AstContext ctx) getArg(Element_Struct& elem, AstContext ctx)
{ {
ROSE_ASSERT(elem.Element_Kind == An_Association); ADA_ASSERT(elem.Element_Kind == An_Association);
Association_Struct& assoc = elem.The_Union.Association; Association_Struct& assoc = elem.The_Union.Association;
ROSE_ASSERT( assoc.Association_Kind == A_Parameter_Association ADA_ASSERT( assoc.Association_Kind == A_Parameter_Association
|| assoc.Association_Kind == A_Pragma_Argument_Association || assoc.Association_Kind == A_Pragma_Argument_Association
); );
logKind( assoc.Association_Kind == A_Parameter_Association logKind( assoc.Association_Kind == A_Parameter_Association
? "A_Parameter_Association" ? "A_Parameter_Association"
: "A_Pragma_Argument_Association" : "A_Pragma_Argument_Association"
); );
SgExpression& arg = getExprID(assoc.Actual_Parameter, ctx); SgExpression& arg = getExprID(assoc.Actual_Parameter, ctx);
Element_Struct* formalParm = retrieveAsOpt<Element_Struct>(elemMap(), as soc.Formal_Parameter); Element_Struct* formalParm = retrieveAsOpt<Element_Struct>(elemMap(), as soc.Formal_Parameter);
/* unused fields (A_Parameter_Association) /* unused fields (A_Parameter_Association)
bool Is_Normalized bool Is_Normalized
bool Is_Defaulted_Association bool Is_Defaulted_Association
*/ */
if (!formalParm) return arg; if (!formalParm) return arg;
ROSE_ASSERT(formalParm->Element_Kind == An_Expression); ADA_ASSERT(formalParm->Element_Kind == An_Expression);
Expression_Struct& formalName = formalParm->The_Union.Expression; Expression_Struct& formalName = formalParm->The_Union.Expression;
ROSE_ASSERT(formalName.Expression_Kind == An_Identifier); ADA_ASSERT(formalName.Expression_Kind == An_Identifier);
logKind("An_Identifier"); logKind("An_Identifier");
SgExpression& namedArg = SG_DEREF(sb::buildActualArgumentExpression(fo rmalName.Name_Image, &arg)); SgExpression& namedArg = SG_DEREF(sb::buildActualArgumentExpression(fo rmalName.Name_Image, &arg));
attachSourceLocation(namedArg, elem, ctx); attachSourceLocation(namedArg, elem, ctx);
return namedArg; return namedArg;
} }
} }
namespace namespace
skipping to change at line 104 skipping to change at line 104
void handle(SgUnaryOp& n) void handle(SgUnaryOp& n)
{ {
// computed target ? // computed target ?
if (n.get_operand() != nullptr) if (n.get_operand() != nullptr)
{ {
mkCall(n); mkCall(n);
return; return;
} }
ROSE_ASSERT(range.size() == 1); ADA_ASSERT(range.size() == 1);
std::vector<SgExpression*> args = computeArguments(); std::vector<SgExpression*> args = computeArguments();
ROSE_ASSERT(args.size() == 1); ADA_ASSERT(args.size() == 1);
n.set_operand(args[0]); n.set_operand(args[0]);
res = &n; res = &n;
} }
void handle(SgBinaryOp& n) void handle(SgBinaryOp& n)
{ {
// lhs and rhs must be null or not-null // lhs and rhs must be null or not-null
ROSE_ASSERT((n.get_lhs_operand() == nullptr) == (n.get_rhs_operand() == nu llptr)); ADA_ASSERT((n.get_lhs_operand() == nullptr) == (n.get_rhs_operand() == nul lptr));
// computed target ? // computed target ?
if (n.get_lhs_operand() != nullptr) if (n.get_lhs_operand() != nullptr)
{ {
mkCall(n); mkCall(n);
return; return;
} }
ROSE_ASSERT(range.size() == 2); ADA_ASSERT(range.size() == 2);
std::vector<SgExpression*> args = computeArguments(); std::vector<SgExpression*> args = computeArguments();
ROSE_ASSERT(args.size() == 2); ADA_ASSERT(args.size() == 2);
n.set_lhs_operand(args[0]); n.set_lhs_operand(args[0]);
n.set_rhs_operand(args[1]); n.set_rhs_operand(args[1]);
res = &n; res = &n;
} }
ElemIdRange range; ElemIdRange range;
AstContext ctx; AstContext ctx;
}; };
struct ArrayAggregateCreator struct ArrayAggregateCreator
skipping to change at line 170 skipping to change at line 170
private: private:
const bool namedElements; const bool namedElements;
AstContext ctx; AstContext ctx;
std::vector<SgExpression*> elems; std::vector<SgExpression*> elems;
ArrayAggregateCreator() = delete; ArrayAggregateCreator() = delete;
}; };
void ArrayAggregateCreator::operator()(Element_Struct& el) void ArrayAggregateCreator::operator()(Element_Struct& el)
{ {
ROSE_ASSERT(el.Element_Kind == An_Association); ADA_ASSERT(el.Element_Kind == An_Association);
Association_Struct& assoc = el.The_Union.Association; Association_Struct& assoc = el.The_Union.Association;
ROSE_ASSERT(assoc.Association_Kind == An_Array_Component_Association); ADA_ASSERT(assoc.Association_Kind == An_Array_Component_Association);
logKind("An_Array_Component_Association"); logKind("An_Array_Component_Association");
SgExpression& init = getExprID(assoc.Component_Expression, ct x); SgExpression& init = getExprID(assoc.Component_Expression, ct x);
SgExpression* sgnode = &init; SgExpression* sgnode = &init;
ElemIdRange range = idRange(assoc.Array_Component_Choices); ElemIdRange range = idRange(assoc.Array_Component_Choices);
ROSE_ASSERT(namedElements || range.size() < 2); ADA_ASSERT(namedElements || range.size() < 2);
if (!range.empty()) if (!range.empty())
{ {
std::vector<SgExpression*> exprs = traverseIDs(range, elemMap(), ExprSeqCr eator{ctx}); std::vector<SgExpression*> exprs = traverseIDs(range, elemMap(), ExprSeqCr eator{ctx});
SgExprListExp& choicelst = mkExprListExp(exprs); SgExprListExp& choicelst = mkExprListExp(exprs);
sgnode = &mkAdaNamedInitializer(choicelst, init); sgnode = &mkAdaNamedInitializer(choicelst, init);
ROSE_ASSERT(choicelst.get_parent()); ADA_ASSERT(choicelst.get_parent());
} }
ROSE_ASSERT(sgnode); ADA_ASSERT(sgnode);
attachSourceLocation(*sgnode, el, ctx); attachSourceLocation(*sgnode, el, ctx);
elems.push_back(sgnode); elems.push_back(sgnode);
} }
struct RecordAggregateCreator struct RecordAggregateCreator
{ {
explicit explicit
RecordAggregateCreator(AstContext astctx) RecordAggregateCreator(AstContext astctx)
: ctx(astctx), elems() : ctx(astctx), elems()
{} {}
skipping to change at line 229 skipping to change at line 229
private: private:
AstContext ctx; AstContext ctx;
std::vector<SgExpression*> elems; std::vector<SgExpression*> elems;
RecordAggregateCreator() = delete; RecordAggregateCreator() = delete;
}; };
void RecordAggregateCreator::operator()(Element_Struct& el) void RecordAggregateCreator::operator()(Element_Struct& el)
{ {
ROSE_ASSERT(el.Element_Kind == An_Association); ADA_ASSERT(el.Element_Kind == An_Association);
Association_Struct& assoc = el.The_Union.Association; Association_Struct& assoc = el.The_Union.Association;
ROSE_ASSERT(assoc.Association_Kind == A_Record_Component_Association); ADA_ASSERT(assoc.Association_Kind == A_Record_Component_Association);
logKind("A_Record_Component_Association"); logKind("A_Record_Component_Association");
SgExpression& init = getExprID(assoc.Component_Expression, ctx) ; SgExpression& init = getExprID(assoc.Component_Expression, ctx) ;
SgExpression* sgnode = &init; SgExpression* sgnode = &init;
ElemIdRange range = idRange(assoc.Record_Component_Choices); ElemIdRange range = idRange(assoc.Record_Component_Choices);
if (!range.empty()) if (!range.empty())
{ {
std::vector<SgExpression*> exprs = traverseIDs(range, elemMap(), ExprSeqCr eator{ctx}); std::vector<SgExpression*> exprs = traverseIDs(range, elemMap(), ExprSeqCr eator{ctx});
SgExprListExp& choicelst = mkExprListExp(exprs); SgExprListExp& choicelst = mkExprListExp(exprs);
sgnode = &mkAdaNamedInitializer(choicelst, init); sgnode = &mkAdaNamedInitializer(choicelst, init);
ROSE_ASSERT(choicelst.get_parent()); ADA_ASSERT(choicelst.get_parent());
} }
attachSourceLocation(SG_DEREF(sgnode), el, ctx); attachSourceLocation(SG_DEREF(sgnode), el, ctx);
elems.push_back(sgnode); elems.push_back(sgnode);
} }
// wrapper uses homogeneous return types instead of covariant ones // wrapper uses homogeneous return types instead of covariant ones
template <class R, R* (*mkexp) (SgExpression*, SgExpression*)> template <class R, R* (*mkexp) (SgExpression*, SgExpression*)>
SgExpression* mk2_wrapper() SgExpression* mk2_wrapper()
{ {
skipping to change at line 296 skipping to change at line 296
{ A_Unary_Minus_Operator, {"A_Unary_Minus_Operator", m k1_wrapper<SgMinusOp, sb::buildMinusOp> }}, { A_Unary_Minus_Operator, {"A_Unary_Minus_Operator", m k1_wrapper<SgMinusOp, sb::buildMinusOp> }},
{ A_Multiply_Operator, {"A_Multiply_Operator", m k2_wrapper<SgMultiplyOp, sb::buildMultiplyOp> }}, { A_Multiply_Operator, {"A_Multiply_Operator", m k2_wrapper<SgMultiplyOp, sb::buildMultiplyOp> }},
{ A_Divide_Operator, {"A_Divide_Operator", m k2_wrapper<SgDivideOp, sb::buildDivideOp> }}, { A_Divide_Operator, {"A_Divide_Operator", m k2_wrapper<SgDivideOp, sb::buildDivideOp> }},
{ A_Mod_Operator, {"A_Mod_Operator", m k2_wrapper<SgModOp, sb::buildModOp> }}, { A_Mod_Operator, {"A_Mod_Operator", m k2_wrapper<SgModOp, sb::buildModOp> }},
{ A_Rem_Operator, {"A_Rem_Operator", m k2_wrapper<SgRemOp, buildRemOp> }}, { A_Rem_Operator, {"A_Rem_Operator", m k2_wrapper<SgRemOp, buildRemOp> }},
{ An_Exponentiate_Operator, {"An_Exponentiate_Operator", m k2_wrapper<SgExponentiationOp, sb::buildExponentiationOp> }}, { An_Exponentiate_Operator, {"An_Exponentiate_Operator", m k2_wrapper<SgExponentiationOp, sb::buildExponentiationOp> }},
{ An_Abs_Operator, {"An_Abs_Operator", m k1_wrapper<SgAbsOp, buildAbsOp> }}, { An_Abs_Operator, {"An_Abs_Operator", m k1_wrapper<SgAbsOp, buildAbsOp> }},
{ A_Not_Operator, {"A_Not_Operator", m k1_wrapper<SgNotOp, sb::buildNotOp> }}, { A_Not_Operator, {"A_Not_Operator", m k1_wrapper<SgNotOp, sb::buildNotOp> }},
}; };
ROSE_ASSERT(expr.Expression_Kind == An_Operator_Symbol); ADA_ASSERT(expr.Expression_Kind == An_Operator_Symbol);
operator_maker_map_t::const_iterator pos = maker_map.find(expr.Operator_Kind ); operator_maker_map_t::const_iterator pos = maker_map.find(expr.Operator_Kind );
if (pos != maker_map.end()) if (pos != maker_map.end())
{ {
logKind(pos->second.first); logKind(pos->second.first);
return SG_DEREF(pos->second.second()); return SG_DEREF(pos->second.second());
} }
ROSE_ASSERT(expr.Operator_Kind != Not_An_Operator); ADA_ASSERT(expr.Operator_Kind != Not_An_Operator);
/* unused fields: /* unused fields:
Defining_Name_ID Corresponding_Name_Definition; Defining_Name_ID Corresponding_Name_Definition;
Defining_Name_List Corresponding_Name_Definition_List; // Only >1 if the expression in a pragma is ambiguous Defining_Name_List Corresponding_Name_Definition_List; // Only >1 if the expression in a pragma is ambiguous
Element_ID Corresponding_Name_Declaration; // Decl or stmt Element_ID Corresponding_Name_Declaration; // Decl or stmt
Defining_Name_ID Corresponding_Generic_Element; Defining_Name_ID Corresponding_Generic_Element;
*/ */
return SG_DEREF(sb::buildOpaqueVarRefExp(expr.Name_Image, &ctx.scope())); return SG_DEREF(sb::buildOpaqueVarRefExp(expr.Name_Image, &ctx.scope()));
} }
/// converts enum values to SgExpressions /// converts enum values to SgExpressions
/// \todo currently only True and False are handled /// \todo currently only True and False are handled
/// revisit when Asis representation is complete /// revisit when Asis representation is complete
SgExpression& SgExpression&
getEnumLiteral(Expression_Struct& expr, AstContext ctx) getEnumLiteral(Expression_Struct& expr, AstContext ctx)
{ {
ROSE_ASSERT(expr.Expression_Kind == An_Enumeration_Literal); ADA_ASSERT(expr.Expression_Kind == An_Enumeration_Literal);
SgExpression* res = NULL; SgExpression* res = NULL;
if (SgInitializedName* enumitem = findFirst(asisVars(), expr.Corresponding_N ame_Definition, expr.Corresponding_Name_Declaration)) if (SgInitializedName* enumitem = findFirst(asisVars(), expr.Corresponding_N ame_Definition, expr.Corresponding_Name_Declaration))
{ {
SgEnumType& enumtype = SG_DEREF( isSgEnumType(enumitem->get_type()) ); SgEnumType& enumtype = SG_DEREF( isSgEnumType(enumitem->get_type()) );
SgEnumDeclaration& enumdecl = SG_DEREF( isSgEnumDeclaration(enumtype.get_d eclaration()) ); SgEnumDeclaration& enumdecl = SG_DEREF( isSgEnumDeclaration(enumtype.get_d eclaration()) );
res = sb::buildEnumVal_nfi(-1, &enumdecl, enumitem->get_name()); res = sb::buildEnumVal_nfi(-1, &enumdecl, enumitem->get_name());
} }
skipping to change at line 372 skipping to change at line 372
void handle(SgDeclarationStatement&) { res = true; } void handle(SgDeclarationStatement&) { res = true; }
void handle(SgAdaTaskSpecDecl&) { res = false; } void handle(SgAdaTaskSpecDecl&) { res = false; }
void handle(SgAdaPackageSpecDecl&) { res = false; } void handle(SgAdaPackageSpecDecl&) { res = false; }
}; };
/// tests whether ROSE represents the prefix expression /// tests whether ROSE represents the prefix expression
/// (e.g., true for objects, false for scope-qualification) /// (e.g., true for objects, false for scope-qualification)
bool roseRequiresPrefixID(Element_ID el, AstContext ctx) bool roseRequiresPrefixID(Element_ID el, AstContext ctx)
{ {
Element_Struct& elem = retrieveAs<Element_Struct>(elemMap(), el); Element_Struct& elem = retrieveAs<Element_Struct>(elemMap(), el);
ROSE_ASSERT(elem.Element_Kind == An_Expression); ADA_ASSERT(elem.Element_Kind == An_Expression);
Expression_Struct& expr = elem.The_Union.Expression; Expression_Struct& expr = elem.The_Union.Expression;
if (expr.Expression_Kind == An_Identifier) if (expr.Expression_Kind == An_Identifier)
{ {
/// \todo dcl == nullptr should be an error (as soon as the Asis AST /// \todo dcl == nullptr should be an error (as soon as the Asis AST
/// is generated completely. /// is generated completely.
SgDeclarationStatement* dcl = getDecl_opt(expr, ctx); SgDeclarationStatement* dcl = getDecl_opt(expr, ctx);
return dcl == nullptr || sg::dispatch(RoseRequiresScopeQual(), dcl); return dcl == nullptr || sg::dispatch(RoseRequiresScopeQual(), dcl);
} }
if (expr.Expression_Kind == A_Selected_Component) if (expr.Expression_Kind == A_Selected_Component)
{ {
/// \todo dcl == nullptr should be an error (as soon as the Asis AST /// \todo dcl == nullptr should be an error (as soon as the Asis AST
/// is generated completely. /// is generated completely.
return roseRequiresPrefixID(expr.Prefix, ctx) return roseRequiresPrefixID(expr.Prefix, ctx)
|| roseRequiresPrefixID(expr.Selector, ctx); || roseRequiresPrefixID(expr.Selector, ctx);
} }
ROSE_ASSERT(!FAIL_ON_ERROR); ADA_ASSERT(!FAIL_ON_ERROR(ctx) && "untested expression-kind");
logWarn() << "roseRequiresPrefixID: untested expression-kind: " logWarn() << "roseRequiresPrefixID: untested expression-kind: "
<< expr.Expression_Kind << expr.Expression_Kind
<< std::endl; << std::endl;
return true; return true;
} }
struct ExprRefMaker : sg::DispatchHandler<SgExpression*> struct ExprRefMaker : sg::DispatchHandler<SgExpression*>
{ {
void handle(SgNode& n) { SG_UNEXPECTED_NODE(n); } using base = sg::DispatchHandler<SgExpression*>;
void handle(SgDeclarationStatement& n) explicit
{ ExprRefMaker(AstContext astctx)
logError() << "ExprRefMaker: " << typeid(n).name() << std::endl; : base(), ctx(astctx)
{}
res = sb::buildIntVal(); void handle(SgNode& n) { SG_UNEXPECTED_NODE(n); }
ROSE_ASSERT(!FAIL_ON_ERROR);
}
// void handle(SgImportStatement& n) void handle(SgDeclarationStatement& n)
{
logError() << "ExprRefMaker: " << typeid(n).name() << std::endl;
void handle(SgFunctionDeclaration& n) { res = sb::buildFunctionRefExp(&n); } res = sb::buildIntVal();
void handle(SgAdaRenamingDecl& n) { res = &mkAdaRenamingRefExp(n); } ADA_ASSERT(!FAIL_ON_ERROR(ctx));
void handle(SgAdaTaskSpecDecl& n) { res = &mkAdaTaskRefExp(n); } }
// void handle(SgImportStatement& n)
void handle(SgFunctionDeclaration& n) { res = sb::buildFunctionRefExp(&n);
}
void handle(SgAdaRenamingDecl& n) { res = &mkAdaRenamingRefExp(n); }
void handle(SgAdaTaskSpecDecl& n) { res = &mkAdaTaskRefExp(n); }
private:
AstContext ctx;
}; };
struct TypeRefMaker : sg::DispatchHandler<SgExpression*> struct TypeRefMaker : sg::DispatchHandler<SgExpression*>
{ {
void set(SgType* ty); using base = sg::DispatchHandler<SgExpression*>;
void handle(SgNode& n) { SG_UNEXPECTED_NODE(n); } explicit
TypeRefMaker(AstContext astctx)
: base(), ctx(astctx)
{}
void handle(SgDeclarationStatement& n) void set(SgType* ty);
{
logError() << "TypeRefMaker: " << typeid(n).name() << std::endl;
set(sb::buildVoidType()); void handle(SgNode& n) { SG_UNEXPECTED_NODE(n); }
ROSE_ASSERT(!FAIL_ON_ERROR);
} void handle(SgDeclarationStatement& n)
{
logError() << "TypeRefMaker: " << typeid(n).name() << std::endl;
set(sb::buildVoidType());
ADA_ASSERT(!FAIL_ON_ERROR(ctx));
}
// void handle(SgImportStatement& n) // void handle(SgImportStatement& n)
void handle(SgClassDeclaration& n) { set(n.get_type()); } void handle(SgClassDeclaration& n) { set(n.get_type()); }
void handle(SgTypedefDeclaration& n) { set(n.get_type()); } void handle(SgTypedefDeclaration& n) { set(n.get_type()); }
void handle(SgEnumDeclaration& n) { set(n.get_type()); } void handle(SgEnumDeclaration& n) { set(n.get_type()); }
private:
AstContext ctx;
}; };
void TypeRefMaker::set(SgType* ty) void TypeRefMaker::set(SgType* ty)
{ {
ROSE_ASSERT(ty); ADA_ASSERT(ty);
res = sb::buildTypeExpression(ty); res = sb::buildTypeExpression(ty);
ROSE_ASSERT(res); ADA_ASSERT(res);
} }
SgExprListExp& SgExprListExp&
getRecordAggregate(Element_Struct& elem, Expression_Struct& expr, AstContext c tx) getRecordAggregate(Element_Struct& elem, Expression_Struct& expr, AstContext c tx)
{ {
ROSE_ASSERT(expr.Expression_Kind == A_Record_Aggregate); ADA_ASSERT(expr.Expression_Kind == A_Record_Aggregate);
logKind("A_Record_Aggregate"); logKind("A_Record_Aggregate");
ElemIdRange range = idRange(expr.Record_Component_Associatio ns); ElemIdRange range = idRange(expr.Record_Component_Associatio ns);
std::vector<SgExpression*> components = traverseIDs(range, elemMap(), Record AggregateCreator{ctx}); std::vector<SgExpression*> components = traverseIDs(range, elemMap(), Record AggregateCreator{ctx});
SgExprListExp& sgnode = mkExprListExp(components); SgExprListExp& sgnode = mkExprListExp(components);
attachSourceLocation(sgnode, elem, ctx); attachSourceLocation(sgnode, elem, ctx);
return sgnode; return sgnode;
} }
SgExprListExp& SgExprListExp&
getArrayAggregate(Element_Struct& elem, Expression_Struct& expr, AstContext ct x) getArrayAggregate(Element_Struct& elem, Expression_Struct& expr, AstContext ct x)
{ {
ROSE_ASSERT( expr.Expression_Kind == A_Named_Array_Aggregate ADA_ASSERT( expr.Expression_Kind == A_Named_Array_Aggregate
|| expr.Expression_Kind == A_Positional_Array_Aggregate || expr.Expression_Kind == A_Positional_Array_Aggregate
); );
const bool namedAggregate = expr.Expression_Kind == A_Named_Array_Aggregate; const bool namedAggregate = expr.Expression_Kind == A_Named_Array_Aggregate;
logKind(namedAggregate ? "A_Named_Array_Aggregate" : "A_Positional_Array_Agg regate"); logKind(namedAggregate ? "A_Named_Array_Aggregate" : "A_Positional_Array_Agg regate");
ElemIdRange range = idRange(expr.Array_Component_Association s); ElemIdRange range = idRange(expr.Array_Component_Association s);
std::vector<SgExpression*> components = traverseIDs(range, elemMap(), ArrayA ggregateCreator{namedAggregate, ctx}); std::vector<SgExpression*> components = traverseIDs(range, elemMap(), ArrayA ggregateCreator{namedAggregate, ctx});
SgExprListExp& sgnode = mkExprListExp(components); SgExprListExp& sgnode = mkExprListExp(components);
skipping to change at line 497 skipping to change at line 517
return getArrayAggregate(elem, expr, ctx); return getArrayAggregate(elem, expr, ctx);
} }
*/ */
} // anonymous } // anonymous
SgAdaAttributeExp& SgAdaAttributeExp&
getAttributeExpr(Expression_Struct& expr, AstContext ctx) getAttributeExpr(Expression_Struct& expr, AstContext ctx)
{ {
ROSE_ASSERT(expr.Expression_Kind == An_Attribute_Reference); ADA_ASSERT(expr.Expression_Kind == An_Attribute_Reference);
SgAdaAttributeExp* res = nullptr; SgAdaAttributeExp* res = nullptr;
NameData name = getNameID(expr.Attribute_Designator_Identifier, ctx) ; NameData name = getNameID(expr.Attribute_Designator_Identifier, ctx) ;
SgExpression& obj = getExprID(expr.Prefix, ctx); SgExpression& obj = getExprID(expr.Prefix, ctx);
switch (expr.Attribute_Kind) switch (expr.Attribute_Kind)
{ {
// attributes with optional expression list argument // attributes with optional expression list argument
case A_First_Attribute: // 3.5(12), 3.6.2(3), K(68), K(70) case A_First_Attribute: // 3.5(12), 3.6.2(3), K(68), K(70)
skipping to change at line 645 skipping to change at line 665
// failure kinds // failure kinds
case Not_An_Attribute: // An unexpected element case Not_An_Attribute: // An unexpected element
default: default:
{ {
logError() << "unknown expression attribute: " << expr.Attribute_Kind logError() << "unknown expression attribute: " << expr.Attribute_Kind
<< std::endl; << std::endl;
res = &mkAdaAttributeExp(obj, "ErrorAttr:" + name.fullName, mkExprListEx p()); res = &mkAdaAttributeExp(obj, "ErrorAttr:" + name.fullName, mkExprListEx p());
ROSE_ASSERT(!FAIL_ON_ERROR); ADA_ASSERT(!FAIL_ON_ERROR(ctx));
} }
} }
return SG_DEREF(res); return SG_DEREF(res);
} }
SgAdaAttributeExp& SgAdaAttributeExp&
getAttributeExprID(Element_ID el, AstContext ctx) getAttributeExprID(Element_ID el, AstContext ctx)
{ {
Element_Struct& elem = retrieveAs<Element_Struct>(elemMap(), el); Element_Struct& elem = retrieveAs<Element_Struct>(elemMap(), el);
ROSE_ASSERT(elem.Element_Kind == An_Expression); ADA_ASSERT(elem.Element_Kind == An_Expression);
SgAdaAttributeExp& sgnode = getAttributeExpr(elem.The_Union.Expression, ctx); SgAdaAttributeExp& sgnode = getAttributeExpr(elem.The_Union.Expression, ctx);
attachSourceLocation(sgnode, elem, ctx); attachSourceLocation(sgnode, elem, ctx);
return sgnode; return sgnode;
} }
namespace namespace
{ {
SgExprListExp& createExprListExpIfNeeded(SgExpression& exp) SgExprListExp& createExprListExpIfNeeded(SgExpression& exp)
{ {
skipping to change at line 681 skipping to change at line 701
} }
SgExpression& SgExpression&
getExprID_undecorated(Element_ID el, AstContext ctx); getExprID_undecorated(Element_ID el, AstContext ctx);
/// creates expressions from elements, but does not decorate /// creates expressions from elements, but does not decorate
/// aggregates with SgAggregateInitializers /// aggregates with SgAggregateInitializers
SgExpression& SgExpression&
getExpr_undecorated(Element_Struct& elem, AstContext ctx) getExpr_undecorated(Element_Struct& elem, AstContext ctx)
{ {
ROSE_ASSERT(elem.Element_Kind == An_Expression); ADA_ASSERT(elem.Element_Kind == An_Expression);
Expression_Struct& expr = elem.The_Union.Expression; Expression_Struct& expr = elem.The_Union.Expression;
SgExpression* res = NULL; SgExpression* res = NULL;
switch (expr.Expression_Kind) switch (expr.Expression_Kind)
{ {
case An_Identifier: // 4.1 case An_Identifier: // 4.1
{ {
logKind("An_Identifier"); logKind("An_Identifier");
if (SgInitializedName* var = findFirst(asisVars(), expr.Corresponding_ Name_Definition, expr.Corresponding_Name_Declaration)) if (SgInitializedName* var = findFirst(asisVars(), expr.Corresponding_ Name_Definition, expr.Corresponding_Name_Declaration))
{ {
res = sb::buildVarRefExp(var, &ctx.scope()); res = sb::buildVarRefExp(var, &ctx.scope());
} }
else if (SgDeclarationStatement* dcl = getDecl_opt(expr, ctx)) else if (SgDeclarationStatement* dcl = getDecl_opt(expr, ctx))
{ {
res = sg::dispatch(ExprRefMaker{}, dcl); res = sg::dispatch(ExprRefMaker{ctx}, dcl);
} }
else if (SgInitializedName* exc = findFirst(asisExcps(), expr.Correspo nding_Name_Definition, expr.Corresponding_Name_Declaration)) else if (SgInitializedName* exc = findFirst(asisExcps(), expr.Correspo nding_Name_Definition, expr.Corresponding_Name_Declaration))
{ {
res = &mkExceptionRef(*exc, ctx.scope()); res = &mkExceptionRef(*exc, ctx.scope());
} }
else if (SgDeclarationStatement* tydcl = findFirst(asisTypes(), expr.C orresponding_Name_Definition, expr.Corresponding_Name_Declaration)) else if (SgDeclarationStatement* tydcl = findFirst(asisTypes(), expr.C orresponding_Name_Definition, expr.Corresponding_Name_Declaration))
{ {
res = sg::dispatch(TypeRefMaker{}, tydcl); res = sg::dispatch(TypeRefMaker{ctx}, tydcl);
} }
else if (SgType* ty = findFirst(adaTypes(), AdaIdentifier(expr.Name_Im age))) else if (SgType* ty = findFirst(adaTypes(), AdaIdentifier{expr.Name_Im age}))
{ {
res = sb::buildTypeExpression(ty); res = sb::buildTypeExpression(ty);
} }
else else
{ {
// \todo check why the name remained unresolved // \todo check why the name remained unresolved
res = &mkUnresolvedName(expr.Name_Image, ctx.scope()); res = &mkUnresolvedName(expr.Name_Image, ctx.scope());
} }
/* unused fields: (Expression_Struct) /* unused fields: (Expression_Struct)
skipping to change at line 841 skipping to change at line 861
{ {
logKind("An_Indexed_Component"); logKind("An_Indexed_Component");
SgExpression& prefix = getExprID(expr.Prefix, ctx); SgExpression& prefix = getExprID(expr.Prefix, ctx);
ElemIdRange idxrange = idRange(expr.Index_Expressions); ElemIdRange idxrange = idRange(expr.Index_Expressions);
std::vector<SgExpression*> idxexpr = traverseIDs(idxrange, elemMap(), ExprSeqCreator{ctx}); std::vector<SgExpression*> idxexpr = traverseIDs(idxrange, elemMap(), ExprSeqCreator{ctx});
SgExpression& indices = SG_DEREF(idxexpr.size() < 2 ? idx expr.at(0) SgExpression& indices = SG_DEREF(idxexpr.size() < 2 ? idx expr.at(0)
: &mk ExprListExp(idxexpr)); : &mk ExprListExp(idxexpr));
res = sb::buildPntrArrRefExp(&prefix, &indices); res = sb::buildPntrArrRefExp(&prefix, &indices);
ROSE_ASSERT(indices.get_parent()); ADA_ASSERT(indices.get_parent());
/* unused fields /* unused fields
Declaration_ID Corresponding_Called_Function; // An_Indexed_ Component (Is_Generalized_Indexing == true) //ASIS 2012 // 4.1.1 Declaration_ID Corresponding_Called_Function; // An_Indexed_ Component (Is_Generalized_Indexing == true) //ASIS 2012 // 4.1.1
bool Is_Generalized_Indexing bool Is_Generalized_Indexing
*/ */
break; break;
} }
case A_Slice: // 4.1.2 case A_Slice: // 4.1.2
{ {
logKind("A_Slice"); logKind("A_Slice");
skipping to change at line 902 skipping to change at line 922
} }
case A_Positional_Array_Aggregate: // 4.3 case A_Positional_Array_Aggregate: // 4.3
case A_Named_Array_Aggregate: // 4.3 case A_Named_Array_Aggregate: // 4.3
{ {
res = &getArrayAggregate(elem, expr, ctx); res = &getArrayAggregate(elem, expr, ctx);
/* /*
SgExprListExp& explst = getArrayAggregate(elem, expr, ctx); SgExprListExp& explst = getArrayAggregate(elem, expr, ctx);
res = sb::buildAggregateInitializer(&explst); res = sb::buildAggregateInitializer(&explst);
ROSE_ASSERT(explst.get_parent()); ADA_ASSERT(explst.get_parent());
*/ */
break; break;
} }
case A_Record_Aggregate: // 4.3 case A_Record_Aggregate: // 4.3
{ {
res = &getRecordAggregate(elem, expr, ctx); res = &getRecordAggregate(elem, expr, ctx);
/* /*
SgExprListExp& explst = getRecordAggregate(elem, expr, ctx); SgExprListExp& explst = getRecordAggregate(elem, expr, ctx);
res = sb::buildAggregateInitializer(&explst); res = sb::buildAggregateInitializer(&explst);
ROSE_ASSERT(explst.get_parent()); ADA_ASSERT(explst.get_parent());
*/ */
break; break;
} }
case An_And_Then_Short_Circuit: // 4.4 case An_And_Then_Short_Circuit: // 4.4
{ {
logKind("An_And_Then_Short_Circuit"); logKind("An_And_Then_Short_Circuit");
SgExpression& lhs = getExprID(expr.Short_Circuit_Operation_Left_Expres sion, ctx); SgExpression& lhs = getExprID(expr.Short_Circuit_Operation_Left_Expres sion, ctx);
SgExpression& rhs = getExprID(expr.Short_Circuit_Operation_Right_Expre ssion, ctx); SgExpression& rhs = getExprID(expr.Short_Circuit_Operation_Right_Expre ssion, ctx);
skipping to change at line 1021 skipping to change at line 1041
Expression_ID Subpool_Name; Expression_ID Subpool_Name;
*/ */
break; break;
} }
case An_Allocation_From_Qualified_Expression: // 4.8 case An_Allocation_From_Qualified_Expression: // 4.8
{ {
logKind("An_Allocation_From_Qualified_Expression"); logKind("An_Allocation_From_Qualified_Expression");
Element_Struct& allocElem = retrieveAs<Element_Struct>(elemMap(), e xpr.Allocator_Qualified_Expression); Element_Struct& allocElem = retrieveAs<Element_Struct>(elemMap(), e xpr.Allocator_Qualified_Expression);
ROSE_ASSERT(allocElem.Element_Kind == An_Expression); ADA_ASSERT(allocElem.Element_Kind == An_Expression);
Expression_Struct& allocExpr = allocElem.The_Union.Expression; Expression_Struct& allocExpr = allocElem.The_Union.Expression;
ROSE_ASSERT(allocExpr.Expression_Kind == A_Qualified_Expression); ADA_ASSERT(allocExpr.Expression_Kind == A_Qualified_Expression);
logKind("A_Qualified_Expression"); logKind("A_Qualified_Expression");
SgType& ty = getDeclTypeID(allocExpr.Converted_Or_Qualifie d_Subtype_Mark, ctx); SgType& ty = getDeclTypeID(allocExpr.Converted_Or_Qualifie d_Subtype_Mark, ctx);
SgExpression& arg = getExprID_undecorated(allocExpr.Converted_Or_ Qualified_Expression, ctx); SgExpression& arg = getExprID_undecorated(allocExpr.Converted_Or_ Qualified_Expression, ctx);
SgExprListExp& inilst = createExprListExpIfNeeded(arg); SgExprListExp& inilst = createExprListExpIfNeeded(arg);
/* /*
Element_Struct& initElem = retrieveAs<Element_Struct>(elemMap(), al locExpr.Converted_Or_Qualified_Expression); Element_Struct& initElem = retrieveAs<Element_Struct>(elemMap(), al locExpr.Converted_Or_Qualified_Expression);
ROSE_ASSERT(initElem.Element_Kind == An_Expression); ADA_ASSERT(initElem.Element_Kind == An_Expression);
Expression_Struct& initExpr = initElem.The_Union.Expression; Expression_Struct& initExpr = initElem.The_Union.Expression;
SgExprListExp& tyinit = getAggregate(initElem, initExpr, ctx); SgExprListExp& tyinit = getAggregate(initElem, initExpr, ctx);
*/ */
res = &mkNewExp(ty, &inilst); res = &mkNewExp(ty, &inilst);
/* unused fields /* unused fields
Expression_ID Subpool_Name Expression_ID Subpool_Name
*/ */
skipping to change at line 1061 skipping to change at line 1081
case A_Raise_Expression: // 4.4 Ada 2012 (AI12-0022 -1) case A_Raise_Expression: // 4.4 Ada 2012 (AI12-0022 -1)
case A_Case_Expression: // Ada 2012 case A_Case_Expression: // Ada 2012
case An_If_Expression: // Ada 2012 case An_If_Expression: // Ada 2012
case A_For_All_Quantified_Expression: // Ada 2012 case A_For_All_Quantified_Expression: // Ada 2012
case A_For_Some_Quantified_Expression: // Ada 2012 case A_For_Some_Quantified_Expression: // Ada 2012
case Not_An_Expression: /* break; */ // An unexpected element case Not_An_Expression: /* break; */ // An unexpected element
default: default:
logWarn() << "unhandled expression: " << expr.Expression_Kind << std::en dl; logWarn() << "unhandled expression: " << expr.Expression_Kind << std::en dl;
res = sb::buildIntVal(); res = sb::buildIntVal();
ROSE_ASSERT(!FAIL_ON_ERROR); ADA_ASSERT(!FAIL_ON_ERROR(ctx));
} }
attachSourceLocation(SG_DEREF(res), elem, ctx); attachSourceLocation(SG_DEREF(res), elem, ctx);
return *res; return *res;
} }
SgExpression& SgExpression&
getExprID_undecorated(Element_ID el, AstContext ctx) getExprID_undecorated(Element_ID el, AstContext ctx)
{ {
return getExpr_undecorated(retrieveAs<Element_Struct>(elemMap(), el), ctx); return getExpr_undecorated(retrieveAs<Element_Struct>(elemMap(), el), ctx);
skipping to change at line 1088 skipping to change at line 1108
SgExpression* res = &getExpr_undecorated(elem, ctx); SgExpression* res = &getExpr_undecorated(elem, ctx);
Expression_Struct& expr = elem.The_Union.Expression; Expression_Struct& expr = elem.The_Union.Expression;
switch (expr.Expression_Kind) switch (expr.Expression_Kind)
{ {
case A_Positional_Array_Aggregate: // 4.3 case A_Positional_Array_Aggregate: // 4.3
case A_Named_Array_Aggregate: // 4.3 case A_Named_Array_Aggregate: // 4.3
case A_Record_Aggregate: // 4.3 case A_Record_Aggregate: // 4.3
{ {
SgExprListExp* explst = isSgExprListExp(res); SgExprListExp* explst = isSgExprListExp(res);
ROSE_ASSERT(explst); ADA_ASSERT(explst);
res = sb::buildAggregateInitializer(explst); res = sb::buildAggregateInitializer(explst);
ROSE_ASSERT(explst->get_parent()); ADA_ASSERT(explst->get_parent());
attachSourceLocation(SG_DEREF(res), elem, ctx); attachSourceLocation(SG_DEREF(res), elem, ctx);
} }
default:; default:;
} }
return SG_DEREF(res); return SG_DEREF(res);
} }
SgExpression& SgExpression&
skipping to change at line 1145 skipping to change at line 1165
// \todo if there is no subtype constraint, shall we produce // \todo if there is no subtype constraint, shall we produce
// a subtype w/ NoConstraint, or leave the original type? // a subtype w/ NoConstraint, or leave the original type?
if (range.Subtype_Constraint) if (range.Subtype_Constraint)
{ {
SgAdaTypeConstraint& constraint = getConstraintID(range.Subtype_Cons traint, ctx); SgAdaTypeConstraint& constraint = getConstraintID(range.Subtype_Cons traint, ctx);
ty = &mkAdaSubtype(SG_DEREF(ty), constraint); ty = &mkAdaSubtype(SG_DEREF(ty), constraint);
} }
ROSE_ASSERT(ty); ADA_ASSERT(ty);
res = sb::buildTypeExpression(ty); res = sb::buildTypeExpression(ty);
break; break;
} }
case A_Discrete_Simple_Expression_Range: // 3.6.1, 3.5 case A_Discrete_Simple_Expression_Range: // 3.6.1, 3.5
{ {
logKind("A_Discrete_Simple_Expression_Range"); logKind("A_Discrete_Simple_Expression_Range");
SgExpression& lb = getExprID(range.Lower_Bound, ctx); SgExpression& lb = getExprID(range.Lower_Bound, ctx);
SgExpression& ub = getExprID(range.Upper_Bound, ctx); SgExpression& ub = getExprID(range.Upper_Bound, ctx);
skipping to change at line 1173 skipping to change at line 1193
logKind("A_Discrete_Range_Attribute_Reference"); logKind("A_Discrete_Range_Attribute_Reference");
res = &getExprID(range.Range_Attribute, ctx); res = &getExprID(range.Range_Attribute, ctx);
break; break;
} }
case Not_A_Discrete_Range: // An unexpected element case Not_A_Discrete_Range: // An unexpected element
default: default:
logWarn() << "Unhandled range: " << range.Discrete_Range_Kind << std::en dl; logWarn() << "Unhandled range: " << range.Discrete_Range_Kind << std::en dl;
res = &mkRangeExp(); res = &mkRangeExp();
ROSE_ASSERT(!FAIL_ON_ERROR); ADA_ASSERT(!FAIL_ON_ERROR(ctx));
} }
attachSourceLocation(SG_DEREF(res), el, ctx); attachSourceLocation(SG_DEREF(res), el, ctx);
return *res; return *res;
} }
/// \private /// \private
/// returns a range expression from the Asis definition \ref def /// returns a range expression from the Asis definition \ref def
SgExpression& SgExpression&
getDiscreteRange(Element_Struct& el, Definition_Struct& def, AstContext ctx) getDiscreteRange(Element_Struct& el, Definition_Struct& def, AstContext ctx)
{ {
ROSE_ASSERT(def.Definition_Kind == A_Discrete_Range); ADA_ASSERT(def.Definition_Kind == A_Discrete_Range);
return getDiscreteRangeGeneric(el, def, def.The_Union.The_Discrete_Range, ct x); return getDiscreteRangeGeneric(el, def, def.The_Union.The_Discrete_Range, ct x);
} }
SgExpression& SgExpression&
getDiscreteRange(Element_Struct& el, AstContext ctx) getDiscreteRange(Element_Struct& el, AstContext ctx)
{ {
ROSE_ASSERT(el.Element_Kind == A_Definition); ADA_ASSERT(el.Element_Kind == A_Definition);
return getDiscreteRange(el, el.The_Union.Definition, ctx); return getDiscreteRange(el, el.The_Union.Definition, ctx);
} }
SgExpression& SgExpression&
getDiscreteSubtype(Element_Struct& el, Definition_Struct& def, AstContext ctx) getDiscreteSubtype(Element_Struct& el, Definition_Struct& def, AstContext ctx)
{ {
ROSE_ASSERT(def.Definition_Kind == A_Discrete_Subtype_Definition); ADA_ASSERT(def.Definition_Kind == A_Discrete_Subtype_Definition);
return getDiscreteRangeGeneric(el, def, def.The_Union.The_Discrete_Subtype_D efinition, ctx); return getDiscreteRangeGeneric(el, def, def.The_Union.The_Discrete_Subtype_D efinition, ctx);
} }
SgExpression& SgExpression&
getConstraintExpr(Definition_Struct& def, AstContext ctx) getConstraintExpr(Definition_Struct& def, AstContext ctx)
{ {
ROSE_ASSERT(def.Definition_Kind == A_Constraint); ADA_ASSERT(def.Definition_Kind == A_Constraint);
Constraint_Struct& constraint = def.The_Union.The_Constraint; Constraint_Struct& constraint = def.The_Union.The_Constraint;
if (constraint.Constraint_Kind == A_Range_Attribute_Reference) // 3.5(2) if (constraint.Constraint_Kind == A_Range_Attribute_Reference) // 3.5(2)
{ {
logKind("A_Range_Attribute_Reference"); logKind("A_Range_Attribute_Reference");
return getExprID(constraint.Range_Attribute, ctx); return getExprID(constraint.Range_Attribute, ctx);
} }
ROSE_ASSERT (constraint.Constraint_Kind == A_Simple_Expression_Range); ADA_ASSERT (constraint.Constraint_Kind == A_Simple_Expression_Range);
logKind("A_Simple_Expression_Range"); logKind("A_Simple_Expression_Range");
SgExpression& lb = getExprID(constraint.Lower_Bound, ctx); SgExpression& lb = getExprID(constraint.Lower_Bound, ctx);
SgExpression& ub = getExprID(constraint.Upper_Bound, ctx); SgExpression& ub = getExprID(constraint.Upper_Bound, ctx);
return mkRangeExp(lb, ub); return mkRangeExp(lb, ub);
} }
} }
void ExprSeqCreator::operator()(Element_Struct& el) void ExprSeqCreator::operator()(Element_Struct& el)
{ {
SgExpression* res = nullptr; SgExpression* res = nullptr;
if (el.Element_Kind == An_Expression) if (el.Element_Kind == An_Expression)
res = &getExpr(el, ctx); res = &getExpr(el, ctx);
else if (el.Element_Kind == A_Definition) else if (el.Element_Kind == A_Definition)
res = &getDefinitionExpr(el, ctx); res = &getDefinitionExpr(el, ctx);
ROSE_ASSERT(res); ADA_ASSERT(res);
elems.push_back(res); elems.push_back(res);
} }
void ArgListCreator::operator()(Element_Struct& elem) void ArgListCreator::operator()(Element_Struct& elem)
{ {
args.push_back(&getArg(elem, ctx)); args.push_back(&getArg(elem, ctx));
} }
void RangeListCreator::operator()(Element_Struct& elem) void RangeListCreator::operator()(Element_Struct& elem)
{ {
lst.push_back(&getDiscreteRange(elem, ctx)); lst.push_back(&getDiscreteRange(elem, ctx));
} }
/// returns an expression from the Asis definition \ref def /// returns an expression from the Asis definition \ref def
SgExpression& SgExpression&
getDefinitionExpr(Element_Struct& el, AstContext ctx) getDefinitionExpr(Element_Struct& el, AstContext ctx)
{ {
ROSE_ASSERT(el.Element_Kind == A_Definition); ADA_ASSERT(el.Element_Kind == A_Definition);
Definition_Struct& def = el.The_Union.Definition; Definition_Struct& def = el.The_Union.Definition;
SgExpression* res = nullptr; SgExpression* res = nullptr;
switch (def.Definition_Kind) switch (def.Definition_Kind)
{ {
case A_Discrete_Range: case A_Discrete_Range:
logKind("A_Discrete_Range"); logKind("A_Discrete_Range");
res = &getDiscreteRange(el, def, ctx); res = &getDiscreteRange(el, def, ctx);
break; break;
skipping to change at line 1286 skipping to change at line 1306
break; break;
case A_Constraint: case A_Constraint:
logKind("A_Constraint"); logKind("A_Constraint");
res = &getConstraintExpr(def, ctx); res = &getConstraintExpr(def, ctx);
break; break;
default: default:
logWarn() << "Unhandled definition expr: " << def.Definition_Kind << std:: endl; logWarn() << "Unhandled definition expr: " << def.Definition_Kind << std:: endl;
res = sb::buildNullExpression(); res = sb::buildNullExpression();
ROSE_ASSERT(!FAIL_ON_ERROR); ADA_ASSERT(!FAIL_ON_ERROR(ctx));
} }
attachSourceLocation(SG_DEREF(res), el, ctx); attachSourceLocation(SG_DEREF(res), el, ctx);
return *res; return *res;
} }
SgExpression& SgExpression&
getDiscreteRangeID(Element_ID id, AstContext ctx) getDiscreteRangeID(Element_ID id, AstContext ctx)
{ {
return getDiscreteRange(retrieveAs<Element_Struct>(elemMap(), id), ctx); return getDiscreteRange(retrieveAs<Element_Struct>(elemMap(), id), ctx);
 End of changes. 63 change blocks. 
75 lines changed or deleted 96 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)