ROSE 0.11.145.147
loopAdapter.h
1/* A thin client example:
2 * A simplest loop tool maintaining a list of loops and source position information
3 * */
4#ifndef loop_adapter_INCLUDED
5#define loop_adapter_INCLUDED
6
7#include <iostream>
8#include <string>
9#include <map>
10#include <vector>
11#include "myloop.h" // customer's own loop representation
12#include "abstract_handle.h"
13
15{
16 public:
17 loopNode(MyLoop* snode):mNode(snode){};
18 virtual ~loopNode(){};
19 MyLoop* getNode() const {return mNode; }
20 virtual std::string getConstructTypeName() const;
21 virtual bool hasSourcePos() const;
24 virtual AbstractHandle::abstract_node* findNode(std::string construct_type_str, AbstractHandle::specifier mspecifier) const;
25 virtual std::string getFileName() const;
26 virtual AbstractHandle::source_position getStartPos() const;
27 virtual std::string toString() const;
28 virtual size_t getNumbering( const abstract_node* another_node) const;
29 virtual bool operator == (const abstract_node & x) const;
30 //Additional stuff
31 std::vector<MyLoop*> getChildren() const {return mNode->children;};
32protected:
33 MyLoop* mNode;
34};
35
36// an internal map to avoid duplicated nodes for a same file
37extern std::map<std::string, AbstractHandle::abstract_node*> file_node_map;
38
39/* Implement fileNode , no direct MyLoop node is associated */
41{
42 public:
43 fileNode(std::string name):mfileName(name){ file_node_map[name]=this;};
44 virtual ~fileNode(){};
45 virtual std::string getConstructTypeName() const;
46 virtual bool hasName() const;
47 virtual std::string getName() const;
48 virtual AbstractHandle::abstract_node* findNode(std::string construct_type_str, AbstractHandle::specifier mspecifier) const;
49 virtual std::string toString() const;
50 virtual std::string getFileName() const;
51 virtual bool operator == (const abstract_node & x) const;
52
53 //Additional stuff
54 void setMLoops(std::vector<MyLoop*> myloops ){mLoops = myloops;}
55 std::vector<MyLoop*> getMLoops() const {return mLoops;}
56
57protected:
58 std::string mfileName;
59 std::vector<MyLoop*> mLoops;
60};
61#endif
Users should provide a concrete node implementation especially a constructor/builder to avoid duplica...
construct specifier could be used to specify a construct by name, position, numbering,...
virtual std::string getName() const
Get the name of the construct if it is named, like function name.
virtual bool hasName() const
If the node has legal names defined by language standards.
virtual std::string getConstructTypeName() const
Get the construct' s type name, like function.
virtual AbstractHandle::abstract_node * findNode(std::string construct_type_str, AbstractHandle::specifier mspecifier) const
Find a node of a given type, it also matches the specifier.
virtual AbstractHandle::abstract_node * findNode(std::string construct_type_str, AbstractHandle::specifier mspecifier) const
Find a node of a given type, it also matches the specifier.
MyLoop * getNode() const
Get the raw IR node associated with the current abstract node.
Definition loopAdapter.h:19
virtual bool hasSourcePos() const
If the node has meaningful line and column numbers associated with a file.
virtual std::string getConstructTypeName() const
Get the construct' s type name, like function.
virtual AbstractHandle::abstract_node * getParent() const
Get parent node, used for generate parent handle automatically.
virtual AbstractHandle::abstract_node * getFileNode() const
Get the start source file position of the construct Get the abstract node for file containing the cur...
source position information: