Merge remote-tracking branch 'redux/master' into sh4-pool
[tamarin-stm.git] / eval / eval-compile.h
blob2466c7712062aab2c7c7f955f1fe7e15b1191e54
1 /* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4 -*- */
2 /* vi: set ts=4 sw=4 expandtab: (add to ~/.vimrc: set modeline modelines=5) */
3 /* ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
16 * The Original Code is [Open Source Virtual Machine.].
18 * The Initial Developer of the Original Code is
19 * Adobe System Incorporated.
20 * Portions created by the Initial Developer are Copyright (C) 2008
21 * the Initial Developer. All Rights Reserved.
23 * Contributor(s):
24 * Adobe AS3 Team
26 * Alternatively, the contents of this file may be used under the terms of
27 * either the GNU General Public License Version 2 or later (the "GPL"), or
28 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
40 // This file is included into eval.h
41 namespace avmplus {
42 namespace RTC {
44 /**
45 * The compiler acts as a coordinating class, managing memory, interning strings,
46 * knowing about settings, etc. Pretty much everyone points to a compiler instance,
47 * which in turn provides the host context and allocator instances.
49 class Compiler {
50 public:
51 Compiler(HostContext* context, const wchar* filename, const wchar* src, uint32_t srclen);
52 ~Compiler() { destroy(); }
54 void compile();
55 void destroy(); // clean up all resources
57 Str* intern(const wchar* w, uint32_t nchars); // intern a string
58 Str* intern(const char* w); // intern a NUL-terminated string
59 Str* intern(uint32_t u); // convert to base-10 string, then intern it
61 // A lineno of 0 is ignored here
62 void syntaxError(uint32_t lineno, SyntaxError fmt, ...);
63 void internalError(uint32_t lineno, const char* fmt, ...);
65 HostContext * const context; // For access to the host environment
66 Allocator* const allocator; // Compiler-private bump-a-pointer never-free heap
67 const wchar * const filename; // Some human-readable name of the originator of the script, NUL-terminated
68 const uint32_t tableSize; // Number of elements in strTable; the abc layer uses this for the multiname table size too
70 // Flags, currently somewhat ad-hoc, that are used by the compiler to control the
71 // language accepted.
73 const bool es3_keywords; // True iff we should only recognize ECMAScript 3.0 keywords
74 const bool standard_regex; // True iff we should only recognize standard regex syntax, not \<newline> nor the "x" flag
75 const bool liberal_idents; // True iff we allow the use of \u to create identifers that look like keywords, or non-E262-sanctioned characters in identifiers
76 const bool local_functions; // True iff we allow block-local function definitions (hoist name, init when reached)
77 const bool octal_literals; // True iff we should recognize 0[0-7]+ as octal (not in AS3)
78 const bool origin_is_file; // True iff input came from file, so "include" should be allowed
79 const bool debugging; // True iff we should generate debug information
81 uint32_t namespace_counter; // Counter for anonymous namespaces
83 private:
84 Str** const strTable; // fixed-length hash table using chaining on collision, chained through 'next' (in private heap)
86 public:
87 // Compiler components
88 Lexer lexer;
89 Parser parser;
90 ABCFile abc; // must be initialized before the ID_ members
92 // Intern all strings after strTable has been initialized
94 // Pre-interned strings signifying themselves, keep alphabetical
95 Str * const SYM_; // ""
96 Str * const SYM_AS3;
97 Str * const SYM_Array;
98 Str * const SYM_CONFIG;
99 Str * const SYM_Namespace;
100 Str * const SYM_Number;
101 Str * const SYM_Object;
102 Str * const SYM_RegExp;
103 Str * const SYM_XML;
104 Str * const SYM_XMLList;
105 Str * const SYM_anonymous;
106 Str * const SYM_arguments;
107 Str * const SYM_children;
108 Str * const SYM_config;
109 Str * const SYM_each;
110 Str * const SYM_extends;
111 Str * const SYM_get;
112 Str * const SYM_implements;
113 Str * const SYM_int;
114 Str * const SYM_length;
115 Str * const SYM_namespace;
116 #ifdef DEBUG
117 Str * const SYM_print;
118 #endif
119 Str * const SYM_set;
120 Str * const SYM_use;
121 Str * const SYM_xml;
123 // Pre-interned strings for other uses
124 Str * const str_filename; // Str representation of the 'filename' member above
126 // Namespaces and names that are commonly used
127 const uint32_t NS_public; // public
128 const uint32_t ID_Array; // public::Array
129 const uint32_t ID_Namespace; // public::Namespace
130 const uint32_t ID_Number; // public::Number
131 const uint32_t ID_Object; // public::Object
132 const uint32_t ID_RegExp; // public::RegExp
133 const uint32_t ID_XML; // public::XML
134 const uint32_t ID_XMLList; // public::XMLList
135 const uint32_t ID_children; // public::children
136 const uint32_t ID_int; // public::int
137 const uint32_t ID_length; // public::length
138 #ifdef DEBUG
139 const uint32_t ID_print; // public::print
140 #endif
141 const uint32_t NSS_public; // [public]
142 const uint32_t MNL_public; // [public]::<>
143 const uint32_t MNL_public_attr; // [public]::<> for @attr names