ROSE  0.11.109.0
sageInterfaceAda.h
1 
2 
3 #ifndef _SAGEINTERFACE_ADA_H
4 #define _SAGEINTERFACE_ADA_H 1
5 
6 #include "sage3basic.hhh"
7 #include "sageInterface.h"
8 
9 #include <tuple>
10 
11 namespace SageInterface
12 {
13 
15 namespace Ada
16 {
17 
18 namespace
19 {
20  inline
22  symOf(const SgVarRefExp& n)
23  {
24  ASSERT_not_null(n.get_symbol());
25 
26  return *n.get_symbol();
27  }
28 
29  inline
31  symOf(const SgFunctionRefExp& n)
32  {
33  ASSERT_not_null(n.get_symbol());
34 
35  return *n.get_symbol();
36  }
37 
38  inline
40  declOf(const SgFunctionSymbol& n)
41  {
42  ASSERT_not_null(n.get_declaration());
43 
44  return *n.get_declaration();
45  }
46 
47  inline
49  declOf(const SgFunctionRefExp& n)
50  {
51  return declOf(symOf(n));
52  }
53 
54  inline
56  declOf(const SgVarRefExp& n)
57  {
58  SgVariableSymbol& sy = symOf(n);
59 
60  ASSERT_not_null(sy.get_declaration());
61  return *sy.get_declaration();
62  }
63 
64  inline
66  declOf(const SgAdaUnitRefExp& n)
67  {
68  ASSERT_not_null(n.get_decl());
69 
70  return *n.get_decl();
71  }
72 
73 
74 
75 /*
76  inline
77  SgVariableDeclaration& declOf(const SgVariableSymbol& n)
78  {
79  SgNode* varnode = SG_DEREF(n.get_declaration()).get_parent();
80 
81  return SG_DEREF(isSgVariableDeclaration(varnode));
82  }
83 
84  inline
85  SgVariableDeclaration& declOf(const SgVarRefExp& n)
86  {
87  return declOf(symOf(n));
88  }
89 */
90 
91  inline
93  declOf(const SgAdaRenamingRefExp& n)
94  {
95  ASSERT_not_null(n.get_decl());
96 
97  return *n.get_decl();
98  }
99 
100 
101 
102  inline
103  SgName
104  nameOf(const SgSymbol& sy)
105  {
106  return sy.get_name();
107  }
108 
109  inline
110  SgName
111  nameOf(const SgVarRefExp& n)
112  {
113  return nameOf(symOf(n));
114  }
115 
116  inline
117  SgName
118  nameOf(const SgFunctionRefExp& n)
119  {
120  return nameOf(symOf(n));
121  }
122 
123  inline
124  SgName
125  nameOf(const SgEnumVal& n)
126  {
127  return n.get_name();
128  }
129 
130  inline
131  SgName
132  nameOf(const SgAdaRenamingDecl& n)
133  {
134  return n.get_name();
135  }
136 
137  inline
138  SgName
139  nameOf(const SgAdaRenamingRefExp& n)
140  {
141  return nameOf(declOf(n));
142  }
143 
144  inline
145  SgName
146  nameOf(const SgAdaUnitRefExp& n)
147  {
148  return SageInterface::get_name(n.get_decl());
149  }
150 
151 
152 /*
153  inline
154  SgName nameOf(const SgImportStatement& import)
155  {
156  const SgExpressionPtrList& lst = import.get_import_list();
157  ROSE_ASSERT(lst.size() == 1);
158 
159  return nameOf(SG_DEREF(isSgVarRefExp(lst.back())));
160  }
161 */
162 
163 } // anononymous namespace for convenience functions
164 
165 
166  extern const std::string roseOperatorPrefix;
167  extern const std::string packageStandardName;
168  extern const std::string durationTypeName;
169  extern const std::string exceptionName;
170 
179 
183  bool unconstrained(const SgArrayType* ty);
184  bool unconstrained(const SgArrayType& ty);
186 
187  using StatementRange = std::pair<SgDeclarationStatementPtrList::iterator, SgDeclarationStatementPtrList::iterator>;
188 
198  StatementRange
199  declsInPackage(SgGlobal& globalScope, const std::string& mainFile);
200 
201  StatementRange
202  declsInPackage(SgGlobal& globalScope, const SgSourceFile& mainFile);
204 
205 
213 
215  using FlatArrayType = std::pair<SgArrayType*, std::vector<SgExpression*> >;
216 
228 
230  template <class SageLocatedNode>
231  struct IfInfo : std::tuple<SgExpression*, SageLocatedNode*>
232  {
233  using base = std::tuple<SgExpression*, SageLocatedNode*>;
234  using base::base;
235 
236  SgExpression* condition() const { return std::get<0>(*this); }
237  SageLocatedNode* trueBranch() const { return std::get<1>(*this); }
238  bool isElse() const { return condition() == nullptr; }
239  };
240 
245 
247  std::vector<IfExpressionInfo>
249 
251  std::vector<IfStatementInfo>
253 
257  long long int
259 
260 
262  SgExpression*
263  underlyingExpr(const SgStatement* s);
264 
272  SgRangeExp* range(const SgAdaAttributeExp* rangeAttribute);
273  SgRangeExp* range(const SgAdaAttributeExp& rangeAttribute);
275 
281 
287 
293 
300 
301 
305  SgStatementPtrList::iterator declarationLimit(SgStatementPtrList& list);
306  SgStatementPtrList::iterator declarationLimit(SgBasicBlock& block);
307  SgStatementPtrList::iterator declarationLimit(SgBasicBlock* block);
308  SgStatementPtrList::const_iterator declarationLimit(const SgStatementPtrList& list);
309  SgStatementPtrList::const_iterator declarationLimit(const SgBasicBlock& block);
310  SgStatementPtrList::const_iterator declarationLimit(const SgBasicBlock* block);
312 
318  bool isFunctionTryBlock(const SgTryStmt& n);
319  bool isFunctionTryBlock(const SgTryStmt* n);
321 
322 
328  bool isPackageTryBlock(const SgTryStmt& n);
329  bool isPackageTryBlock(const SgTryStmt* n);
331 
332 
338 
339 
342  bool isModularType(const SgType& ty);
343  bool isModularType(const SgType* ty);
344  bool isIntegerType(const SgType& ty);
345  bool isIntegerType(const SgType* ty);
346  bool isFloatingPointType(const SgType& ty);
347  bool isFloatingPointType(const SgType* ty);
348  bool isDiscreteType(const SgType* ty);
349  bool isDiscreteType(const SgType& ty);
351 
356  bool isFixedType(const SgType* ty);
357  bool isFixedType(const SgType& ty);
359 
364  bool isDecimalFixedType(const SgType* ty);
365  bool isDecimalFixedType(const SgType& ty);
367 
380 
388 
389 
396 
399  bool hasSeparatedBody(const SgDeclarationStatement& dcl);
400  bool hasSeparatedBody(const SgDeclarationStatement* dcl);
402 
408 
415 
423 
429 
436 
438  struct ImportedUnitResult : std::tuple<std::string, const SgDeclarationStatement*, const SgAdaRenamingDecl*>
439  {
440  using base = std::tuple<std::string, const SgDeclarationStatement*, const SgAdaRenamingDecl*>;
441  using base::base;
442 
443  const std::string& name() const { return std::get<0>(*this); }
444 
445  const SgDeclarationStatement& decl() const
446  {
447  ASSERT_not_null(std::get<1>(*this));
448  return *(std::get<1>(*this));
449  }
450 
451  const SgAdaRenamingDecl* renamingDecl() const { return std::get<2>(*this); }
452  };
453 
456  importedUnit(const SgImportStatement& impdcl);
457 
459  const SgExpression&
461 
462 
465 
469  std::string convertRoseOperatorNameToAdaName(const std::string& nameInRose);
470 
474  std::string convertRoseOperatorNameToAdaOperator(const std::string& nameInRose);
475 
477  struct AggregateInfo : std::tuple< SgAdaAncestorInitializer*,
478  SgExpressionPtrList::const_iterator,
479  SgExpressionPtrList::const_iterator
480  >
481  {
482  using base = std::tuple< SgAdaAncestorInitializer*,
483  SgExpressionPtrList::const_iterator,
484  SgExpressionPtrList::const_iterator
485  >;
486  using base::base;
487 
489  SgAdaAncestorInitializer* ancestor() const { return std::get<0>(*this); }
490 
492  SgExpressionPtrList::const_iterator begin() const { return std::get<1>(*this); }
493 
495  SgExpressionPtrList::const_iterator end() const { return std::get<2>(*this); }
496 
498  bool nullRecord() const { return begin() == end(); }
499  };
500 
504  AggregateInfo splitAggregate(const SgExprListExp& exp);
505  AggregateInfo splitAggregate(const SgExprListExp* exp);
507 
508 
515 
516 
519  bool isFunction(const SgFunctionType& ty);
520  bool isFunction(const SgFunctionType* ty);
522 
525  bool isObjectRenaming(const SgAdaRenamingDecl* dcl);
526  bool isObjectRenaming(const SgAdaRenamingDecl& dcl);
528 
531  bool isExceptionRenaming(const SgAdaRenamingDecl* dcl);
532  bool isExceptionRenaming(const SgAdaRenamingDecl& dcl);
534 
535  struct PrimitiveParameterDesc : std::tuple<size_t, const SgInitializedName*>
536  {
537  using base = std::tuple<size_t, const SgInitializedName*>;
538  using base::base;
539 
541  size_t
542  pos() const { return std::get<0>(*this); }
543 
545  const SgInitializedName*
546  name() const { return std::get<1>(*this); }
547  };
548 
551  std::vector<PrimitiveParameterDesc>
553 
554  std::vector<PrimitiveParameterDesc>
557 
558 
571  std::tuple<const SgScopeStatement*, const SgSymbol*>
572  findSymbolInContext(std::string id, const SgScopeStatement& scope, const SgScopeStatement* limit = nullptr);
574 
575 
576 
586  overridingScope(const SgExprListExp& args, const std::vector<PrimitiveParameterDesc>& primitiveArgs);
587 
589  overridingScope(const SgExprListExp* args, const std::vector<PrimitiveParameterDesc>& primitiveArgs);
591 
600  baseDeclaration(SgType& ty);
601 
603  baseDeclaration(SgType* ty);
605 
613  const SgScopeStatement*
615 
616  const SgScopeStatement*
619 
620 
624 
634 
638 
640  bool explicitNullProcedure(const SgFunctionDefinition& fndef);
641 
643  bool explicitNullRecord(const SgClassDefinition& recdef);
644 
654  size_t
655  positionalArgumentLimit(const SgExpressionPtrList& arglst);
656 
657  size_t
659 
660  size_t
663 
666  long long int convertIntegerLiteral(const char* img);
667 
668  std::string convertStringLiteral(const char* img);
669 
670  long double convertRealLiteral(const char* img);
671 
672  char convertCharLiteral(const char* img);
674 
675 
677  // \todo mv into Ada to C++ converter
678  void convertAdaToCxxComments(SgNode* root, bool cxxLineComments = true);
679 
681  // \todo mv into Ada to C++ converter
683 
692  // \todo mv into Ada to C++ converter
693  void convertToOperatorRepresentation(SgNode* root, bool convertCallSyntax = false, bool convertNamedArguments = false);
694 } // Ada
695 } // SageInterface
696 
697 #endif /* _SAGEINTERFACE_ADA_H */
describes properties of imported units
This class represents the concept of a scope in C++ (e.g. global scope, fuction scope, etc.).
StatementRange declsInPackage(SgGlobal &globalScope, const std::string &mainFile)
returns all statements/declarations in the global scope that were defined in the source file...
std::string convertStringLiteral(const char *img)
converts text to constant values
This class represents the base class for all types.
int firstLastDimension(SgExprListExp &args)
returns an integer value for args[0] as used by type attributes first and last
This class represents the concept of an enum declaration.
SgAdaPackageSpecDecl & getSpecificationDeclaration(const SgAdaPackageBodyDecl &bodyDecl)
returns the declaration node for the package specification
This class represents the notion of a declared variable.
bool explicitNullProcedure(const SgFunctionDefinition &fndef)
returns true, iff fndef is the body of an explicit null procedure
void convertToCaseSensitiveSymbolTables(SgNode *root)
converts all symbol tables from case insensitive to case sensitive
bool isFixedType(const SgType *ty)
returns if the type ty is a fixed point type
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.).
This class represents the concept of a C and C++ expression list.
SgStatementPtrList::iterator declarationLimit(SgStatementPtrList &list)
returns the iterator to one past the last declaration (the limit) in the statement sequence...
Details of expression aggregates.
std::string get_name(const SgNode *node)
Generate a useful name to describe the SgNode.
SgExpression * underlyingExpr(const SgStatement *s)
returns the expression of an expression statement, or nullptr if s is some other node ...
SgAdaGenericDecl & getGenericDecl(const SgAdaGenericInstanceDecl &n)
Returns SgAdaGenericDecl for a given SgAdaGenericInstanceDecl.
const SgScopeStatement * logicalParentScope(const SgScopeStatement &s)
returns the logical parent scope of a scope s.
SgRangeExp * range(const SgAdaAttributeExp *rangeAttribute)
returns a range for the range attribute rangeAttribute.
size_t pos() const
the position within the parameter list
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 ...
SgAdaGenericDecl * isGenericDecl(const SgDeclarationStatement &n)
Returns the SgAdaGenericDecl node that makes a declaration (either function/procedure or package) gen...
bool isModularType(const SgType &ty)
return if the type ty is the corresponding universal type representation in ROSE
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.
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 + '...
bool explicitNullRecord(const SgClassDefinition &recdef)
returns true, iff recdef is the body of an explicit null record
SgEnumDeclaration * baseEnumDeclaration(SgType *ty)
finds the underlying enum declaration of a type ty
This class represents the concept of a name within the compiler.
SgScopeStatement * pkgStandardScope()
do not use, this is temporary
SgType * typeOfExpr(SgExpression &)
returns the type of an expression corrects for some peculiarities in the AST
SgDeclarationStatement * associatedDecl(const SgSymbol &n)
returns the associated declaration for symbol n or nullptr if there is none.
SgScopeStatement * scopeOfTypedecl(const SgType &ty)
returns the scope where ty was defined
SgAdaPackageBodyDecl & getBodyDeclaration(const SgAdaPackageSpecDecl &specDecl)
returns the declaration node for the package body, if available
const SgInitializedName * name() const
the parameters name in form of an SgInitializedName
This class represents the concept of a class definition in C++.
This class represents strings within the IR nodes.
SgAdaPackageSpecDecl * renamedPackage(const SgAdaRenamingDecl &n)
returns a package spec decl if the declaration n renames a package returns nullptr otherwise ...
ImportedUnitResult importedUnit(const SgImportStatement &impdcl)
queries properties of an imported unit
bool isDecimalFixedType(const SgType *ty)
returns if the type ty is a decimal fixed point type
Functions that are useful when operating on the AST.
Definition: sageBuilder.h:25
bool isExceptionRenaming(const SgAdaRenamingDecl *dcl)
returns true iff ty refers to an exception renaming
bool withPrivateDefinition(const SgDeclarationStatement *dcl)
tests if the declaration dcl defines a public type that is completed in a private section...
represents a branch in an if elsif else context (either statement or expression). ...
std::vector< IfStatementInfo > flattenIfStatements(SgIfStmt &n)
returns a flat representation of if-elsif-else statements
This class represents the base class for all IR nodes within Sage III.
Definition: Cxx_Grammar.h:9737
long double convertRealLiteral(const char *img)
converts text to constant values
This class represents the concept of a variable name within the compiler (a shared container for the ...
bool isPackageTryBlock(const SgTryStmt &n)
returns true iff n is an Ada package try block
This class represents the concept of a block (not a basic block from control flow analysis)...
This class represents the notion of a statement.
This class represents the concept of a namespace definition.
long long int staticIntegralValue(SgExpression *n)
integer constant folding
SgDeclarationStatement * associatedDeclaration(const SgType &ty)
returns the scope where ty was defined
SgType * typeRoot(SgType &)
returns the most fundamental type after skipping derived types, subtypes, typedefs, etc.
const SgExpression & importedElement(const SgImportStatement &n)
returns the imported element (i.e., the first entry in n's import_list
bool unconstrained(const SgArrayType *ty)
tests if ty is an unconstrained array
bool isDiscreteType(const SgType *ty)
return if the type ty is the corresponding universal type representation in ROSE
This class represents a type for all functions.
This class represents the concept of an "if" construct.
bool isFloatingPointType(const SgType &ty)
return if the type ty is the corresponding universal type representation in ROSE
size_t positionalArgumentLimit(const SgExpressionPtrList &arglst)
finds the one past the last positional argument (aka the first named argument position).
std::vector< IfExpressionInfo > flattenIfExpressions(SgConditionalExp &n)
returns a flat representation of if expressions
void convertToOperatorRepresentation(SgNode *root, bool convertCallSyntax=false, bool convertNamedArguments=false)
converts AST from a function call representation to operator form for fundamental operator declaratio...
This class represents the variable refernece in expressions.
std::tuple< const SgScopeStatement *, const SgSymbol * > findSymbolInContext(std::string id, const SgScopeStatement &scope, const SgScopeStatement *limit=nullptr)
finds the symbol with Naming tips in the context of scope or its logical parents in the range [scope...
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).
SgExpressionPtrList::const_iterator end() const
returns the underlying's list end iterator
SgExpressionPtrList::const_iterator begin() const
returns the remaining range-begin without the ancestor initializer (if it existed) ...
std::pair< SgArrayType *, std::vector< SgExpression * > > FlatArrayType
defines the result type for getArrayTypeInfo
bool isFunction(const SgFunctionType &ty)
returns true iff ty refers to a function type (as opposed to procedure)
bool isFunctionTryBlock(const SgTryStmt &n)
returns true iff n is an Ada function try block
AggregateInfo splitAggregate(const SgExprListExp &exp)
returns the ancestor initializer, if exp refers to an extension aggregate null otherwise ...
This class represents the function being called and must be assembled in the SgFunctionCall with the ...
This class represents the concept of try statement within the try-catch support for exception handlin...
bool hasSeparatedBody(const SgDeclarationStatement &dcl)
tests if the declaration decl corresponds to a stub (aka separated unit)
char convertCharLiteral(const char *img)
converts text to constant values
bool isObjectRenaming(const SgAdaRenamingDecl *dcl)
returns true iff ty refers to an object renaming
SgAdaDiscriminatedTypeDecl * getAdaDiscriminatedTypeDecl(const SgDeclarationStatement &n)
returns the SgAdaDiscriminatedTypeDecl iff n is discriminated null otherwise
bool nullRecord() const
returns if the remaining range (w/o the ancestor initializer) indicates a null record.
std::vector< PrimitiveParameterDesc > primitiveParameterPositions(const SgFunctionDeclaration &)
returns the descriptions for parameters that make an operations primitive
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
SgDeclarationStatement * baseDeclaration(SgType &ty)
finds the type declaration of a type ty
SgAdaAncestorInitializer * ancestor() const
returns the ancestor initializer iff it exists, otherwise null
This class represents the concept of a declaration statement.
virtual SgName get_name() const =0
Access function for getting name from declarations or types internally.
void convertAdaToCxxComments(SgNode *root, bool cxxLineComments=true)
converts all Ada style comments to C++ comments
FlatArrayType getArrayTypeInfo(SgType *atype)
returns a flattened representation of Ada array types.
bool isIntegerType(const SgType &ty)
return if the type ty is the corresponding universal type representation in ROSE