<commit_before>// @(#)root/reflex:$Id$
// Author: <NAME> 2004

// Copyright CERN, CH-1211 Geneva 23, 2004-2006, All rights reserved.
//
// Permission to use, copy, modify, and distribute this software for any
// purpose is hereby granted without fee, provided that this copyright and
// permissions notice appear in all copies and derivatives.
//
// This software is provided "as is" without express or implied warranty.

#ifndef REFLEX_BUILD
#define REFLEX_BUILD
#endif

#include "Reflex/Kernel.h"

#include "Reflex/Scope.h"
#include "Reflex/internal/ScopeName.h"
#include "Reflex/PropertyList.h"
#include "Reflex/Type.h"
#include "Reflex/Base.h"
#include "Reflex/Member.h"
#include "Reflex/Object.h"
#include "Reflex/PropertyList.h"
#include "Reflex/MemberTemplate.h"
#include "Reflex/Any.h"

#include "Fundamental.h"
#include "Namespace.h"
#include "Typedef.h"
#include "Class.h"
#include <typeinfo>


//-------------------------------------------------------------------------------
Reflex::Instance::Instance() {
//-------------------------------------------------------------------------------
// Initialisation of Reflex.Setup of global scope, fundamental types.

   static bool initialized = false;

   if (initialized) {
      return;
   }

   initialized = true;

   /** initialisation of the global namespace */
   Namespace::GlobalScope();

   // initialising fundamental types
   TypeBase* tb = 0;
   Type t = Type();
 
   // char [3.9.1.1]
   tb = new TypeBase( "char", sizeof( char ), FUNDAMENTAL, typeid( char ), Type(), REPRES_CHAR);
   tb->Properties().AddProperty( "Description", "fundamental type" );

   // signed integer types [3.9.1.2]
   tb = new TypeBase( "signed char", sizeof( signed char ), FUNDAMENTAL, typeid( signed char ), Type(), REPRES_SIGNED_CHAR);
   tb->Properties().AddProperty( "Description", "fundamental type" );

   tb = new TypeBase( "short int", sizeof( short int ), FUNDAMENTAL, typeid( short int ), Type(), REPRES_SHORT_INT);
   tb->Properties().AddProperty( "Description", "fundamental type" );
   t = tb->ThisType();
   new Typedef( "short", t, FUNDAMENTAL, t );
   new Typedef( "signed short", t, FUNDAMENTAL, t );
   new Typedef( "short signed", t, FUNDAMENTAL, t );
   new Typedef( "signed short int", t, FUNDAMENTAL, t );
   new Typedef( "short signed int", t, FUNDAMENTAL, t );

   tb = new TypeBase( "int", sizeof( int ), FUNDAMENTAL, typeid( int ), Type(), REPRES_INT);
   tb->Properties().AddProperty( "Description", "fundamental type" );
   t = tb->ThisType();
   new Typedef( "signed", t, FUNDAMENTAL, t );
   new Typedef( "signed int", t, FUNDAMENTAL, t );

   tb = new TypeBase( "long int", sizeof( long int ), FUNDAMENTAL, typeid( long int ), Type(), REPRES_LONG_INT);
   tb->Properties().AddProperty( "Description", "fundamental type" );
   t = tb->ThisType();
   new Typedef( "long", t, FUNDAMENTAL, t );
   new Typedef( "signed long", t, FUNDAMENTAL, t );
   new Typedef( "long signed", t, FUNDAMENTAL, t );
   new Typedef( "signed long int", t, FUNDAMENTAL, t );
   new Typedef( "long signed int", t, FUNDAMENTAL, t );

   // unsigned integer types [3.9.1.3]
   tb = new TypeBase( "unsigned char", sizeof( unsigned char ), FUNDAMENTAL, typeid( unsigned char ), Type(), REPRES_UNSIGNED_CHAR);
   tb->Properties().AddProperty( "Description", "fundamental type" );

   tb = new TypeBase( "unsigned short int", sizeof( unsigned short int ), FUNDAMENTAL, typeid( unsigned short int ), Type(), REPRES_UNSIGNED_SHORT_INT);
   tb->Properties().AddProperty( "Description", "fundamental type" );
   t = tb->ThisType();
   new Typedef( "unsigned short", t, FUNDAMENTAL, t );
   new Typedef( "short unsigned int", t, FUNDAMENTAL, t );

   tb = new TypeBase( "unsigned int", sizeof( unsigned int ), FUNDAMENTAL, typeid( unsigned int ), Type(), REPRES_UNSIGNED_INT);
   tb->Properties().AddProperty( "Description", "fundamental type" );
   t = tb->ThisType();
   new Typedef( "unsigned", t, FUNDAMENTAL, t );

   tb = new TypeBase( "unsigned long int", sizeof( unsigned long int ), FUNDAMENTAL, typeid( unsigned long int ), Type(), REPRES_UNSIGNED_LONG_INT);
   tb->Properties().AddProperty( "Description", "fundamental type" );
   t = tb->ThisType();
   new Typedef( "unsigned long", t, FUNDAMENTAL, t );
   new Typedef( "long unsigned", t, FUNDAMENTAL, t );
   new Typedef( "long unsigned int", t, FUNDAMENTAL, t );

   /*/ w_chart [3.9.1.5]
     tb = new TypeBase( "w_chart", 
     sizeof( w_chart ), 
     & typeid( w_chart ));
     tb->Properties().AddProperty( "Description", "fundamental type" );
   */

   // bool [3.9.1.6]
   tb = new TypeBase( "bool", sizeof( bool ), FUNDAMENTAL, typeid( bool ), Type(), REPRES_BOOL);
   tb->Properties().AddProperty( "Description", "fundamental type" );

   // floating point types [3.9.1.8]
   tb = new TypeBase( "float", sizeof( float ), FUNDAMENTAL, typeid( float ), Type(), REPRES_FLOAT);
   tb->Properties().AddProperty( "Description", "fundamental type" );

   tb = new TypeBase( "double", sizeof( double ), FUNDAMENTAL, typeid( double ), Type(), REPRES_DOUBLE);
   tb->Properties().AddProperty( "Description", "fundamental type" );

   tb = new TypeBase( "long double", sizeof( long double ), FUNDAMENTAL, typeid( long double ), Type(), REPRES_LONG_DOUBLE);
   tb->Properties().AddProperty( "Description", "fundamental type" );

   // void [3.9.1.9]
   tb = new TypeBase( "void", 0, FUNDAMENTAL, typeid( void ), Type(), REPRES_VOID);
   tb->Properties().AddProperty( "Description", "fundamental type" );

      // Large integer definition depends of the platform
#if defined(_WIN32) && !defined(__CINT__)
   typedef __int64 longlong;
   typedef unsigned __int64 ulonglong;
#else
   typedef long long int longlong; /* */
   typedef unsigned long long int /**/ ulonglong;
#endif

   // non fundamental types but also supported at initialisation
   tb = new TypeBase( "long long", sizeof( longlong ), FUNDAMENTAL, typeid( longlong ), Type(), REPRES_LONGLONG);
   tb->Properties().AddProperty( "Description", "fundamental type" );
   t = tb->ThisType();
   new Typedef( "long long int", t, FUNDAMENTAL, t );

   tb = new TypeBase( "unsigned long long", sizeof( ulonglong ), FUNDAMENTAL, typeid( ulonglong ), Type(), REPRES_ULONGLONG);
   tb->Properties().AddProperty( "Description", "fundamental type" );
   t = tb->ThisType();
   new Typedef( "long long unsigned", t, FUNDAMENTAL, t );
   new Typedef( "unsigned long long int", t, FUNDAMENTAL, t );
   new Typedef( "long long unsigned int", t, FUNDAMENTAL, t );

}


