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
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.
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 provides common, private APIs for the eval implementation.
42 // About the coding style used in eval:
44 // - eval.h is included into every cpp file in the eval subdirectory.
46 // - Inline functions are almost never in-line in the class definition, but
47 // are placed in a separate file and declared 'inline' explicitly. This
48 // helps separate definition from implementation and reduces clutter, and
49 // it resolves circular dependencies between classes in that two class
50 // definitions will be visible to both classes' inline functions. The main
51 // exception to the rule is trivial constructors, especially in eval-parse.h.
53 // - Class members are 'const' whenever possible.
55 // - All eval code is placed in the namespace avmplus::RTC ("run-time compiler")
56 // so that it is clearly segregated from the rest of the VM; no part of the
57 // VM code should need to open that namespace at all.
59 // - Reasonably standard C++ is assumed, the intent is not for this code to
60 // be portable to the most feeble compilers for embedded systems.
62 // - Almost all allocation is off a private heap of header-less objects that
63 // has minimal allocation cost, very low fragmentation, and which can be
64 // freed in bulk very quickly. See eval-util.h.
66 // - The code is almost entirely independent of avmplus, so that it can be
67 // easily incorporated into a standalone compiler. As a consequence, there
68 // is no use of String, AvmCore, GC, or other central data structures of
69 // avmplus; the necessary functionality (not much) is implemented inside
70 // eval or made available through an abstract HostContext class provided
71 // to the Compiler instance when the latter is created.
73 // Still, a few dependencies remain:
75 // - avmplus.h is included everywhere, so there's a dependency on that name,
78 // - ActionBlockConstants data, both opcode definitions and the instruction
81 // - MathUtils, for isNaN (in one case, can be factored into HostContext)
83 // - AvmAssert (can be mapped trivially to ISO C "assert")
85 // - wchar (can be mapped trivially to uint16_t)
87 // A prototype standalone compiler exists in utils/avmc and demonstrates that
88 // the independence works pretty well in practice; all the dependencies are
89 // resolved by implementations in that shell code.
94 #pragma warning(disable:4355) // 'this' : used in base member initializer list
95 #pragma warning(disable:4345) // behavior change: an object of POD type constructed with an initializer of the form () will be default-initialized
99 # define DEBUG_ONLY(x) x
101 # define DEBUG_ONLY(x)
108 using namespace ActionBlockConstants
;
112 // egrep '^class ' *.h | awk '{ print $2 }' | sort | awk '{ print "class " $1 ";" }'
116 class ABCExceptionInfo
;
117 class ABCExceptionTable
;
119 class ABCInstanceInfo
;
120 class ABCMetadataInfo
;
121 class ABCMethodBodyInfo
;
123 class ABCMethodTrait
;
124 class ABCMultinameInfo
;
125 class ABCNamespaceInfo
;
126 class ABCNamespaceSetInfo
;
130 class ABCTraitsTable
;
149 class CommonNamespace
;
152 class ConditionalExpr
;
156 class ControlFlowCtx
;
159 class DefaultXmlNamespaceStmt
;
160 class DescendantsExpr
;
180 class LiteralBoolean
;
183 class LiteralFunction
;
190 class LiteralUndefined
;
221 class XmlInitializer
;
223 // some special cases
228 * Symbolic names for syntax error messages / format strings (localizable). See
229 * eval-compile.cpp for the actual contents, the English language strings define
230 * the meaning of the symbols.
233 SYNTAXERR_EOT_IN_REGEXP
= 0,
234 SYNTAXERR_NEWLINE_IN_REGEXP
= 1,
235 SYNTAXERR_XML_UNEXPECTED_TOKEN
= 2,
236 SYNTAXERR_NATIVE_NOT_SUPPORTED
= 3,
237 SYNTAXERR_DEFAULT_NOT_EXPECTED
= 4,
238 SYNTAXERR_ILLEGAL_QNAME
= 5,
239 SYNTAXERR_IMPOSSIBLE_DEFAULT
= 6,
240 SYNTAXERR_ILLEGAL_TYPENAME
= 7,
241 SYNTAXERR_ILLEGAL_FIELDNAME
= 8,
242 SYNTAXERR_ILLEGAL_PROPNAME
= 9,
243 SYNTAXERR_QUALIFIER_NOT_ALLOWED
= 10,
244 SYNTAXERR_ILLEGAL_INCLUDE
= 11,
245 SYNTAXERR_ILLEGAL_NAMESPACE
= 12,
246 SYNTAXERR_ILLEGAL_IN_INTERFACE
= 13,
247 SYNTAXERR_ONE_ARGUMENT_REQUIRED
= 14,
248 SYNTAXERR_NO_FUNCTIONS_IN_BLOCKS
= 15,
249 SYNTAXERR_SEMICOLON_OR_NEWLINE
= 16,
250 SYNTAXERR_CONST_INIT_REQD
= 17,
251 SYNTAXERR_ILLEGAL_USE
= 18,
252 SYNTAXERR_RETURN_OUTSIDE_FN
= 19,
253 SYNTAXERR_VOIDFN_RETURNS_VALUE
= 20,
254 SYNTAXERR_EXPECT_DXNS
= 21,
255 SYNTAXERR_FOR_IN_ONEBINDING
= 22,
256 SYNTAXERR_FOR_EACH_REQS_IN
= 23,
257 SYNTAXERR_DUPLICATE_DEFAULT
= 24,
258 SYNTAXERR_EXPECT_CASE_OR_DEFAULT
= 25,
259 SYNTAXERR_CLASS_NOT_ALLOWED
= 26,
260 SYNTAXERR_XML_ILLEGAL_CHARS
= 27,
261 SYNTAXERR_INTERFACE_NOT_ALLOWED
= 28,
262 SYNTAXERR_PROPERTY_OPERATOR_REQUIRED
= 29,
263 SYNTAXERR_STMT_IN_INTERFACE
= 30,
264 SYNTAXERR_ILLEGAL_STMT
= 31,
265 SYNTAXERR_KWD_NOT_ALLOWED
= 32,
266 SYNTAXERR_INCLUDE_ORIGIN
= 33,
267 SYNTAXERR_INCLUDE_INACCESSIBLE
= 34,
268 SYNTAXERR_REDEFINITION
= 35,
269 SYNTAXERR_REDEFINITION_TYPE
= 36,
270 SYNTAXERR_REDUNDANT_CONST
= 37,
271 SYNTAXERR_REDUNDANT_METHOD
= 38,
272 SYNTAXERR_REDUNDANT_NAMESPACE
= 39,
273 SYNTAXERR_DEFAULT_VALUE_REQD
= 40,
274 SYNTAXERR_WRONG_TOKEN
= 41,
275 SYNTAXERR_EXPECTED_IDENT
= 42,
276 SYNTAXERR_ILLEGALCHAR_NUL
= 43,
277 SYNTAXERR_ILLEGAL_NUMBER
= 44,
278 SYNTAXERR_ILLEGALCHAR_POSTNUMBER
= 45,
279 SYNTAXERR_EOI_IN_COMMENT
= 46,
280 SYNTAXERR_ILLEGALCHAR
= 47,
281 SYNTAXERR_UNTERMINATED_STRING
= 48,
282 SYNTAXERR_EOI_IN_ESC
= 49,
283 SYNTAXERR_XML_UNTERMINATED
= 50,
284 SYNTAXERR_XML_INVALID_SLASH
= 51,
285 SYNTAXERR_XML_INVALID_LEFTBANG
= 52,
286 SYNTAXERR_IDENT_IS_KWD
= 53,
287 SYNTAXERR_EOL_IN_ESC
= 54,
288 SYNTAXERR_INVALID_VAR_ESC
= 55,
289 SYNTAXERR_ILLEGAL_BREAK
= 56,
290 SYNTAXERR_BREAK_LABEL_UNDEF
= 57,
291 SYNTAXERR_ILLEGAL_CONTINUE
= 58,
292 SYNTAXERR_CONTINUE_LABEL_UNDEF
= 59,
293 SYNTAXERR_XML_EOI_IN_MARKUP
= 60,
294 SYNTAXERR_UNBOUND_CONST_NAME
= 61,
295 SYNTAXERR_ILLEGAL_OP_IN_CONSTEXPR
= 62,
296 SYNTAXERR_CONFIG_NAMESPACE_SHADOWING
= 63,
297 SYNTAXERR_ILLEGAL_METADATA
= 64,
298 SYNTAXERR_KWD_NAMESPACE_REQUIRED
= 65,
299 SYNTAXERR_CONFIG_NAMESPACE_NOT_ALLOWED
= 66,
300 SYNTAXERR_CONFIG_NAMESPACE_MUST_BE_UNQUALIFIED
= 67,
301 SYNTAXERR_DUPLICATE_CONFIG
= 68,
302 SYNTAXERR_DIRECTIVE_REQUIRED
= 69,
303 SYNTAXERR_METADATA_NOT_ALLOWED
= 70,
304 SYNTAXERR_NEWLINE_NOT_ALLOWED
= 71,
305 SYNTAXERR_DUPLICATE_QUALIFIER
= 72,
306 SYNTAXERR_CONFIG_REQUIRED
= 73,
307 SYNTAXERR_CONFIG_PROHIBITED
= 74,
310 // The HostContext must be implemented by the embedder of eval. 'wchar' is a 16-bit unsigned value always.
314 #ifndef AVMC_STANDALONE
315 // AvmCore is used for VMPI_alloca.
316 HostContext(AvmCore
* core
) : core(core
), stopAfterParse(false) {}
317 AvmCore
* const core
;
319 HostContext() : stopAfterParse(false) {}
323 virtual ~HostContext() {};
324 virtual uint8_t* obtainStorageForResult(uint32_t nbytes
) = 0;
325 virtual const wchar
* readFileForEval(const wchar
* basename
, const wchar
* filename
, uint32_t* inputlen
) = 0;
326 virtual void freeInput(const wchar
* input
) = 0;
327 virtual void doubleToString(double d
, char* buf
, size_t bufsiz
) = 0;
328 virtual bool stringToDouble(const char* s
, double* d
) = 0;
329 virtual void throwInternalError(const char* msgz
) = 0;
330 virtual void throwSyntaxError(const char* msgz
) = 0;
339 #include "eval-util.h"
340 #include "eval-lex.h"
341 #include "eval-parse.h"
342 #include "eval-cogen.h"
343 #include "eval-abc.h"
344 #include "eval-compile.h"
345 #include "eval-unicode.h"
347 // all inline functions for those types
349 #include "eval-util-inlines.h"
350 #include "eval-abc-inlines.h"
351 #include "eval-lex-inlines.h"
352 #include "eval-parse-inlines.h"
353 #include "eval-cogen-inlines.h"