1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef V8_PARSING_PARSING_H_
6 #define V8_PARSING_PARSING_H_
7 
8 #include "src/common/globals.h"
9 
10 namespace v8 {
11 namespace internal {
12 
13 class ParseInfo;
14 class SharedFunctionInfo;
15 
16 namespace parsing {
17 
18 enum class ReportStatisticsMode { kYes, kNo };
19 
20 // Parses the top-level source code represented by the parse info and sets its
21 // function literal. Returns false (and deallocates any allocated AST nodes) if
22 // parsing failed.
23 V8_EXPORT_PRIVATE bool ParseProgram(ParseInfo* info, Handle<Script> script,
24                                     Isolate* isolate,
25                                     ReportStatisticsMode mode);
26 
27 // Parses the top-level source code represented by the parse info and sets its
28 // function literal. Allows passing an |outer_scope| for programs that exist in
29 // another scope (e.g. eval). Returns false (and deallocates any allocated AST
30 // nodes) if parsing failed.
31 V8_EXPORT_PRIVATE bool ParseProgram(ParseInfo* info, Handle<Script> script,
32                                     MaybeHandle<ScopeInfo> outer_scope,
33                                     Isolate* isolate,
34                                     ReportStatisticsMode mode);
35 
36 // Like ParseProgram but for an individual function which already has a
37 // allocated shared function info.
38 V8_EXPORT_PRIVATE bool ParseFunction(ParseInfo* info,
39                                      Handle<SharedFunctionInfo> shared_info,
40                                      Isolate* isolate,
41                                      ReportStatisticsMode mode);
42 
43 // If you don't know whether info->is_toplevel() is true or not, use this method
44 // to dispatch to either of the above functions. Prefer to use the above methods
45 // whenever possible.
46 V8_EXPORT_PRIVATE bool ParseAny(ParseInfo* info,
47                                 Handle<SharedFunctionInfo> shared_info,
48                                 Isolate* isolate, ReportStatisticsMode mode);
49 
50 }  // namespace parsing
51 }  // namespace internal
52 }  // namespace v8
53 
54 #endif  // V8_PARSING_PARSING_H_
55