1#!/usr/bin/env python3 2# -*- coding: utf-8 -*- 3# 4# Copyright (C) 2024 Antmicro 5# 6# Licensed under the Apache License, Version 2.0 (the "License"); 7# you may not use this file except in compliance with the License. 8# You may obtain a copy of the License at 9# 10# http://www.apache.org/licenses/LICENSE-2.0 11# 12# Unless required by applicable law or agreed to in writing, software 13# distributed under the License is distributed on an "AS IS" BASIS, 14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15# See the License for the specific language governing permissions and 16# limitations under the License. 17# 18# SPDX-License-Identifier: Apache-2.0 19 20from . import ast, operators as op, op_null, op_order 21from .helper import Visitor 22 23class MakeAllPublic(Visitor): 24 def __init__(self, nodes: ast.Node, verbose: bool = False) -> None: 25 super().__init__(nodes, verbose) 26 27 def visit_VariableDecl(self, node: ast.VariableDecl) -> None: 28 node.access = ast.AccessibilityMod.PUBLIC 29 30 def visit_InvokableDefinition(self, node: ast.InvokableDefinition) -> None: 31 # Hack for ignoring interface and partial methods 32 if not (isinstance(node, ast.MethodDefinition) and '.' in node.name) \ 33 and not node.partial: 34 node.access = ast.AccessibilityMod.PUBLIC 35 36 def visit_Class(self, node: ast.Class) -> None: 37 node.access = ast.AccessibilityMod.PUBLIC 38 39 self.iterate_children_dfs(node) 40 41def process_ast(root: ast.Node, make_all_public: bool = False) -> ast.Node: 42 op_null.EvalNulls(root) 43 op_order.OrderOperators(root) 44 45 if make_all_public: 46 MakeAllPublic(root, verbose=True) 47 48 return root 49