13af6ab5fSopenharmony_ci#!/usr/bin/env ruby
23af6ab5fSopenharmony_ci# Copyright (c) 2021-2024 Huawei Device Co., Ltd.
33af6ab5fSopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License");
43af6ab5fSopenharmony_ci# you may not use this file except in compliance with the License.
53af6ab5fSopenharmony_ci# You may obtain a copy of the License at
63af6ab5fSopenharmony_ci#
73af6ab5fSopenharmony_ci# http://www.apache.org/licenses/LICENSE-2.0
83af6ab5fSopenharmony_ci#
93af6ab5fSopenharmony_ci# Unless required by applicable law or agreed to in writing, software
103af6ab5fSopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS,
113af6ab5fSopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
123af6ab5fSopenharmony_ci# See the License for the specific language governing permissions and
133af6ab5fSopenharmony_ci# limitations under the License.
143af6ab5fSopenharmony_ci
153af6ab5fSopenharmony_cirequire 'ostruct'
163af6ab5fSopenharmony_cirequire 'set'
173af6ab5fSopenharmony_cirequire 'delegate'
183af6ab5fSopenharmony_ci
193af6ab5fSopenharmony_cimodule Signatures
203af6ab5fSopenharmony_ci  DEFINES = Hash.new()
213af6ab5fSopenharmony_ci  SIGNATURES = Hash.new()
223af6ab5fSopenharmony_ci  BUILTINS = Hash.new()
233af6ab5fSopenharmony_ci  PRIMITIVES = Hash.new()
243af6ab5fSopenharmony_ci  TYPEDESCRIPTORS = Hash.new()
253af6ab5fSopenharmony_ci  DYNAMIC = Hash.new()
263af6ab5fSopenharmony_ci
273af6ab5fSopenharmony_ci  def wrap_data(data)
283af6ab5fSopenharmony_ci    refs = Hash.new()
293af6ab5fSopenharmony_ci
303af6ab5fSopenharmony_ci    unless data
313af6ab5fSopenharmony_ci      return
323af6ab5fSopenharmony_ci    end
333af6ab5fSopenharmony_ci
343af6ab5fSopenharmony_ci    data.defines.each do |define|
353af6ab5fSopenharmony_ci      refs[define.ref] = define.name
363af6ab5fSopenharmony_ci      Signatures::DEFINES[define.ref] = define
373af6ab5fSopenharmony_ci    end
383af6ab5fSopenharmony_ci
393af6ab5fSopenharmony_ci    data.packages.each do |package|
403af6ab5fSopenharmony_ci        refs[package.ref] = package.name
413af6ab5fSopenharmony_ci    end
423af6ab5fSopenharmony_ci
433af6ab5fSopenharmony_ci    data.primitives.each do |primitive|
443af6ab5fSopenharmony_ci        refs[primitive.ref] = primitive.name
453af6ab5fSopenharmony_ci        Signatures::PRIMITIVES[primitive.ref] = primitive.name
463af6ab5fSopenharmony_ci    end
473af6ab5fSopenharmony_ci
483af6ab5fSopenharmony_ci    data.typedescriptors.each do |typedescriptor|
493af6ab5fSopenharmony_ci      refs[typedescriptor.ref] = typedescriptor.name
503af6ab5fSopenharmony_ci      Signatures::TYPEDESCRIPTORS[typedescriptor.ref] = typedescriptor.name
513af6ab5fSopenharmony_ci    end
523af6ab5fSopenharmony_ci
533af6ab5fSopenharmony_ci    data.builtins.each do |builtin|
543af6ab5fSopenharmony_ci        sig = "%s.%s" % [refs[builtin.package], builtin.name]
553af6ab5fSopenharmony_ci        refs[builtin.ref] = sig
563af6ab5fSopenharmony_ci        Signatures::BUILTINS[builtin.ref] = [sig, builtin.name]
573af6ab5fSopenharmony_ci    end
583af6ab5fSopenharmony_ci
593af6ab5fSopenharmony_ci    data.signatures.each do |signature|
603af6ab5fSopenharmony_ci        method_name = signature.method_name.start_with?('$') ? refs[signature.method_name[1..-1]] : signature.method_name
613af6ab5fSopenharmony_ci        sig = "%s.%s:" % [refs[signature.callee], method_name]
623af6ab5fSopenharmony_ci
633af6ab5fSopenharmony_ci        signature.params.each do |param|
643af6ab5fSopenharmony_ci            sig += "%s;" % [refs[param]]
653af6ab5fSopenharmony_ci        end
663af6ab5fSopenharmony_ci
673af6ab5fSopenharmony_ci        sig += "%s;" % [refs[signature.return_type]]
683af6ab5fSopenharmony_ci
693af6ab5fSopenharmony_ci        Signatures::SIGNATURES[signature.ref] = sig
703af6ab5fSopenharmony_ci    end
713af6ab5fSopenharmony_ci
723af6ab5fSopenharmony_ci    data.dynamiclangs.each do |lang|
733af6ab5fSopenharmony_ci      Signatures::DYNAMIC[lang.name] = OpenStruct.new(lang)
743af6ab5fSopenharmony_ci    end
753af6ab5fSopenharmony_ci  end
763af6ab5fSopenharmony_ci  module_function :wrap_data
773af6ab5fSopenharmony_ciend
783af6ab5fSopenharmony_ci
793af6ab5fSopenharmony_cidef Gen.on_require(data)
803af6ab5fSopenharmony_ci    Signatures.wrap_data(data)
813af6ab5fSopenharmony_ciend
823af6ab5fSopenharmony_ci
83