<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/Builder/FunctionBuilder.h"

#include "Reflex/PropertyList.h"
#include "Reflex/Scope.h"
#include "Reflex/Any.h"
#include "Reflex/Type.h"
#include "Reflex/Tools.h"
#include "Reflex/internal/OwnedMember.h"

#include "FunctionMember.h"
#include "FunctionMemberTemplateInstance.h"
#include "Namespace.h"


//-------------------------------------------------------------------------------
Reflex::FunctionBuilder::~FunctionBuilder() {
//-------------------------------------------------------------------------------
// Functionbuilder destructor used for call backs.
   FireFunctionCallback( fFunction );
}


//-------------------------------------------------------------------------------
Reflex::FunctionBuilder & 
Reflex::FunctionBuilder::AddProperty( const char * key, 
                                            const char * value ) {
//-------------------------------------------------------------------------------
// Add property info to this function as string.
   fFunction.Properties().AddProperty( key , value );
   return * this;
}


//-------------------------------------------------------------------------------
Reflex::FunctionBuilder & 
Reflex::FunctionBuilder::AddProperty( const char * key, 
                                            Any value ) {
//-------------------------------------------------------------------------------
// Add property info to this function as Any object.
   fFunction.Properties().AddProperty( key , value );
   return * this;
}


//-------------------------------------------------------------------------------
Reflex::Member Reflex::FunctionBuilder::ToMember() {
//-------------------------------------------------------------------------------
   // Return the function currently being built.
   return fFunction;
}


//-------------------------------------------------------------------------------
Reflex::FunctionBuilderImpl::FunctionBuilderImpl( const char * nam, 
                                                        const Type & typ,
                                                        StubFunction stubFP,
                                                        void * stubCtx,
                                                        const char * params, 
                                                        unsigned char modifiers) 
   : fFunction( Member(0)) {
//-------------------------------------------------------------------------------
// Create function type dictionary info (internal).
   std::string fullname( nam );
   std::string declScope;
   std::string funcName;
   size_t pos = Tools::GetTemplateName(nam).rfind( "::" );
   // Name contains declaring At
   if ( pos != std::string::npos ) {   
      funcName  = fullname.substr( pos + 2 );
      declScope = fullname.substr( 0, pos ); 
   }
   else {
      funcName  = nam;
      declScope = "";
   }

   Scope sc = Scope::ByName(declScope);
   if ( ! sc ) {
      // Let's create the namespace here
      sc = (new Namespace(declScope.c_str()))->ThisScope();
   }

   if ( ! sc.IsNamespace() ) throw RuntimeError("Declaring scope is not a namespace");
   if ( Tools::IsTemplated( funcName.c_str()))
      fFunction = Member( new FunctionMemberTemplateInstance( funcName.c_str(),
                                                              typ,
                                                              stubFP,
                                                              stubCtx,
                                                              params,
                                                              modifiers,
                                                              sc ));
   else fFunction = Member(new FunctionMember(funcName.c_str(), 
                                              typ, 
                                              stubFP, 
                                              stubCtx, 
                                              params, 
                                              modifiers));
   sc.AddFunctionMember(fFunction);
}


//-------------------------------------------------------------------------------
Reflex::FunctionBuilderImpl::~FunctionBuilderImpl() {
//-------------------------------------------------------------------------------
// FunctionBuilder destructor.
   FireFunctionCallback( fFunction );
}
 

//-------------------------------------------------------------------------------
void Reflex::FunctionBuilderImpl::AddProperty( const char * key, 
                                                     const char * value ) {
//-------------------------------------------------------------------------------
// Add property info to this function type.
   fFunction.Properties().AddProperty( key , value );
}


//-------------------------------------------------------------------------------
void Reflex::FunctionBuilderImpl::AddProperty( const char * key, 
                                                     Any value ) {
//-------------------------------------------------------------------------------
// Add property info to this function type.
   fFunction.Properties().AddProperty( key , value );
}


//-------------------------------------------------------------------------------
Reflex::Member Reflex::FunctionBuilderImpl::ToMember() {
//-------------------------------------------------------------------------------
   // Return the function member currently being built.
   return fFunction;
}


//-------------------------------------------------------------------------------
Reflex::FunctionBuilder::FunctionBuilder( const Type & typ,
                                                const char * nam, 
                                                StubFunction stubFP,
                                                void * stubCtx,
                                                const char * params, 
                                                unsigned char modifiers) 
   : fFunction(Member(0)) {
//-------------------------------------------------------------------------------
// Create function dictionary type information.
   std::string fullname( nam );
   std::string declScope;
   std::string funcName;
   size_t pos = Tools::GetTemplateName( nam ).rfind( "::" );
   // Name contains declaring scope
   if ( pos != std::string::npos ) {   
      funcName  = fullname.substr( pos + 2 );
      declScope = fullname.substr( 0, pos ); 
   }
   else {
      funcName  = nam;
      declScope = "";
   }
   Scope sc = Scope::ByName(declScope);
   if ( ! sc ) {
      // Let's create the namespace here
      sc = (new Namespace(declScope.c_str()))->ThisScope();
   }
   if ( ! sc.IsNamespace() ) throw RuntimeError("Declaring scope is not a namespace");
   if ( Tools::IsTemplated( funcName.c_str()))
      fFunction = Member( new FunctionMemberTemplateInstance( funcName.c_str(),
                                                              typ,
                                                              stubFP,
                                                              stubCtx,
                                                              params,
                                                              modifiers,
                                                              sc ));
   else fFunction = Member(new FunctionMember( funcName.c_str(), 
                                               typ, 
                                               stubFP, 
                                               stubCtx, 
                                               params, 
                                               modifiers));
   sc.AddFunctionMember(fFunction);
}
<commit_msg>Correct hopelessly naive code in FunctionBuilder constructor which totally failed to parse a scoped name correctly in the presence of a template with scoped template arguments.<commit_after>// @(#)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/Builder/FunctionBuilder.h"

