Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 1 | #ifndef AST_H_ |
| 2 | |
| 3 | #define AST_H_ |
| 4 | |
| 5 | #include <android-base/macros.h> |
Andreas Huber | eb1081f | 2016-07-28 13:13:24 -0700 | [diff] [blame] | 6 | #include <string> |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 7 | #include <utils/Vector.h> |
| 8 | |
Andreas Huber | da51b8e | 2016-07-28 16:00:57 -0700 | [diff] [blame] | 9 | #include "FQName.h" |
| 10 | |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 11 | namespace android { |
| 12 | |
Andreas Huber | 5345ec2 | 2016-07-29 13:33:27 -0700 | [diff] [blame] | 13 | struct Coordinator; |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 14 | struct Formatter; |
| 15 | struct Type; |
| 16 | struct Scope; |
| 17 | |
| 18 | struct AST { |
Andreas Huber | 5345ec2 | 2016-07-29 13:33:27 -0700 | [diff] [blame] | 19 | AST(Coordinator *coordinator); |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 20 | ~AST(); |
| 21 | |
Andreas Huber | 84f89de | 2016-07-28 15:39:51 -0700 | [diff] [blame] | 22 | bool setPackage(const char *package); |
| 23 | bool addImport(const char *import); |
Andreas Huber | eb1081f | 2016-07-28 13:13:24 -0700 | [diff] [blame] | 24 | |
Andreas Huber | a2723d2 | 2016-07-29 15:36:07 -0700 | [diff] [blame^] | 25 | // package and version really. |
| 26 | FQName package() const; |
| 27 | bool isInterface(std::string *ifaceName) const; |
| 28 | |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 29 | void enterScope(Scope *container); |
| 30 | void leaveScope(); |
| 31 | Scope *scope(); |
| 32 | |
| 33 | void *scanner(); |
| 34 | void setScanner(void *scanner); |
| 35 | |
Andreas Huber | 5345ec2 | 2016-07-29 13:33:27 -0700 | [diff] [blame] | 36 | // Look up a type by FQName, "pure" names, i.e. those without package |
| 37 | // or version are first looked up in the current scope chain. |
| 38 | // After that lookup proceeds to imports. |
| 39 | Type *lookupType(const char *name) const; |
| 40 | |
| 41 | // Takes dot-separated path components to a type possibly inside this AST. |
| 42 | // Name resolution goes from root scope downwards, i.e. the path must be |
| 43 | // absolute. |
| 44 | Type *lookupTypeInternal(const std::string &namePath) const; |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 45 | |
| 46 | void dump(Formatter &out) const; |
| 47 | |
| 48 | private: |
Andreas Huber | 5345ec2 | 2016-07-29 13:33:27 -0700 | [diff] [blame] | 49 | Coordinator *mCoordinator; |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 50 | Vector<Scope *> mScopePath; |
| 51 | |
| 52 | void *mScanner; |
| 53 | Scope *mRootScope; |
| 54 | |
Andreas Huber | da51b8e | 2016-07-28 16:00:57 -0700 | [diff] [blame] | 55 | FQName mPackage; |
Andreas Huber | 84f89de | 2016-07-28 15:39:51 -0700 | [diff] [blame] | 56 | |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 57 | DISALLOW_COPY_AND_ASSIGN(AST); |
| 58 | }; |
| 59 | |
| 60 | } // namespace android |
| 61 | |
| 62 | #endif // AST_H_ |