blob: 497deb7c0031a4d9f2c4e441237eae74264c413a [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
Andreas Huber84f89de2016-07-28 15:39:51 -070022 bool setPackage(const char *package);
23 bool addImport(const char *import);
Andreas Hubereb1081f2016-07-28 13:13:24 -070024
Andreas Hubera2723d22016-07-29 15:36:07 -070025 // package and version really.
26 FQName package() const;
27 bool isInterface(std::string *ifaceName) const;
28
Andreas Huberc9410c72016-07-28 12:18:40 -070029 void enterScope(Scope *container);
30 void leaveScope();
31 Scope *scope();
32
33 void *scanner();
34 void setScanner(void *scanner);
35
Andreas Huber5345ec22016-07-29 13:33:27 -070036 // 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 Huberc9410c72016-07-28 12:18:40 -070045
46 void dump(Formatter &out) const;
47
48private:
Andreas Huber5345ec22016-07-29 13:33:27 -070049 Coordinator *mCoordinator;
Andreas Huberc9410c72016-07-28 12:18:40 -070050 Vector<Scope *> mScopePath;
51
52 void *mScanner;
53 Scope *mRootScope;
54
Andreas Huberda51b8e2016-07-28 16:00:57 -070055 FQName mPackage;
Andreas Huber84f89de2016-07-28 15:39:51 -070056
Andreas Huberc9410c72016-07-28 12:18:40 -070057 DISALLOW_COPY_AND_ASSIGN(AST);
58};
59
60} // namespace android
61
62#endif // AST_H_