[0dd3a2f] | 1 | // |
---|
| 2 | // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo |
---|
| 3 | // |
---|
| 4 | // The contents of this file are covered under the licence agreement in the |
---|
| 5 | // file "LICENCE" distributed with Cforall. |
---|
| 6 | // |
---|
| 7 | // Mangler.h -- |
---|
| 8 | // |
---|
| 9 | // Author : Richard C. Bilson |
---|
| 10 | // Created On : Sun May 17 21:44:03 2015 |
---|
[4aa0858] | 11 | // Last Modified By : Rob Schluntz |
---|
| 12 | // Last Modified On : Wed Aug 19 15:48:46 2015 |
---|
| 13 | // Update Count : 14 |
---|
[0dd3a2f] | 14 | // |
---|
| 15 | |
---|
| 16 | #ifndef MANGLER_H |
---|
| 17 | #define MANGLER_H |
---|
[51b7345] | 18 | |
---|
[5f2f2d7] | 19 | #include <sstream> |
---|
[51b7345] | 20 | #include "SynTree/SynTree.h" |
---|
| 21 | #include "SynTree/Visitor.h" |
---|
| 22 | |
---|
| 23 | namespace SymTab { |
---|
[a08ba92] | 24 | class Mangler : public Visitor { |
---|
| 25 | public: |
---|
[0dd3a2f] | 26 | template< typename SynTreeClass > |
---|
[4aa0858] | 27 | static std::string mangle( SynTreeClass *decl, bool mangleOverridable = true ); // interface to clients |
---|
[51b7345] | 28 | |
---|
| 29 | /// using Visitor::visit; |
---|
[0dd3a2f] | 30 | virtual void visit( ObjectDecl *declaration ); |
---|
| 31 | virtual void visit( FunctionDecl *declaration ); |
---|
| 32 | virtual void visit( TypeDecl *declaration ); |
---|
| 33 | |
---|
| 34 | virtual void visit( VoidType *voidType ); |
---|
| 35 | virtual void visit( BasicType *basicType ); |
---|
| 36 | virtual void visit( PointerType *pointerType ); |
---|
| 37 | virtual void visit( ArrayType *arrayType ); |
---|
| 38 | virtual void visit( FunctionType *functionType ); |
---|
| 39 | virtual void visit( StructInstType *aggregateUseType ); |
---|
| 40 | virtual void visit( UnionInstType *aggregateUseType ); |
---|
| 41 | virtual void visit( EnumInstType *aggregateUseType ); |
---|
| 42 | virtual void visit( TypeInstType *aggregateUseType ); |
---|
| 43 | virtual void visit( TupleType *tupleType ); |
---|
[51b7345] | 44 | |
---|
[5f2f2d7] | 45 | std::string get_mangleName() { return mangleName.str(); } |
---|
[a08ba92] | 46 | private: |
---|
[5f2f2d7] | 47 | std::ostringstream mangleName; |
---|
[0dd3a2f] | 48 | typedef std::map< std::string, std::pair< int, int > > VarMapType; |
---|
| 49 | VarMapType varNums; |
---|
| 50 | int nextVarNum; |
---|
| 51 | bool isTopLevel; |
---|
[4aa0858] | 52 | bool mangleOverridable; |
---|
[51b7345] | 53 | |
---|
[4aa0858] | 54 | Mangler( bool mangleOverridable ); |
---|
[0dd3a2f] | 55 | Mangler( const Mangler & ); |
---|
[51b7345] | 56 | |
---|
[0dd3a2f] | 57 | void mangleDecl( DeclarationWithType *declaration ); |
---|
| 58 | void mangleRef( ReferenceToType *refType, std::string prefix ); |
---|
[51b7345] | 59 | |
---|
[0dd3a2f] | 60 | void printQualifiers( Type *type ); |
---|
[a08ba92] | 61 | }; // Mangler |
---|
[ea3eb06] | 62 | |
---|
[a08ba92] | 63 | template< typename SynTreeClass > |
---|
[4aa0858] | 64 | std::string Mangler::mangle( SynTreeClass *decl, bool mangleOverridable ) { |
---|
| 65 | Mangler mangler( mangleOverridable ); |
---|
[0dd3a2f] | 66 | maybeAccept( decl, mangler ); |
---|
| 67 | return mangler.get_mangleName(); |
---|
[a08ba92] | 68 | } |
---|
[ea3eb06] | 69 | } // SymTab |
---|
| 70 | |
---|
[0dd3a2f] | 71 | #endif // MANGLER_H |
---|
| 72 | |
---|
| 73 | // Local Variables: // |
---|
| 74 | // tab-width: 4 // |
---|
| 75 | // mode: c++ // |
---|
| 76 | // compile-command: "make install" // |
---|
| 77 | // End: // |
---|