]> git.saurik.com Git - cycript.git/blob - Driver.hpp
50d513ce4960326a0025c4beac50a0bfafc7482b
[cycript.git] / Driver.hpp
1 /* Cycript - Optimizing JavaScript Compiler/Runtime
2 * Copyright (C) 2009-2015 Jay Freeman (saurik)
3 */
4
5 /* GNU Affero General Public License, Version 3 {{{ */
6 /*
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
16
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 **/
20 /* }}} */
21
22 #ifndef CYCRIPT_DRIVER_HPP
23 #define CYCRIPT_DRIVER_HPP
24
25 #include <iostream>
26
27 #include <stack>
28 #include <string>
29 #include <vector>
30
31 #include "Location.hpp"
32 #include "Parser.hpp"
33
34 class _visible CYDriver {
35 public:
36 CYPool &pool_;
37 void *scanner_;
38
39 std::stack<bool> in_;
40
41 bool newline_;
42 bool last_;
43
44 struct {
45 bool AtImplementation;
46 bool Function;
47 bool OpenBrace;
48 bool NewLine;
49 } no_;
50
51 std::istream &data_;
52
53 int debug_;
54 bool strict_;
55 bool commented_;
56
57 enum Condition {
58 RegExpCondition,
59 XMLContentCondition,
60 XMLTagCondition,
61 };
62
63 std::string filename_;
64
65 struct Error {
66 bool warning_;
67 CYLocation location_;
68 std::string message_;
69 };
70
71 typedef std::vector<Error> Errors;
72
73 CYProgram *program_;
74 Errors errors_;
75
76 bool auto_;
77
78 struct Context {
79 CYExpression *context_;
80
81 Context(CYExpression *context) :
82 context_(context)
83 {
84 }
85
86 typedef std::vector<CYWord *> Words;
87 Words words_;
88 };
89
90 typedef std::vector<Context> Contexts;
91 Contexts contexts_;
92
93 CYExpression *context_;
94
95 enum Mode {
96 AutoNone,
97 AutoPrimary,
98 AutoDirect,
99 AutoIndirect,
100 AutoMessage
101 } mode_;
102
103 private:
104 void ScannerInit();
105 void ScannerDestroy();
106
107 public:
108 CYDriver(CYPool &pool, std::istream &data, const std::string &filename = "");
109 ~CYDriver();
110
111 bool Parse();
112 void Replace(CYOptions &options);
113
114 Condition GetCondition();
115 void SetCondition(Condition condition);
116
117 void PushCondition(Condition condition);
118 void PopCondition();
119
120 void Warning(const CYLocation &location, const char *message);
121 };
122
123 #endif/*CYCRIPT_DRIVER_HPP*/