//-------------------------------------------------------------------------------
void Reflex::Instance::Shutdown() {
//-------------------------------------------------------------------------------
   // function to be called at tear down of Reflex, removes all memory allocations
   MemberTemplateName::CleanUp();
   TypeTemplateName::CleanUp();
   TypeName::CleanUp();
   ScopeName::CleanUp();<commit_msg>Simplify creation of fundamentals by factoring out the common code.<commit_after>// @(#)root/reflex:$Id$
// Author: <NAME> 2004

// Copyright CERN, CH-1211 <NAME>3, 2004-2006, All rights reserved.
//
// Permission to use, copy, modify, and distribute this software for any
// purpose is hereby granted without fee, provided that this copyright and
// permissions notice appear in all copies and derivatives.
//
// This software is provided "as is" without express or implied warranty.

#ifndef REFLEX_BUILD
#define REFLEX_BUILD
#endif

#include "Reflex/Kernel.h"

#include "Reflex/Scope.h"
#include "Reflex/internal/ScopeName.h"
#include "Reflex/PropertyList.h"
#include "Reflex/Type.h"
#include "Reflex/Base.h"
#include "Reflex/Member.h"
#include "Reflex/Object.h"
#include "Reflex/PropertyList.h"
#include "Reflex/MemberTemplate.h"
#include "Reflex/Any.h"

#include "Fundamental.h"
#include "Namespace.h"
#include "Typedef.h"
#include "Class.h"
#include <typeinfo>

namespace {
   // Helper to factor out common code
   class FundamentalDeclarator {
   public:
      FundamentalDeclarator(const char* name, size_t size, const std::type_info& ti,
                            Reflex::REPRESTYPE repres) {
         Reflex::TypeBase* tb = new Reflex::TypeBase(name, size, Reflex::FUNDAMENTAL,
                                                     ti, Reflex::Type(), repres);
         tb->Properties().AddProperty( "Description", "fundamental type" );
         fType = tb->ThisType();
      }

      FundamentalDeclarator& Typedef(const char* name) {
         new Reflex::Typedef(name, fType, Reflex::FUNDAMENTAL, fType);
         return *this;
      }
   private:
      Reflex::Type fType;
   };

   // sizeof(void) doesn't work; we want it to return 0.
   // This template with the specialization does just that.
   template <typename T>
   struct GetSizeOf {
      size_t operator()() const { return sizeof(T); }
   };
   template <>
   struct GetSizeOf<void> {
      size_t operator()() const { return 0; }
   };

   // Helper function constructing the declarator
   template <typename T>
   FundamentalDeclarator DeclFundamental(const char* name, Reflex::REPRESTYPE repres) {
      return FundamentalDeclarator(name, GetSizeOf<T>()(), typeid(T), repres);
   }
}

//-------------------------------------------------------------------------------
Reflex::Instance::Instance() {
//-------------------------------------------------------------------------------
// Initialisation of Reflex.Setup of global scope, fundamental types.

   static bool initialized = false;

   if (initialized) {
      return;
   }

   initialized = true;

   /** initialisation of the global namespace */
   Namespace::GlobalScope();

   // initialising fundamental types
   // char [3.9.1.1]
   DeclFundamental<char>("char", REPRES_CHAR);

   // signed integer types [3.9.1.2]
   DeclFundamental<signed char>("signed char", REPRES_SIGNED_CHAR);

   DeclFundamental<short int>("short int", REPRES_SHORT_INT)
      .Typedef("short")
      .Typedef("signed short")
      .Typedef("short signed")
      .Typedef("signed short int")
      .Typedef("short signed int");

   DeclFundamental<int>("int", REPRES_INT)
      .Typedef("signed")
      .Typedef("signed int");

   DeclFundamental<long int>("long int", REPRES_LONG_INT)
      .Typedef("long")
      .Typedef("signed long")
      .Typedef("long signed")
      .Typedef("signed long int")
      .Typedef("long signed int");

   // unsigned integer types [3.9.1.3]
   DeclFundamental<unsigned char>("unsigned char", REPRES_UNSIGNED_CHAR);

   DeclFundamental<unsigned short int>("unsigned short int", REPRES_UNSIGNED_SHORT_INT)
      .Typedef("unsigned short")
      .Typedef("short unsigned int");

   DeclFundamental<unsigned int>("unsigned int", REPRES_UNSIGNED_INT)
      .Typedef("unsigned");

   DeclFundamental<unsigned long int>("unsigned long int", REPRES_UNSIGNED_LONG_INT)
      .Typedef("unsigned long")
      .Typedef("long unsigned")
      .Typedef("long unsigned int");

   /* w_chart [3.9.1.5]
      DeclFundamental<w_chart>("w_chart", REPRES_WCHART);
   */

   // bool [3.9.1.6]
   DeclFundamental<bool>("bool", REPRES_BOOL);

   // floating point types [3.9.1.8]
   DeclFundamental<float>("float", REPRES_FLOAT);
   DeclFundamental<double>("double", REPRES_DOUBLE);
   DeclFundamental<long double>("long double", REPRES_LONG_DOUBLE);

   // void [3.9.1.9]
   DeclFundamental<void>("void", REPRES_VOID);

      // Large integer definition depends of the platform
#if defined(_WIN32) && !defined(__CINT__)
   typedef __int64 longlong;
   typedef unsigned __int64 ulonglong;
#else
   typedef long long int longlong; /* */
   typedef unsigned long long int /**/ ulonglong;
#endif

   // non fundamental types but also supported at initialisation
   DeclFundamental<longlong>("long long", REPRES_LONGLONG)
      .Typedef("long long int");

   DeclFundamental<ulonglong>("unsigned long long", REPRES_ULONGLONG)
      .Typedef("long long unsigned")
      .Typedef("unsigned long long int")
      .Typedef("long long unsigned int");

}


//-------------------------------------------------------------------------------
void Reflex::Instance::Shutdown() {
//-------------------------------------------------------------------------------
   // function to be called at tear down of Reflex, removes all memory allocations
   MemberTemplateName::CleanUp();
   TypeTemplateName::CleanUp();
   TypeName::CleanUp();
   ScopeName::CleanUp();
{'fraction_non_alphanumeric': 0.1862246955399629, 'fraction_numerical': 0.00862972820388741, 'mean_word_length': 3.0233614536015576, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 14, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6480584', 'n_tokens_mistral': 3927, 'n_tokens_neox': 3716, 'n_words': 1079}