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