ROSE  0.11.87.0
sageInterfaceAda.h
1 
2 
3 #ifndef _SAGEINTERFACE_ADA_H
4 #define _SAGEINTERFACE_ADA_H 1
5 
6 #include "sage3basic.hhh"
7 
8 #include <tuple>
9 
10 namespace SageInterface
11 {
12 
14 namespace ada
15 {
16  extern const std::string roseOperatorPrefix;
17  extern const std::string packageStandardName;
18  extern const std::string durationTypeName;
19  extern const std::string exceptionName;
20 
29 
33  bool unconstrained(const SgArrayType* ty);
34  bool unconstrained(const SgArrayType& ty);
36 
37  using StatementRange = std::pair<SgDeclarationStatementPtrList::iterator, SgDeclarationStatementPtrList::iterator>;
38 
48  StatementRange
49  declsInPackage(SgGlobal& globalScope, const std::string& mainFile);
50 
51  StatementRange
52  declsInPackage(SgGlobal& globalScope, const SgSourceFile& mainFile);
54 
55 
63 
65  using FlatArrayType = std::pair<SgArrayType*, std::vector<SgExpression*> >;
66 
78 
80  template <class SageLocatedNode>
81  struct IfInfo : std::tuple<SgExpression*, SageLocatedNode*>
82  {
83  using base = std::tuple<SgExpression*, SageLocatedNode*>;
84  using base::base;
85 
86  SgExpression* condition() const { return std::get<0>(*this); }
87  SageLocatedNode* trueBranch() const { return std::get<1>(*this); }
88  bool isElse() const { return condition() == nullptr; }
89  };
90 
95 
97  std::vector<IfExpressionInfo>
99 
101  std::vector<IfStatementInfo>
103 
107  long long int
109 
110 
112  SgExpression*
113  underlyingExpr(const SgStatement* s);
114 
122  SgRangeExp* range(const SgAdaAttributeExp* rangeAttribute);
123  SgRangeExp* range(const SgAdaAttributeExp& rangeAttribute);
125 
131 
137 
141  SgStatementPtrList::iterator declarationLimit(SgStatementPtrList& list);
142  SgStatementPtrList::iterator declarationLimit(SgBasicBlock& block);
143  SgStatementPtrList::iterator declarationLimit(SgBasicBlock* block);
144  SgStatementPtrList::const_iterator declarationLimit(const SgStatementPtrList& list);
145  SgStatementPtrList::const_iterator declarationLimit(const SgBasicBlock& block);
146  SgStatementPtrList::const_iterator declarationLimit(const SgBasicBlock* block);
148 
154  bool isFunctionTryBlock(const SgTryStmt& n);
155  bool isFunctionTryBlock(const SgTryStmt* n);
157 
158 
164  bool isPackageTryBlock(const SgTryStmt& n);
165  bool isPackageTryBlock(const SgTryStmt* n);
167 
168 
174 
175 
178  bool isModularType(const SgType& ty);
179  bool isModularType(const SgType* ty);
180  bool isIntegerType(const SgType& ty);
181  bool isIntegerType(const SgType* ty);
182  bool isFloatingPointType(const SgType& ty);
183  bool isFloatingPointType(const SgType* ty);
184  bool isDiscreteType(const SgType* ty);
185  bool isDiscreteType(const SgType& ty);
187 
192  bool isFixedType(const SgType* ty);
193  bool isFixedType(const SgType& ty);
195 
200  bool isDecimalFixedType(const SgType* ty);
201  bool isDecimalFixedType(const SgType& ty);
203 
216 
224 
225 
232 
235  bool hasSeparatedBody(const SgDeclarationStatement& dcl);
236  bool hasSeparatedBody(const SgDeclarationStatement* dcl);
238 
244 
253 
254 
258  std::string convertRoseOperatorNameToAdaName(const std::string& nameInRose);
259 
263  std::string convertRoseOperatorNameToAdaOperator(const std::string& nameInRose);
264 
266  struct AggregateInfo : std::tuple< SgAdaAncestorInitializer*,
267  SgExpressionPtrList::const_iterator,
268  SgExpressionPtrList::const_iterator
269  >
270  {
271  using base = std::tuple< SgAdaAncestorInitializer*,
272  SgExpressionPtrList::const_iterator,
273  SgExpressionPtrList::const_iterator
274  >;
275  using base::base;
276 
278  SgAdaAncestorInitializer* ancestor() const { return std::get<0>(*this); }
279 
281  SgExpressionPtrList::const_iterator begin() const { return std::get<1>(*this); }
282 
284  SgExpressionPtrList::const_iterator end() const { return std::get<2>(*this); }
285 
287  bool nullRecord() const { return begin() == end(); }
288  };
289 
293  AggregateInfo splitAggregate(const SgExprListExp& exp);
294  AggregateInfo splitAggregate(const SgExprListExp* exp);
296 
297 
304 
305 
308  bool isFunction(const SgFunctionType& ty);
309  bool isFunction(const SgFunctionType* ty);
311 
314  bool isObjectRenaming(const SgAdaRenamingDecl* dcl);
315  bool isObjectRenaming(const SgAdaRenamingDecl& dcl);
317 
320  bool isExceptionRenaming(const SgAdaRenamingDecl* dcl);
321  bool isExceptionRenaming(const SgAdaRenamingDecl& dcl);
323 
324 
325  //
326  // Ada Variant processing
327 
328  struct VariantInfo : std::tuple<SgExprListExp*, int>
329  {
330  using base = std::tuple<SgExprListExp*, int>;
331  using base::base;
332 
334  SgExprListExp* variants() const { return std::get<0>(*this); }
335 
337  int depth() const { return std::get<1>(*this); }
338  };
339 
341  VariantInfo
343 
345  int getSharedControlDepth(const VariantInfo& prev, const VariantInfo& next);
346 
348  bool haveSameConditionAt(const VariantInfo& prev, const VariantInfo& next, int i);
349 
350  struct VariantEntry : std::tuple<SgVarRefExp*, SgExprListExp*>
351  {
352  using base = std::tuple<SgVarRefExp*, SgExprListExp*>;
353  using base::base;
354 
355  SgVarRefExp* control() const { return std::get<0>(*this); }
356  SgExprListExp* conditions() const { return std::get<1>(*this); }
357  };
358 
360  VariantEntry getVariant(const VariantInfo& prev, int i);
361 
364  SgDeclarationStatementPtrList::const_iterator
365  findVariantConditionChange( SgDeclarationStatementPtrList::const_iterator begin,
366  SgDeclarationStatementPtrList::const_iterator end,
367  const SgAdaVariantFieldDecl* lastVariant
368  );
369 
370  //
371 
372 
373  struct PrimitiveParameterDesc : std::tuple<size_t, const SgInitializedName*>
374  {
375  using base = std::tuple<size_t, const SgInitializedName*>;
376  using base::base;
377 
379  size_t
380  pos() const { return std::get<0>(*this); }
381 
383  const SgInitializedName*
384  name() const { return std::get<1>(*this); }
385  };
386 
389  std::vector<PrimitiveParameterDesc>
391 
392  std::vector<PrimitiveParameterDesc>
395 
396 
406  overridingScope(const SgExprListExp& args, const std::vector<PrimitiveParameterDesc>& primitiveArgs);
407 
409  overridingScope(const SgExprListExp* args, const std::vector<PrimitiveParameterDesc>& primitiveArgs);
411 
420  baseDeclaration(SgType& ty);
421 
423  baseDeclaration(SgType* ty);
425 
435 
439 
441  bool explicitNullProcedure(const SgFunctionDefinition& fndef);
442 
444  bool explicitNullRecord(const SgClassDefinition& recdef);
445 
455  size_t
456  positionalArgumentLimit(const SgExpressionPtrList& arglst);
457 
458  size_t
460 
461  size_t
464 
467  long long int convertIntegerLiteral(const char* img);
468 
469  std::string convertStringLiteral(const char* img);
470 
471  long double convertRealLiteral(const char* img);
472 
473  char convertCharLiteral(const char* img);
475 
476 
478  // \todo mv into Ada to C++ converter
479  void convertAdaToCxxComments(SgNode* root, bool cxxLineComments = true);
480 
482  // \todo mv into Ada to C++ converter
484 
493  // \todo mv into Ada to C++ converter
494  void convertToOperatorRepresentation(SgNode* root, bool convertCallSyntax = false, bool convertNamedArguments = false);
495 } // Ada
496 } // SageInterface
497 
498 #endif /* _SAGEINTERFACE_ADA_H */
SgDeclarationStatementPtrList::const_iterator findVariantConditionChange(SgDeclarationStatementPtrList::const_iterator begin, SgDeclarationStatementPtrList::const_iterator end, const SgAdaVariantFieldDecl *lastVariant)
finds the next statement in the range [begin, end) that has a different variant condition than lastVa...
This class represents the concept of a scope in C++ (e.g. global scope, fuction scope, etc.).
std::string convertRoseOperatorNameToAdaName(const std::string &nameInRose)
takes a function name as used in ROSE and converts it to a name in Ada (i.e., '"' + operator_text + '...
long long int staticIntegralValue(SgExpression *n)
integer constant folding
std::vector< IfStatementInfo > flattenIfStatements(SgIfStmt &n)
returns a flat representation of if-elsif-else statements
SgExpressionPtrList::const_iterator begin() const
returns the remaining range-begin without the ancestor initializer (if it existed) ...
int getSharedControlDepth(const VariantInfo &prev, const VariantInfo &next)
get the depth of shared of control variables
bool hasSeparatedBody(const SgDeclarationStatement &dcl)
tests if the declaration decl corresponds to a stub (aka separated unit)
const SgInitializedName * name() const
the parameters name in form of an SgInitializedName
bool isPackageTryBlock(const SgTryStmt &n)
returns true iff n is an Ada package try block
SgRangeExp * range(const SgAdaAttributeExp *rangeAttribute)
returns a range for the range attribute rangeAttribute.
VariantInfo variantInfo(const SgAdaVariantFieldDecl *n)
returns basic information about the variant declaration
std::pair< SgArrayType *, std::vector< SgExpression * > > FlatArrayType
defines the result type for getArrayTypeInfo
This class represents the base class for all types.
bool isFixedType(const SgType *ty)
returns if the type ty is a fixed point type
SgType * typeRoot(SgType &)
returns the most fundamental type after skipping derived types, subtypes, typedefs, etc.
bool withPrivateDefinition(const SgDeclarationStatement *dcl)
tests if the declaration dcl defines a public type that is completed in a private section...
This class represents the concept of an enum declaration.
AggregateInfo splitAggregate(const SgExprListExp &exp)
returns the ancestor initializer, if exp refers to an extension aggregate null otherwise ...
SgAdaGenericDecl * isGenericDecl(const SgDeclarationStatement &n)
Returns the SgAdaGenericDecl node that makes a declaration (either function/procedure or package) gen...
This class represents the notion of a declared variable.
std::string convertStringLiteral(const char *img)
converts text to constant values
This class represents the concept of a function declaration statement.
This class represents the concept of a scope in C++ (e.g. global scope, fuction scope, etc.).
SgAdaGenericDecl & getGenericDecl(const SgAdaGenericInstanceDecl &n)
Returns SgAdaGenericDecl for a given SgAdaGenericInstanceDecl.
This class represents the concept of a C and C++ expression list.
Details of expression aggregates.
long double convertRealLiteral(const char *img)
converts text to constant values
size_t positionalArgumentLimit(const SgExpressionPtrList &arglst)
finds the one past the last positional argument (aka the first named argument position).
bool hasUnknownDiscriminants(const SgAdaDiscriminatedTypeDecl &n)
returns true iff n has an unknown discriminant part
This class represents the concept of a C trinary conditional expression (e.g. "test ...
This class represents the notion of an expression. Expressions are derived from SgLocatedNodes, since similar to statement, expressions have a concrete location within the user's source code.
SgEnumDeclaration * baseEnumDeclaration(SgType *ty)
finds the underlying enum declaration of a type ty
int firstLastDimension(SgExprListExp &args)
returns an integer value for args[0] as used by type attributes first and last
SgDeclarationStatement * baseDeclaration(SgType &ty)
finds the type declaration of a type ty
bool isDiscreteType(const SgType *ty)
return if the type ty is the corresponding universal type representation in ROSE
represents a branch in an if elsif else context (either statement or expression). ...
SgExpressionPtrList::const_iterator end() const
returns the underlying's list end iterator
This class represents the concept of a class definition in C++.
bool isIntegerType(const SgType &ty)
return if the type ty is the corresponding universal type representation in ROSE
Functions that are useful when operating on the AST.
Definition: sageBuilder.h:25
bool unconstrained(const SgArrayType *ty)
tests if ty is an unconstrained array
char convertCharLiteral(const char *img)
converts text to constant values
void convertToOperatorRepresentation(SgNode *root, bool convertCallSyntax=false, bool convertNamedArguments=false)
converts AST from a function call representation to operator form for fundamental operator declaratio...
bool isFunctionTryBlock(const SgTryStmt &n)
returns true iff n is an Ada function try block
This class represents the base class for all IR nodes within Sage III.
std::vector< IfExpressionInfo > flattenIfExpressions(SgConditionalExp &n)
returns a flat representation of if expressions
int depth() const
the variant nesting level
void convertToCaseSensitiveSymbolTables(SgNode *root)
converts all symbol tables from case insensitive to case sensitive
std::vector< PrimitiveParameterDesc > primitiveParameterPositions(const SgFunctionDeclaration &)
returns the descriptions for parameters that make an operations primitive
This class represents the concept of a block (not a basic block from control flow analysis)...
bool isFloatingPointType(const SgType &ty)
return if the type ty is the corresponding universal type representation in ROSE
This class represents the notion of a statement.
This class represents the concept of a namespace definition.
bool isDecimalFixedType(const SgType *ty)
returns if the type ty is a decimal fixed point type
bool explicitNullRecord(const SgClassDefinition &recdef)
returns true, iff recdef is the body of an explicit null record
This class represents a type for all functions.
This class represents the concept of an "if" construct.
SgAdaPackageSpecDecl & getSpecificationDeclaration(const SgAdaPackageBodyDecl &bodyDecl)
returns the declaration node for the package specification
SgStatementPtrList::iterator declarationLimit(SgStatementPtrList &list)
returns the iterator to one past the last declaration (the limit) in the statement sequence...
std::string convertRoseOperatorNameToAdaOperator(const std::string &nameInRose)
takes a function name as used in ROSE and converts it to an operator in Ada (i.e., operator_text).
SgExpression * underlyingExpr(const SgStatement *s)
returns the expression of an expression statement, or nullptr if s is some other node ...
This class represents the variable refernece in expressions.
bool nullRecord() const
returns if the remaining range (w/o the ancestor initializer) indicates a null record.
SgExprListExp * variants() const
the exprlist condition
bool isObjectRenaming(const SgAdaRenamingDecl *dcl)
returns true iff ty refers to an object renaming
bool haveSameConditionAt(const VariantInfo &prev, const VariantInfo &next, int i)
test if prev and next have the same variant condition at position i
SgScopeStatement * overridingScope(const SgExprListExp &args, const std::vector< PrimitiveParameterDesc > &primitiveArgs)
returns the overriding scope of a primitive function based on the associated arguments as defined by ...
bool isSeparatedBody(const SgDeclarationStatement &n)
returns true iff n is a unit definition that has been separated
long long int convertIntegerLiteral(const char *img)
converts text to constant values
SgAdaPackageBodyDecl & getBodyDeclaration(const SgAdaPackageSpecDecl &specDecl)
returns the declaration node for the package body, if available
This class represents the concept of try statement within the try-catch support for exception handlin...
SgAdaDiscriminatedTypeDecl * getAdaDiscriminatedTypeDecl(const SgDeclarationStatement &n)
returns the SgAdaDiscriminatedTypeDecl iff n is discriminated null otherwise
StatementRange declsInPackage(SgGlobal &globalScope, const std::string &mainFile)
returns all statements/declarations in the global scope that were defined in the source file...
bool isModularType(const SgType &ty)
return if the type ty is the corresponding universal type representation in ROSE
void convertAdaToCxxComments(SgNode *root, bool cxxLineComments=true)
converts all Ada style comments to C++ comments
bool isExceptionRenaming(const SgAdaRenamingDecl *dcl)
returns true iff ty refers to an exception renaming
SgAdaAncestorInitializer * ancestor() const
returns the ancestor initializer iff it exists, otherwise null
VariantEntry getVariant(const VariantInfo &prev, int i)
get the control/conditions of the i th entry.
bool isFunction(const SgFunctionType &ty)
returns true iff ty refers to a function type (as opposed to procedure)
SgAdaPackageSpecDecl * renamedPackage(const SgAdaRenamingDecl &n)
returns a package spec decl if the declaration n renames a package returns nullptr otherwise ...
bool explicitNullProcedure(const SgFunctionDefinition &fndef)
returns true, iff fndef is the body of an explicit null procedure
This class represents the concept of a declaration statement.
FlatArrayType getArrayTypeInfo(SgType *atype)
returns a flattened representation of Ada array types.
size_t pos() const
the position within the parameter list