]> git.saurik.com Git - cycript.git/blob - Driver.hpp
0df39d7dd9242a49f2500b3930a2810daabf3753
[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 enum CYMark {
35 CYMarkIgnore,
36 CYMarkScript,
37 CYMarkModule,
38 };
39
40 class _visible CYDriver {
41 public:
42 CYPool &pool_;
43 void *scanner_;
44
45 std::vector<char> buffer_;
46 bool tail_;
47
48 std::stack<bool> in_;
49 std::stack<bool> return_;
50 std::stack<bool> template_;
51 std::stack<bool> yield_;
52
53 bool newline_;
54 bool last_;
55 bool next_;
56
57 std::istream &data_;
58 CYMark mark_;
59
60 int debug_;
61 bool strict_;
62 bool highlight_;
63
64 enum Condition {
65 RegExpCondition,
66 XMLContentCondition,
67 XMLTagCondition,
68 };
69
70 std::string filename_;
71
72 struct Error {
73 bool warning_;
74 CYLocation location_;
75 std::string message_;
76 };
77
78 typedef std::vector<Error> Errors;
79
80 CYScript *script_;
81 Errors errors_;
82
83 bool auto_;
84
85 struct Context {
86 CYExpression *context_;
87
88 Context(CYExpression *context) :
89 context_(context)
90 {
91 }
92
93 typedef std::vector<CYWord *> Words;
94 Words words_;
95 };
96
97 typedef std::vector<Context> Contexts;
98 Contexts contexts_;
99
100 CYExpression *context_;
101
102 enum Mode {
103 AutoNone,
104 AutoPrimary,
105 AutoDirect,
106 AutoIndirect,
107 AutoMessage
108 } mode_;
109
110 private:
111 void ScannerInit();
112 void ScannerDestroy();
113
114 public:
115 CYDriver(CYPool &pool, std::istream &data, const std::string &filename = "");
116 ~CYDriver();
117
118 bool Parse(CYMark mark = CYMarkScript);
119 void Replace(CYOptions &options);
120
121 void SetCondition(Condition condition);
122
123 void PushCondition(Condition condition);
124 void PopCondition();
125
126 void Warning(const CYLocation &location, const char *message);
127 };
128
129 #endif/*CYCRIPT_DRIVER_HPP*/