Inferno  0.2
misc.hpp
Go to the documentation of this file.
00001 #ifndef MISC_HPP
00002 #define MISC_HPP
00003 
00004 #include "cpptree.hpp"
00005 #include "helpers/walk.hpp"
00006 #include "helpers/transformation.hpp"
00007 
00008 TreePtr<CPPTree::Identifier> GetIdentifier( TreePtr<CPPTree::Declaration> d );
00009 
00010 class GetDeclaration : public OutOfPlaceTransformation
00011 {
00012 public:
00013     virtual TreePtr<Node> operator()( TreePtr<Node> context, TreePtr<Node> root );
00014     static GetDeclaration instance;
00015 private:
00016   TreePtr<CPPTree::UserType> Get( TreePtr<Node> context, TreePtr<CPPTree::TypeIdentifier> id );
00017   TreePtr<CPPTree::Instance> Get( TreePtr<Node> context, TreePtr<CPPTree::InstanceIdentifier> id );
00018 };
00019 
00020 // Look for a record, skipping over typedefs. Returns NULL if not a record.
00021 // TODO make this a Transformation
00022 TreePtr<CPPTree::Record> GetRecordDeclaration( TreePtr<Node> context, TreePtr<CPPTree::TypeIdentifier> id );
00023 
00024 // Hunt through a record and its bases to find the named member
00025 TreePtr<CPPTree::Instance> FindMemberByName( TreePtr<CPPTree::Program> program, TreePtr<CPPTree::Record> r, string name );
00026 
00027 // concatenate sequences by adding them, like strings etc
00028 // TODO move to common/
00029 template<typename T>
00030 Sequence<T> operator+( Sequence<T> &s1, Sequence<T> &s2 )
00031 {
00032     Sequence<T> sr=s1;
00033     FOREACH( TreePtr<T> t, s2 )
00034         sr.push_back(t);
00035     return sr;    
00036 }
00037 
00038 // Really, Declaration should point to an Identifier and that would be that, but at present
00039 // there are differnent kinds of Declaration that point to different kinds of Node.
00040 // TODO refactor this away
00041 TreePtr<CPPTree::Identifier> GetIdentifierOfDeclaration( TreePtr<CPPTree::Declaration> d );
00042 
00043 #endif
00044