#include "Reflex/PropertyList.h"
#include "Reflex/Scope.h"
#include "Reflex/Any.h"
#include "Reflex/Type.h"
#include "Reflex/Tools.h"
#include "Reflex/internal/OwnedMember.h"

#include "FunctionMember.h"
#include "FunctionMemberTemplateInstance.h"
#include "Namespace.h"


//-------------------------------------------------------------------------------
Reflex::FunctionBuilder::~FunctionBuilder() {
//-------------------------------------------------------------------------------
// Functionbuilder destructor used for call backs.
   FireFunctionCallback( fFunction );
}


//-------------------------------------------------------------------------------
Reflex::FunctionBuilder & 
Reflex::FunctionBuilder::AddProperty( const char * key, 
                                            const char * value ) {
//-------------------------------------------------------------------------------
// Add property info to this function as string.
   fFunction.Properties().AddProperty( key , value );
   return * this;
}


//-------------------------------------------------------------------------------
Reflex::FunctionBuilder & 
Reflex::FunctionBuilder::AddProperty( const char * key, 
                                            Any value ) {
//-------------------------------------------------------------------------------
// Add property info to this function as Any object.
   fFunction.Properties().AddProperty( key , value );
   return * this;
}


//-------------------------------------------------------------------------------
Reflex::Member Reflex::FunctionBuilder::ToMember() {
//-------------------------------------------------------------------------------
   // Return the function currently being built.
   return fFunction;
}


//-------------------------------------------------------------------------------
Reflex::FunctionBuilderImpl::FunctionBuilderImpl( const char * nam, 
                                                        const Type & typ,
                                                        StubFunction stubFP,
                                                        void * stubCtx,
                                                        const char * params, 
                                                        unsigned char modifiers) 
   : fFunction( Member(0)) {
//-------------------------------------------------------------------------------
// Create function type dictionary info (internal).
   std::string fullname( nam );
   std::string declScope;
   std::string funcName;
   size_t pos = Tools::GetTemplateName(nam).rfind( "::" );
   // Name contains declaring At
   if ( pos != std::string::npos ) {   
      funcName  = fullname.substr( pos + 2 );
      declScope = fullname.substr( 0, pos ); 
   }
   else {
      funcName  = nam;
      declScope = "";
   }

   Scope sc = Scope::ByName(declScope);
   if ( ! sc ) {
      // Let's create the namespace here
      sc = (new Namespace(declScope.c_str()))->ThisScope();
   }

   if ( ! sc.IsNamespace() ) throw RuntimeError("Declaring scope is not a namespace");
   if ( Tools::IsTemplated( funcName.c_str()))
      fFunction = Member( new FunctionMemberTemplateInstance( funcName.c_str(),
                                                              typ,
                                                              stubFP,
                                                              stubCtx,
                                                              params,
                                                              modifiers,
                                                              sc ));
   else fFunction = Member(new FunctionMember(funcName.c_str(), 
                                              typ, 
                                              stubFP, 
                                              stubCtx, 
                                              params, 
                                              modifiers));
   sc.AddFunctionMember(fFunction);
}


//-------------------------------------------------------------------------------
Reflex::FunctionBuilderImpl::~FunctionBuilderImpl() {
//-------------------------------------------------------------------------------
// FunctionBuilder destructor.
   FireFunctionCallback( fFunction );
}
 

//-------------------------------------------------------------------------------
void Reflex::FunctionBuilderImpl::AddProperty( const char * key, 
                                                     const char * value ) {
//-------------------------------------------------------------------------------
// Add property info to this function type.
   fFunction.Properties().AddProperty( key , value );
}


//-------------------------------------------------------------------------------
void Reflex::FunctionBuilderImpl::AddProperty( const char * key, 
                                                     Any value ) {
//-------------------------------------------------------------------------------
// Add property info to this function type.
   fFunction.Properties().AddProperty( key , value );
}


//-------------------------------------------------------------------------------
Reflex::Member Reflex::FunctionBuilderImpl::ToMember() {
//-------------------------------------------------------------------------------
   // Return the function member currently being built.
   return fFunction;
}


//-------------------------------------------------------------------------------
Reflex::FunctionBuilder::FunctionBuilder(const Type& typ, const char* nam, StubFunction stubFP, void* stubCtx, const char* params, unsigned char modifiers) : fFunction(Member(0))
{
   // Create function dictionary type information.
   std::string declScope(Tools::GetScopeName(nam));
   std::string funcName(Tools::GetBaseName(nam));
   Scope sc = Scope::ByName(declScope);
   if (!sc) {
      // Let's create the namespace here
      sc = (new Namespace(declScope.c_str()))->ThisScope();
   }
   if (!sc.IsNamespace()) {
      throw RuntimeError("Declaring scope is not a namespace");
   }
   if (Tools::IsTemplated(funcName.c_str())) {
      fFunction = Member(new FunctionMemberTemplateInstance(funcName.c_str(), typ, stubFP, stubCtx, params, modifiers, sc));
   }
   else {
      fFunction = Member(new FunctionMember(funcName.c_str(), typ, stubFP, stubCtx, params, modifiers));
   }
   sc.AddFunctionMember(fFunction);
}

{'fraction_non_alphanumeric': 0.2812274131020435, 'fraction_numerical': 0.003022537617451869, 'mean_word_length': 0.9075072064168442, 'pattern_counts': {'":': 3, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 112, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1062363', 'n_tokens_mistral': 2907, 'n_tokens_neox': 2799, 'n_words': 779}