<commit_before>/*
 * Copyright © 2014 <NAME> (<EMAIL>)
 *
 * 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.
 */
package org.emmalanguage
package ast

import util.Monoids._

import cats.std.all._
import shapeless._

import scala.annotation.tailrec

trait Symbols { this: AST =>

  trait SymbolAPI { this: API =>

    import universe._
    import definitions._
    import internal._
    import reificationSupport._
    import Flag.IMPLICIT

    object Sym extends Node {

      // ------------------------------------------------------------------------------------------
      // Predefined symbols
      // ------------------------------------------------------------------------------------------

      lazy val none    = u.NoSymbol
      lazy val foreach = Type[TraversableOnce[Nothing]]
        .member(TermName.foreach).asMethod

      /** A map of all tuple symbols by number of elements. */
      lazy val tuple: Map[Int, u.ClassSymbol] =
        TupleClass.seq.view.zipWithIndex.map {
          case (cls, n) => n + 1 -> cls
        }.toMap

      /** A set of all tuple symbols. */
      lazy val tuples: Set[u.Symbol] =
        TupleClass.seq.toSet

      /** A map of all lambda function symbols by number of arguments. */
      lazy val fun: Map[Int, u.ClassSymbol] =
        FunctionClass.seq.view.zipWithIndex.map(_.swap).toMap

      /** A set of all lambda function symbols. */
      lazy val funs: Set[u.Symbol] =
        FunctionClass.seq.toSet

      // ------------------------------------------------------------------------------------------
      // Utility methods
      // ------------------------------------------------------------------------------------------

      /** Returns the flags associated with `sym`. */
      def flags(sym: u.Symbol): u.FlagSet =
        internal.flags(sym)

      /** Returns modifiers corresponding to the definition of `sym`. */
      def mods(sym: u.Symbol): u.Modifiers =
        u.Modifiers(flags(sym), TypeName.empty, sym.annotations.map(_.tree))

      /** Returns any annotation of type `A` associated with `sym`. */
      def findAnn[A: TypeTag](sym: u.Symbol): Option[u.Annotation] =
        sym.annotations.find(_.tree.tpe =:= Type[A])

      /** Copy / extractor for symbol attributes. */
      object With {

        /** Creates a copy of `sym`, optionally changing some of its attributes. */
        def apply[S <: u.Symbol](sym: S)(
          own: u.Symbol          = sym.owner,
          nme: u.Name            = sym.name,
          tpe: u.Type            = sym.info,
          pos: u.Position        = sym.pos,
          flg: u.FlagSet         = flags(sym),
          ans: Seq[u.Annotation] = Seq.empty
        ): S = {
          // Optimize when there are no changes.
          val noChange = own == sym.owner &&
            nme == sym.name &&
            tpe == sym.info &&
            pos == sym.pos &&<commit_msg>[IR] Added api.Sym.apply[T] for type symbols<commit_after>/*
 * Copyright © 2014 <NAME> (<EMAIL>)
 *
 * 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.
 */
package org.emmalanguage
package ast

import util.Monoids._

import cats.std.all._
import shapeless._

import scala.annotation.tailrec

trait Symbols { this: AST =>

  trait SymbolAPI { this: API =>

    import universe._
    import definitions._
    import internal._
    import reificationSupport._
    import Flag.IMPLICIT

    object Sym extends Node {

      // ------------------------------------------------------------------------------------------
      // Predefined symbols
      // ------------------------------------------------------------------------------------------

      lazy val none    = u.NoSymbol
      lazy val foreach = Type[TraversableOnce[Nothing]]
        .member(TermName.foreach).asMethod

      /** A map of all tuple symbols by number of elements. */
      lazy val tuple: Map[Int, u.ClassSymbol] =
        TupleClass.seq.view.zipWithIndex.map {
          case (cls, n) => n + 1 -> cls
        }.toMap

      /** A set of all tuple symbols. */
      lazy val tuples: Set[u.Symbol] =
        TupleClass.seq.toSet

      /** A map of all lambda function symbols by number of arguments. */
      lazy val fun: Map[Int, u.ClassSymbol] =
        FunctionClass.seq.view.zipWithIndex.map(_.swap).toMap

      /** A set of all lambda function symbols. */
      lazy val funs: Set[u.Symbol] =
        FunctionClass.seq.toSet

      // ------------------------------------------------------------------------------------------
      // Utility methods
      // ------------------------------------------------------------------------------------------

      /** Returns the symbol corresponding to a type. */
      def apply[T: u.WeakTypeTag]: u.Symbol = {
        val sym = symbolOf[T]
        if (sym.isModuleClass) sym.asClass.module else sym
      }

      /** Returns the flags associated with `sym`. */
      def flags(sym: u.Symbol): u.FlagSet =
        internal.flags(sym)

      /** Returns modifiers corresponding to the definition of `sym`. */
      def mods(sym: u.Symbol): u.Modifiers =
        u.Modifiers(flags(sym), TypeName.empty, sym.annotations.map(_.tree))

      /** Returns any annotation of type `A` associated with `sym`. */
      def findAnn[A: TypeTag](sym: u.Symbol): Option[u.Annotation] =
        sym.annotations.find(_.tree.tpe =:= Type[A])

      /** Copy / extractor for symbol attributes. */
      object With {

        /** Creates a copy of `sym`, optionally changing some of its attributes. */
        def apply[S <: u.Symbol](sym: S)(
          own: u.Symbol          = sym.owner,
          nme: u.Name            = sym.name,
          tpe: u.Type            = sym.info,
          pos: u.Position        = sym.pos,
          flg: u.FlagSet         = flags(sym),
          ans: Seq[u.Annotation] = Seq.empty
        ): S = {
          // Optimize when there are no changes.
          val noChange = own == sym.owner &&
            nme == sym.name &&
            tpe == sym.info &&
            pos == sym.pos &&
{'fraction_non_alphanumeric': 0.20213371266002844, 'fraction_numerical': 0.0025604551920341396, 'mean_word_length': 1.5511611030478956, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6345140', 'n_tokens_mistral': 1837, 'n_tokens_neox': 1792, 'n_words': 610}