# Copyright (c) 2024-2026 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

module:
  name: es2panda
  namespace: ark::es2panda::util::gen

options:
- name: help
  type: bool
  default: false
  description: Print this message and exit

- name: version
  type: bool
  default: false
  description: Print version and exit

- name: arktsconfig
  type: std::string
  default: $ORIGIN/arktsconfig.json
  description: Path to arkts configuration file

# Parser
- name: extension
  type: std::string
  default: ets
  description: Parse the input as the given extension
  enum: &ScriptExtension
  - js
  - ts
  - as
  - ets
  possible_values: *ScriptExtension

- name: module
  type: bool
  default: false
  description: Parse the input as module (JS only option)

- name: parse-only
  type: bool
  default: false
  description: Parse the input only

- name: dump-ast
  description: Dump the parsed AST
  sub_options:
  - name: output
    type: std::string
    default: ""
    description: Dump the parsed AST to the specified file

- name: dump-cfg
  type: bool
  default: false
  description: Dump the constructed CFG into a .dot file

- name: dump-dynamic-ast
  type: bool
  default: false
  description: Dump AST with synthetic nodes for dynamic languages

- name: dump-ast-only-silent
  type: bool
  default: false
  description: Dump parsed AST with all dumpers available but don't print to stdout

- name: list-files
  type: bool
  default: false
  description: Print names of files that are part of compilation

# Compiler
- name: dump-assembly
  type: bool
  default: false
  description: Dump pandasm

- name: debug-info
  type: bool
  default: false
  description: Compile with debug info

- name: dump-debug-info
  type: bool
  default: false
  description: Dump debug info

- name: opt-level
  type: int
  default: 1
  description: Compiler optimization level
  range: 0-2

- name: ets-module
  type: bool
  default: false
  description: Compile the input as ets-module

- name: eval-mode
  description: (js-only) Set 'eval'-mode
  type: std::string
  enum: &EvalMode
  - none
  - default
  - direct
  - function
  possible_values: *EvalMode
  default: none

- name: ets-warnings
  description: Enable ETS-warnings
  enum: &ETSWarnings
    # Warinings that keep code in subset:
    subset_aware:
    - ets-prohibit-top-level-statements  # Prohibit top-level statements
    - ets-boost-equality-statement       # Suggest boosting Equality Statements
    - ets-remove-lambda                  # Suggestions to replace lambda with regular functions
    - ets-implicit-boxing-unboxing       # Check if a program contains implicit boxing or unboxing
    - ets-annotation-unused-generic-alias-warn # Check if type alias unused
    # Warinings that do not keep code in subset:
    subset_unaware:
    - ets-suggest-final           # Suggest final keyword warning
    - ets-remove-async            # Suggests replacing async functions with coroutines
  sub_options:
  - name: werror
    type: bool
    default: false
    description: Treat all enabled warnings as errors
  - name: enable
    description: Specify warnings to enable. Overrided by ':disable=' suboption.
    type: arg_list_t
    default: [ subset_aware, subset_unaware ]
    possible_values: *ETSWarnings
    delimiter: ":"
  - name: disable
    description: Specify warnings to disable. Overrides ':enable=' suboption.
    type: arg_list_t
    default: []
    possible_values: *ETSWarnings
    delimiter: ":"
  - name: base-path
    type: std::string
    default: ""
    description: Base directory for relative paths of filenames in warnings;
  - name: diagnostic-format
    type: std::string
    default: default
    possible_values:
    - default
    - build-system
    description: Diagnostic output format

- name: debugger-eval
  description: Compile given file in evaluation mode
  sub_options:
  - name: line
    type: uint64_t
    default: 0
    description: Line in the source file code where evaluate occurs.
  - name: source
    type: std::string
    default: ""
    description: Path to evaluation mode source file
  - name: panda-files
    type: arg_list_t
    default: []
    description: Paths to evaluation mode (.abc) files, must be accessible
    delimiter: ":"

- name: generate-decl
  description: Input static file and generate static declaration files
  sub_options:
  - name: enabled
    type: bool
    default: false
    description: Whether to enable static declaration file generation
  - name: path
    type: std::string
    default: ""
    description: Output path for generated static declaration files

- name: emit-declaration
  type: bool
  default: false
  description: Emit declaration to .abc file

- name: thread
  type: int
  default: 0
  description: Number of worker threads

- name: dump-size-stat
  type: bool
  default: false
  description: Dump size statistics

- name: output
  type: std::string
  default: ""
  description: Compiler binary output (.abc)

- name: log-level
  type: std::string
  default: error
  description: Log-level
  possible_values:
  - debug
  - info
  - warning
  - error
  - fatal

- name: stdlib
  type: std::string
  default: ""
  description: Path to standard library

- name: gen-stdlib
  type: bool
  default: false
  description: Gen standard library

- name: plugins
  type: arg_list_t
  default: []
  description: Plugins
  delimiter: ","

- name: skip-phases
  type: arg_list_t
  default: []
  description: Phases to skip
  delimiter: ","

