]> git.saurik.com Git - cycript.git/blame - Driver.hpp
Attempt to make all the identifiers look the same.
[cycript.git] / Driver.hpp
CommitLineData
b12a9965 1/* Cycript - Optimizing JavaScript Compiler/Runtime
c1d3e52e 2 * Copyright (C) 2009-2015 Jay Freeman (saurik)
b12a9965
JF
3*/
4
f95d2598 5/* GNU Affero General Public License, Version 3 {{{ */
b12a9965 6/*
f95d2598
JF
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
b12a9965 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f95d2598
JF
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/>.
b12a9965
JF
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
58afc6aa 31#include "Location.hpp"
b12a9965
JF
32#include "Parser.hpp"
33
34enum CYState {
35 CYClear,
36 CYRestricted,
37 CYNewLine
38};
39
d9c91152 40class _visible CYDriver {
b12a9965 41 public:
2c1d569a 42 CYPool &pool_;
b12a9965
JF
43 void *scanner_;
44
45 CYState state_;
46 std::stack<bool> in_;
47
48 struct {
49 bool AtImplementation;
50 bool Function;
51 bool OpenBrace;
52 } no_;
53
54 std::istream &data_;
55
d9c91152 56 int debug_;
b12a9965
JF
57 bool strict_;
58 bool commented_;
59
60 enum Condition {
61 RegExpCondition,
62 XMLContentCondition,
63 XMLTagCondition,
64 };
65
66 std::string filename_;
67
68 struct Error {
69 bool warning_;
58afc6aa 70 CYLocation location_;
b12a9965
JF
71 std::string message_;
72 };
73
74 typedef std::vector<Error> Errors;
75
76 CYProgram *program_;
77 Errors errors_;
78
79 bool auto_;
80
81 struct Context {
82 CYExpression *context_;
83
84 Context(CYExpression *context) :
85 context_(context)
86 {
87 }
88
89 typedef std::vector<CYWord *> Words;
90 Words words_;
91 };
92
93 typedef std::vector<Context> Contexts;
94 Contexts contexts_;
95
96 CYExpression *context_;
97
98 enum Mode {
99 AutoNone,
100 AutoPrimary,
101 AutoDirect,
102 AutoIndirect,
103 AutoMessage
104 } mode_;
105
106 private:
107 void ScannerInit();
108 void ScannerDestroy();
109
110 public:
2c1d569a 111 CYDriver(CYPool &pool, std::istream &data, const std::string &filename = "");
b12a9965
JF
112 ~CYDriver();
113
2c1d569a
JF
114 bool Parse();
115 void Replace(CYOptions &options);
d9c91152 116
b12a9965
JF
117 Condition GetCondition();
118 void SetCondition(Condition condition);
119
120 void PushCondition(Condition condition);
121 void PopCondition();
122
58afc6aa 123 void Warning(const CYLocation &location, const char *message);
b12a9965
JF
124};
125
126#endif/*CYCRIPT_DRIVER_HPP*/