<commit_before># Copyright FuseSoC contributors
# Licensed under the 2-Clause BSD License, see LICENSE for details.
# SPDX-License-Identifier: BSD-2-Clause

# FIXME: Add IP-XACT support
import logging
import os
import shutil
import warnings

import yaml
from edalize import get_edatools

from fusesoc import utils
from fusesoc.capi2.exprs import Exprs
from fusesoc.provider import get_provider
from fusesoc.vlnv import Vlnv

logger = logging.getLogger(__name__)


class File:
    def __init__(self, tree):
        self.copyto = ""
        self.file_type = ""
        self.is_include_file = False
        self.include_path = None
        self.logical_name = ""
        if type(tree) is dict:
            for k, v in tree.items():
                self.name = StringWithUseFlags(os.path.expandvars(k))
                self.file_type = v.get("file_type", "")
                self.is_include_file = v.get("is_include_file", False)
                self.include_path = v.get("include_path")
                self.copyto = v.get("copyto", "")
                self.logical_name = v.get("logical_name", "")
        else:
            self.name = StringWithUseFlags(os.path.expandvars(tree))
            self.is_include_file = False  # "FIXME"


class Genparams(dict):
    pass


class StringWithUseFlags(str):
    """ A parsed string with support for use flags. """

    def __init__(self, string):
        self.exprs = None

    def parse(self, flags):
        if self.exprs is None:
            self.exprs = Exprs(str(self))
        return self.exprs.expand(flags)


class String(str):
    """ A plain (unparsed) string. """

    def parse(self, flags):
        raise RuntimeError(
            "BUG: Attempted to parse a plain string. This is a bug in FuseSoC. "
            "Please file an issue at "
            "https://github.com/olofk/fusesoc/issues/new."
        )


class StringWithUseFlagsOrList:
    def __new__(cls, *args, **kwargs):
        if type(args[0]) == list:
            return [StringWithUseFlags(s) for s in args[0]]
        elif type(args[0]) == str:
            return [StringWithUseFlags(args[0])]


class StringWithUseFlagsOrDict:
    def __init__(self, tree):
        self.params = {}
        if type(tree) is dict:
            for k, v in tree.items():
                self.params = v
                self.name = StringWithUseFlags(os.path.expandvars(k))
        else:
            self.name = StringWithUseFlags(os.path.expandvars(tree))


class Section:
    members = {}
    lists = {}
    dicts = {}

    def __init__(self, tree):
        for k, v in sorted(tree.items()):
            if v is None:
                continue<commit_msg>Remove variable expansion from generate names<commit_after># Copyright FuseSoC contributors
# Licensed under the 2-Clause BSD License, see LICENSE for details.
# SPDX-License-Identifier: BSD-2-Clause

# FIXME: Add IP-XACT support
import logging
import os
import shutil
import warnings

import yaml
from edalize import get_edatools

from fusesoc import utils
from fusesoc.capi2.exprs import Exprs
from fusesoc.provider import get_provider
from fusesoc.vlnv import Vlnv

logger = logging.getLogger(__name__)


class File:
    def __init__(self, tree):
        self.copyto = ""
        self.file_type = ""
        self.is_include_file = False
        self.include_path = None
        self.logical_name = ""
        if type(tree) is dict:
            for k, v in tree.items():
                self.name = StringWithUseFlags(os.path.expandvars(k))
                self.file_type = v.get("file_type", "")
                self.is_include_file = v.get("is_include_file", False)
                self.include_path = v.get("include_path")
                self.copyto = v.get("copyto", "")
                self.logical_name = v.get("logical_name", "")
        else:
            self.name = StringWithUseFlags(os.path.expandvars(tree))
            self.is_include_file = False  # "FIXME"


class Genparams(dict):
    pass


class StringWithUseFlags(str):
    """ A parsed string with support for use flags. """

    def __init__(self, string):
        self.exprs = None

    def parse(self, flags):
        if self.exprs is None:
            self.exprs = Exprs(str(self))
        return self.exprs.expand(flags)


class String(str):
    """ A plain (unparsed) string. """

    def parse(self, flags):
        raise RuntimeError(
            "BUG: Attempted to parse a plain string. This is a bug in FuseSoC. "
            "Please file an issue at "
            "https://github.com/olofk/fusesoc/issues/new."
        )


class StringWithUseFlagsOrList:
    def __new__(cls, *args, **kwargs):
        if type(args[0]) == list:
            return [StringWithUseFlags(s) for s in args[0]]
        elif type(args[0]) == str:
            return [StringWithUseFlags(args[0])]


class StringWithUseFlagsOrDict:
    def __init__(self, tree):
        self.params = {}
        if type(tree) is dict:
            for k, v in tree.items():
                self.params = v
                self.name = StringWithUseFlags(k)
        else:
            self.name = StringWithUseFlags(tree)


class Section:
    members = {}
    lists = {}
    dicts = {}

    def __init__(self, tree):
        for k, v in sorted(tree.items()):
            if v is None:
                continue
{'fraction_non_alphanumeric': 0.1060377358490566, 'fraction_numerical': 0.0026415094339622643, 'mean_word_length': 2.2088377723970942, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3354742', 'n_tokens_mistral': 1636, 'n_tokens_neox': 1599, 'n_words': 426}