]> git.saurik.com Git - cycript.git/blame - Driver.hpp
Stub alternative (vector) implementation of Stack.
[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
40class CYDriver {
41 public:
42 void *scanner_;
43
44 CYState state_;
45 std::stack<bool> in_;
46
47 struct {
48 bool AtImplementation;
49 bool Function;
50 bool OpenBrace;
51 } no_;
52
53 std::istream &data_;
54
55 bool strict_;
56 bool commented_;
57
58 enum Condition {
59 RegExpCondition,
60 XMLContentCondition,
61 XMLTagCondition,
62 };
63
64 std::string filename_;
65
66 struct Error {
67 bool warning_;
58afc6aa 68 CYLocation location_;
b12a9965
JF
69 std::string message_;
70 };
71
72 typedef std::vector<Error> Errors;
73
74 CYProgram *program_;
75 Errors errors_;
76
77 bool auto_;
78
79 struct Context {
80 CYExpression *context_;
81
82 Context(CYExpression *context) :
83 context_(context)
84 {
85 }
86
87 typedef std::vector<CYWord *> Words;
88 Words words_;
89 };
90
91 typedef std::vector<Context> Contexts;
92 Contexts contexts_;
93
94 CYExpression *context_;
95
96 enum Mode {
97 AutoNone,
98 AutoPrimary,
99 AutoDirect,
100 AutoIndirect,
101 AutoMessage
102 } mode_;
103
104 private:
105 void ScannerInit();
106 void ScannerDestroy();
107
108 public:
109 CYDriver(std::istream &data, const std::string &filename = "");
110 ~CYDriver();
111
112 Condition GetCondition();
113 void SetCondition(Condition condition);
114
115 void PushCondition(Condition condition);
116 void PopCondition();
117
58afc6aa 118 void Warning(const CYLocation &location, const char *message);
b12a9965
JF
119};
120
121#endif/*CYCRIPT_DRIVER_HPP*/