- name: ast-verifier
  description: Configure AST-verifier.
  enum: &VerifierInvariants
    Base:
    - NodeHasParent
    - NodeHasSourceRange
    - EveryChildHasValidParent
    - EveryChildInParentRange
    AfterPluginsAfterParse:
    - CheckStructDeclaration
    AfterScopesInitPhase:
    - VariableHasScope
    AfterCheckerPhase:
    - NodeHasType
    - NoPrimitiveTypes
    - EnumHasCorrectType
    - IdentifierHasVariable
    - ReferenceTypeAnnotationIsNull
    - ArithmeticOperationValid
    - SequenceExpressionHasLastType
    - ForLoopCorrectlyInitialized
    - VariableHasEnclosingScope
    - ModifierAccessValid
    - VariableNameIdentifierNameSame
    - CheckAbstractMethod
    - GetterSetterValidation
    - CheckScopeDeclaration
    - CheckConstProperties
    # - ImportExportAccessValid
  sub_options:
  - name: warnings
    type: arg_list_t
    description: Print warnings and continue compilation even if AST tree is incorrect.
    default: [ ]
    possible_values: *VerifierInvariants
    delimiter: ':'
  - name: errors
    type: arg_list_t
    description: Print errors and aborts compilation if AST tree is incorrect.
    default:
    - ArithmeticOperationValid
    - CheckAbstractMethod
    # - CheckConstProperties
    # - CheckScopeDeclaration
    - CheckStructDeclaration
    - EveryChildHasValidParent
    # - EveryChildInParentRange
    - ForLoopCorrectlyInitialized
    - GetterSetterValidation
    - IdentifierHasVariable
    - ModifierAccessValid
    - NodeHasParent
    # - NodeHasSourceRange
    - NodeHasType
    - NoPrimitiveTypes
    - EnumHasCorrectType
    - ReferenceTypeAnnotationIsNull
    - SequenceExpressionHasLastType
    - VariableHasEnclosingScope
    - VariableHasScope
    - VariableNameIdentifierNameSame
    possible_values: *VerifierInvariants
    delimiter: ':'
  - name: phases
    type: arg_list_t
    default: [ "after" ]
    description: >
      Specify phases to finalize with ASTVerifier. Shortcuts: "before", "each", "after".
    delimiter: ':'
  - name: full-program
    type: bool
    default: false
    description: Analyze full program, including program AST and it's dependencies
  - name: json
    type: bool
    default: false
    description: Report in json-format instead of stderr dump. More verbose.
  - name: json-path
    type: std::string
    default: "astverifier_report.json"
    description: Path to json-dump (if enabled)

- name: list-phases
  type: bool
  default: false
  description: Dump list of available phases

- name: ets-unnamed
  type: bool
  default: false
  description: Legacy option to compile a module as unnamed

- name: ets-path
  type: std::string
  default: ""
  description: Legacy option to set global prefix path for all compiled modules

- name: exit-before-phase
  type: std::string
  default: ""
  description: Exit compilation before running the provided phase

- name: exit-after-phase
  type: std::string
  default: ""
  description: Exit compilation after running the provided phase

- name: dump-before-phases
  type: arg_list_t
  default: []
  description: Generate program dump before running phases in the list
  delimiter: ","

- name: dump-after-phases
  type: arg_list_t
  default: []
  description: Generate program dump after running phases in the list
  delimiter: ","

- name: dump-ets-src-before-phases
  type: arg_list_t
  default: []
  description: Generate program dump as ets source code before running phases in the list
  delimiter: ","

- name: dump-ets-src-after-phases
  type: arg_list_t
  default: []
  description: Generate program dump as ets source code after running phases in the list
  delimiter: ","

- name: bco-optimizer
  type: arg_list_t
  default: []
  description: Bytecode optimizer arguments

- name: bco-compiler
  type: arg_list_t
  default: []
  description: Bytecode optimizer's compiler arguments

- name: dump-perf-metrics
  type: bool
  default: false
  description: Dump es2panda performance metrics

- name: simultaneous
  type: bool
  default: false
  description: compile all the files to abc in once.

- name: store-declaration-cache-directly-in-memory
  type: bool
  default: false
  description: |
    If some of the cache-decls are generated, besides generating a file,
    directly emplace them in global memory.

#26986
- name: ets-strings-concat
  type: bool
  default: true
  description: "(experimental) Use StringBuilder.concat instead of StringBuilder.append"

- name: permit-relaxed-any
  type: bool
  default: false
  description: "Permit experimental 'any' type annotation"

- name: emit-metadata
  type: bool
  default: false
  description: "(experimental) Emit metadata into abc file, to use it while importing the current module from other modules instead of using sources directly"

- name: stackless-coros
  type: bool
  default: false
  description: "(experimental) Emit bytecode that supports stackless coroutines"

- name: incremental
  type: bool
  default: false
  description: "Enable incremental build. Together with 'simultaneous' flag, the compiler produces several abc files, one for each input source file."

- name: read-metadata
  type: bool
  default: false
  description: "(experimental) Use metadata (if recorded) when importing the module with abc file provided"