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" |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 10 | #include "Type.h" |
Andreas Huber | da51b8e | 2016-07-28 16:00:57 -0700 | [diff] [blame] | 11 | |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 12 | namespace android { |
| 13 | |
Andreas Huber | 5345ec2 | 2016-07-29 13:33:27 -0700 | [diff] [blame] | 14 | struct Coordinator; |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 15 | struct Formatter; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 16 | struct Method; |
| 17 | struct TypedVar; |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 18 | struct Scope; |
| 19 | |
| 20 | struct AST { |
Andreas Huber | 5345ec2 | 2016-07-29 13:33:27 -0700 | [diff] [blame] | 21 | AST(Coordinator *coordinator); |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 22 | ~AST(); |
| 23 | |
Andreas Huber | 84f89de | 2016-07-28 15:39:51 -0700 | [diff] [blame] | 24 | bool setPackage(const char *package); |
| 25 | bool addImport(const char *import); |
Andreas Huber | eb1081f | 2016-07-28 13:13:24 -0700 | [diff] [blame] | 26 | |
Andreas Huber | a2723d2 | 2016-07-29 15:36:07 -0700 | [diff] [blame] | 27 | // package and version really. |
| 28 | FQName package() const; |
| 29 | bool isInterface(std::string *ifaceName) const; |
| 30 | |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 31 | void enterScope(Scope *container); |
| 32 | void leaveScope(); |
| 33 | Scope *scope(); |
| 34 | |
| 35 | void *scanner(); |
| 36 | void setScanner(void *scanner); |
| 37 | |
Andreas Huber | 5345ec2 | 2016-07-29 13:33:27 -0700 | [diff] [blame] | 38 | // Look up a type by FQName, "pure" names, i.e. those without package |
| 39 | // or version are first looked up in the current scope chain. |
| 40 | // After that lookup proceeds to imports. |
| 41 | Type *lookupType(const char *name) const; |
| 42 | |
| 43 | // Takes dot-separated path components to a type possibly inside this AST. |
| 44 | // Name resolution goes from root scope downwards, i.e. the path must be |
| 45 | // absolute. |
| 46 | Type *lookupTypeInternal(const std::string &namePath) const; |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 47 | |
| 48 | void dump(Formatter &out) const; |
| 49 | |
Andreas Huber | b82318c | 2016-08-02 14:45:54 -0700 | [diff] [blame^] | 50 | status_t generateCpp(const std::string &outputPath) const; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 51 | |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 52 | private: |
Andreas Huber | 5345ec2 | 2016-07-29 13:33:27 -0700 | [diff] [blame] | 53 | Coordinator *mCoordinator; |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 54 | Vector<Scope *> mScopePath; |
| 55 | |
| 56 | void *mScanner; |
| 57 | Scope *mRootScope; |
| 58 | |
Andreas Huber | da51b8e | 2016-07-28 16:00:57 -0700 | [diff] [blame] | 59 | FQName mPackage; |
Andreas Huber | 84f89de | 2016-07-28 15:39:51 -0700 | [diff] [blame] | 60 | |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 61 | void getPackageComponents(std::vector<std::string> *components) const; |
| 62 | |
| 63 | void getPackageAndVersionComponents( |
| 64 | std::vector<std::string> *components, bool cpp_compatible) const; |
| 65 | |
| 66 | std::string makeHeaderGuard(const std::string &baseName) const; |
| 67 | void enterLeaveNamespace(Formatter &out, bool enter) const; |
| 68 | |
Andreas Huber | b82318c | 2016-08-02 14:45:54 -0700 | [diff] [blame^] | 69 | status_t generateInterfaceHeader(const std::string &outputPath) const; |
| 70 | status_t generateStubHeader(const std::string &outputPath) const; |
| 71 | status_t generateProxyHeader(const std::string &outputPath) const; |
| 72 | status_t generateAllSource(const std::string &outputPath) const; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 73 | |
| 74 | status_t generateTypeSource( |
| 75 | Formatter &out, const std::string &ifaceName) const; |
| 76 | |
| 77 | status_t generateProxySource( |
| 78 | Formatter &out, const std::string &baseName) const; |
| 79 | |
| 80 | status_t generateStubSource( |
| 81 | Formatter &out, const std::string &baseName) const; |
| 82 | |
| 83 | status_t generateStubSourceForMethod( |
| 84 | Formatter &out, const Method *method) const; |
| 85 | |
| 86 | void emitCppReaderWriter( |
| 87 | Formatter &out, |
| 88 | const std::string &parcelObj, |
| 89 | bool parcelObjIsPointer, |
| 90 | const TypedVar *arg, |
| 91 | bool isReader, |
| 92 | Type::ErrorMode mode) const; |
| 93 | |
| 94 | status_t emitTypeDeclarations(Formatter &out) const; |
| 95 | |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 96 | DISALLOW_COPY_AND_ASSIGN(AST); |
| 97 | }; |
| 98 | |
| 99 | } // namespace android |
| 100 | |
| 101 | #endif // AST_H_ |