blob: f58bf7e601ea455683df24e8ec8288a7150b2bb7 [file] [log] [blame]
Andreas Huberc9410c72016-07-28 12:18:40 -07001#ifndef AST_H_
2
3#define AST_H_
4
5#include <android-base/macros.h>
Andreas Hubereb1081f2016-07-28 13:13:24 -07006#include <string>
Andreas Huberc9410c72016-07-28 12:18:40 -07007#include <utils/Vector.h>
8
Andreas Huberda51b8e2016-07-28 16:00:57 -07009#include "FQName.h"
10
Andreas Huberc9410c72016-07-28 12:18:40 -070011namespace android {
12
Andreas Huber5345ec22016-07-29 13:33:27 -070013struct Coordinator;
Andreas Huberc9410c72016-07-28 12:18:40 -070014struct Formatter;
15struct Type;
16struct Scope;
17
18struct AST {
Andreas Huber5345ec22016-07-29 13:33:27 -070019 AST(Coordinator *coordinator);
Andreas Huberc9410c72016-07-28 12:18:40 -070020 ~AST();
21
22 static AST *Parse(const char *path);
23
Andreas Huber84f89de2016-07-28 15:39:51 -070024 bool setPackage(const char *package);
25 bool addImport(const char *import);
Andreas Hubereb1081f2016-07-28 13:13:24 -070026
Andreas Huberc9410c72016-07-28 12:18:40 -070027 void enterScope(Scope *container);
28 void leaveScope();
29 Scope *scope();
30
31 void *scanner();
32 void setScanner(void *scanner);
33
Andreas Huber5345ec22016-07-29 13:33:27 -070034 // Look up a type by FQName, "pure" names, i.e. those without package
35 // or version are first looked up in the current scope chain.
36 // After that lookup proceeds to imports.
37 Type *lookupType(const char *name) const;
38
39 // Takes dot-separated path components to a type possibly inside this AST.
40 // Name resolution goes from root scope downwards, i.e. the path must be
41 // absolute.
42 Type *lookupTypeInternal(const std::string &namePath) const;
Andreas Huberc9410c72016-07-28 12:18:40 -070043
44 void dump(Formatter &out) const;
45
46private:
Andreas Huber5345ec22016-07-29 13:33:27 -070047 Coordinator *mCoordinator;
Andreas Huberc9410c72016-07-28 12:18:40 -070048 Vector<Scope *> mScopePath;
49
50 void *mScanner;
51 Scope *mRootScope;
52
Andreas Huberda51b8e2016-07-28 16:00:57 -070053 FQName mPackage;
Andreas Huber84f89de2016-07-28 15:39:51 -070054
Andreas Huberc9410c72016-07-28 12:18:40 -070055 DISALLOW_COPY_AND_ASSIGN(AST);
56};
57
58} // namespace android
59
60#endif // AST_H_