ROSE  0.11.130.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  inline
102  SgName
103  nameOf(const SgSymbol& sy)
104  {
105  return sy.get_name();
106  }
107 
108  inline
109  SgName
110  nameOf(const SgVarRefExp& n)
111  {
112  return nameOf(symOf(n));
113  }
114 
115  inline
116  SgName
117  nameOf(const SgFunctionRefExp& n)
118  {
119  return nameOf(symOf(n));
120  }
121 
122  inline
123  SgName
124  nameOf(const SgEnumVal& n)
125  {
126  return n.get_name();
127  }
128 
129  inline
130  SgName
131  nameOf(const SgAdaRenamingDecl& n)
132  {
133  return n.get_name();
134  }
135 
136  inline
137  SgName
138  nameOf(const SgAdaRenamingRefExp& n)
139  {
140  return nameOf(declOf(n));
141  }
142 
143  inline
144  SgName
145  nameOf(const SgAdaUnitRefExp& n)
146  {
147  return SageInterface::get_name(n.get_decl());
148  }
149 
150 
151 /*
152  inline
153  SgName nameOf(const SgImportStatement& import)
154  {
155  const SgExpressionPtrList& lst = import.get_import_list();
156  ROSE_ASSERT(lst.size() == 1);
157 
158  return nameOf(SG_DEREF(isSgVarRefExp(lst.back())));
159  }
160 */
161 
162 } // anononymous namespace for convenience functions
163 
164 
165  extern const std::string roseOperatorPrefix;
166  extern const std::string packageStandardName;
167  extern const std::string durationTypeName;
168  extern const std::string exceptionName;
169 
178 
182  bool unconstrained(const SgArrayType* ty);
183  bool unconstrained(const SgArrayType& ty);
185 
186  using StatementRange = std::pair<SgDeclarationStatementPtrList::iterator, SgDeclarationStatementPtrList::iterator>;
187 
197  StatementRange
198  declsInPackage(SgGlobal& globalScope, const std::string& mainFile);
199 
200  StatementRange
201  declsInPackage(SgGlobal& globalScope, const SgSourceFile& mainFile);
203 
204 
212 
214  struct FlatArrayType : std::tuple<SgArrayType*, std::vector<SgExpression*> >
215  {
216  using base = std::tuple<SgArrayType*, std::vector<SgExpression*> >;
217  using base::base;
218 
219  SgArrayType* type() const { return std::get<0>(*this); }
220  std::vector<SgExpression*> const& dims() const { return std::get<1>(*this); }
221  std::vector<SgExpression*>& dims() { return std::get<1>(*this); }
222  };
223 
235 
237  template <class SageLocatedNode>
238  struct IfInfo : std::tuple<SgExpression*, SageLocatedNode*>
239  {
240  using base = std::tuple<SgExpression*, SageLocatedNode*>;
241  using base::base;
242 
243  SgExpression* condition() const { return std::get<0>(*this); }
244  SageLocatedNode* trueBranch() const { return std::get<1>(*this); }
245  bool isElse() const { return condition() == nullptr; }
246  };
247 
252 
254  std::vector<IfExpressionInfo>
256 
258  std::vector<IfStatementInfo>
260 
264  long long int
266 
267 
269  SgExpression*
270  underlyingExpr(const SgStatement* s);
271 
279  SgRangeExp* range(const SgAdaAttributeExp* rangeAttribute);
280  SgRangeExp* range(const SgAdaAttributeExp& rangeAttribute);
282 
288 
294 
300 
307 
318 
322  SgStatementPtrList::iterator declarationLimit(SgStatementPtrList& list);
323  SgStatementPtrList::iterator declarationLimit(SgBasicBlock& block);
324  SgStatementPtrList::iterator declarationLimit(SgBasicBlock* block);
325  SgStatementPtrList::const_iterator declarationLimit(const SgStatementPtrList& list);
326  SgStatementPtrList::const_iterator declarationLimit(const SgBasicBlock& block);
327  SgStatementPtrList::const_iterator declarationLimit(const SgBasicBlock* block);
329 
335  bool isFunctionTryBlock(const SgTryStmt& n);
336  bool isFunctionTryBlock(const SgTryStmt* n);
338 
339 
345  bool isPackageTryBlock(const SgTryStmt& n);
346  bool isPackageTryBlock(const SgTryStmt* n);
348 
349 
355 
356 
359  bool isModularType(const SgType& ty);
360  bool isModularType(const SgType* ty);
361  bool isIntegerType(const SgType& ty);
362  bool isIntegerType(const SgType* ty);
363  bool isFloatingPointType(const SgType& ty);
364  bool isFloatingPointType(const SgType* ty);
365  bool isDiscreteType(const SgType* ty);
366  bool isDiscreteType(const SgType& ty);
368 
373  bool isFixedType(const SgType* ty);
374  bool isFixedType(const SgType& ty);
376 
381  bool resolvesToFixedType(const SgType* ty);
382  bool resolvesToFixedType(const SgType& ty);
384 
389  bool isDecimalFixedType(const SgType* ty);
390  bool isDecimalFixedType(const SgType& ty);
392 
405 
412 
420 
421 
428 
431  bool hasSeparatedBody(const SgDeclarationStatement& dcl);
432  bool hasSeparatedBody(const SgDeclarationStatement* dcl);
434 
440 
446 
447  struct TypeDescription : std::tuple<SgType*, bool>
448  {
449  using base = std::tuple<SgType*, bool>;
450  using base::base;
451 
452  SgType* typerep() const { return std::get<0>(*this); }
453  SgType& typerep_ref() const;
454  bool polymorphic() const { return std::get<1>(*this); }
455  };
456 
463 
471 
477  SgScopeStatement* operatorScope(std::string opname, SgTypePtrList argtypes);
479 
481  struct ImportedUnitResult : std::tuple<std::string, const SgDeclarationStatement*, const SgAdaRenamingDecl*>
482  {
483  using base = std::tuple<std::string, const SgDeclarationStatement*, const SgAdaRenamingDecl*>;
484  using base::base;
485 
486  const std::string& name() const { return std::get<0>(*this); }
487 
488  const SgDeclarationStatement& decl() const
489  {
490  ASSERT_not_null(std::get<1>(*this));
491  return *(std::get<1>(*this));
492  }
493 
494  const SgAdaRenamingDecl* renamingDecl() const { return std::get<2>(*this); }
495  };
496 
499  importedUnit(const SgImportStatement& impdcl);
500 
502  const SgExpression&
504 
505 
508 
512  std::string convertRoseOperatorNameToAdaName(const std::string& nameInRose);
513 
517  std::string convertRoseOperatorNameToAdaOperator(const std::string& nameInRose);
518 
520  struct AggregateInfo : std::tuple< SgAdaAncestorInitializer*,
521  SgExpressionPtrList::const_iterator,
522  SgExpressionPtrList::const_iterator
523  >
524  {
525  using base = std::tuple< SgAdaAncestorInitializer*,
526  SgExpressionPtrList::const_iterator,
527  SgExpressionPtrList::const_iterator
528  >;
529  using base::base;
530 
532  SgAdaAncestorInitializer* ancestor() const { return std::get<0>(*this); }
533 
535  SgExpressionPtrList::const_iterator begin() const { return std::get<1>(*this); }
536 
538  SgExpressionPtrList::const_iterator end() const { return std::get<2>(*this); }
539 
541  bool nullRecord() const { return begin() == end(); }
542  };
543 
547  AggregateInfo splitAggregate(const SgExprListExp& exp);
548  AggregateInfo splitAggregate(const SgExprListExp* exp);
550 
551 
558 
559 
562  bool isFunction(const SgFunctionType& ty);
563  bool isFunction(const SgFunctionType* ty);
564  bool isFunction(const SgAdaSubroutineType& ty);
565  bool isFunction(const SgAdaSubroutineType* ty);
567 
570  bool isObjectRenaming(const SgAdaRenamingDecl* dcl);
571  bool isObjectRenaming(const SgAdaRenamingDecl& dcl);
573 
576  bool isExceptionRenaming(const SgAdaRenamingDecl* dcl);
577  bool isExceptionRenaming(const SgAdaRenamingDecl& dcl);
579 
580  struct PrimitiveParameterDesc : std::tuple<size_t, const SgInitializedName*>
581  {
582  using base = std::tuple<size_t, const SgInitializedName*>;
583  using base::base;
584 
586  size_t
587  pos() const { return std::get<0>(*this); }
588 
590  const SgInitializedName*
591  name() const { return std::get<1>(*this); }
592  };
593 
596  std::vector<PrimitiveParameterDesc>
598 
599  std::vector<PrimitiveParameterDesc>
602 
609  SgExpressionPtrList
612 
620  std::size_t
622 
623 
624 
637  std::tuple<const SgScopeStatement*, const SgSymbol*>
638  findSymbolInContext(std::string id, const SgScopeStatement& scope, const SgScopeStatement* limit = nullptr);
640 
641 
642 
652  overridingScope(const SgExprListExp& args, const std::vector<PrimitiveParameterDesc>& primitiveArgs);
653 
655  overridingScope(const SgExprListExp* args, const std::vector<PrimitiveParameterDesc>& primitiveArgs);
657 
658 
666  const SgScopeStatement*
668 
669  const SgScopeStatement*
672 
673 
677 
688 
701  SgType*
702  baseType(const SgType& ty);
703 
704  SgType*
705  baseType(const SgType* ty);
707 /*
716  SgDeclarationStatement*
717  baseDeclaration(const SgType& ty);
718 
719  SgDeclarationStatement*
720  baseDeclaration(const SgType* ty);
722 */
732 
736 
738  bool explicitNullProcedure(const SgFunctionDefinition& fndef);
739 
741  bool explicitNullRecord(const SgClassDefinition& recdef);
742 
752  size_t
753  positionalArgumentLimit(const SgExpressionPtrList& arglst);
754 
755  size_t
757 
758  size_t
761 
764  long long int convertIntegerLiteral(const char* img);
765 
766  std::string convertStringLiteral(const char* img);
767 
768  long double convertRealLiteral(const char* img);
769 
770  char convertCharLiteral(const char* img);
772 
773 
775  // \todo mv into Ada to C++ converter
776  void convertAdaToCxxComments(SgNode* root, bool cxxLineComments = true);
777 
779  // \todo mv into Ada to C++ converter
781 
790  // \todo mv into Ada to C++ converter
791  void convertToOperatorRepresentation(SgNode* root, bool convertCallSyntax = false, bool convertNamedArguments = false);
792 } // Ada
793 } // SageInterface
794 
795 #endif /* _SAGEINTERFACE_ADA_H */
bool isSeparatedDefinition(const SgFunctionDeclaration &n)
returns true iff n is a separated function definition is separated
describes properties of imported units
This class represents the concept of a scope in C++ (e.g. global scope, fuction scope, etc.).
bool unitRefDenotesGenericInstance(const SgAdaUnitRefExp &n)
returns true iff n refers to a generic declaration from inside said declaration false otherwise (e...
std::size_t normalizedArgumentPosition(const SgFunctionCallExp &call, const SgExpression &arg)
returns the parameter position of arg in the callee, after the parameters have been normalized...
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.).
TypeDescription typeRoot(SgType &)
returns the most fundamental type after skipping subtypes, typedefs, 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
defines the result type for getArrayTypeInfo
SgEnumDeclaration * baseEnumDeclaration(SgType *ty)
finds the underlying enum declaration of a type ty
This class represents the concept of a name within the compiler.
bool resolvesToFixedType(const SgType *ty)
returns if the type ty resolves to a fixed point type
SgScopeStatement * pkgStandardScope()
do not use, this is temporary
SgScopeStatement * operatorScope(std::string opname, SgTypePtrList argtypes)
returns the scope where an operator with name opname and argument types in argtypes should be defined...
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). ...
SgExpressionPtrList normalizedCallArguments(const SgFunctionCallExp &n)
returns a list of arguments with named arguments placed at the correct position
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:9754
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
SgType * baseType(const SgType &ty)
returns the base type of a type ty
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
const SgExpression & importedElement(const SgImportStatement &n)
returns the imported element (i.e., the first entry in n's import_list
TypeDescription typeOfExpr(SgExpression &)
returns the type of an expression corrects for some peculiarities in the AST
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.
SgDeclarationStatement * associatedDeclaration(const SgSymbol &n)
returns the associated declaration for symbol n or nullptr if there is none.
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) ...
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 ...
const SgScopeStatement * correspondingBody(const SgScopeStatement *scope)
returns the body scope (aka definition) of a task, package, or protected object.
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...
SgAdaPackageBodyDecl & getPackageBodyDeclaration(const SgAdaPackageSpecDecl &specDecl)
returns the declaration node for the package body, if available
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
This class represents the concept of a C++ function call (which is an expression).
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