: m_Type(eType_Primitive), m_IsTemplate(
false), m_DoStoreArg(
false)
68 if( var_name.empty() ) {
69 throwruntime_error(
"No var_name given for CTraversalNode");
100: m_Type(eType_Primitive), m_IsTemplate(
false), m_DoStoreArg(
false)
125 while( parent_asn_node ) {
128 stringparent_class_name = parent_type_strings->
GetCType(parent_ns);
156}
else if(
dynamic_cast<CEnumDataType*
>(asn_node) != 0 ) {
158}
else if(
dynamic_cast<CNullDataType*
>(asn_node) != 0 ) {
163 throwruntime_error(
"possible bug in code generator: unknown type for '"+
m_TypeName+
"'");
186traversal_output_file <<
"template< typename "<<
m_InputClassName<<
" >"<< endl;
188traversal_output_file <<
"void ";
190traversal_output_file << func_class_name <<
"::";
194traversal_output_file <<
m_FuncName<<
"( void )";
203traversal_output_file <<
";"<< endl;
207traversal_output_file << endl;
212traversal_output_file <<
" CRef<CSeq_feat> raw_ref( &arg0_raw );"<< endl;
213traversal_output_file <<
" CSeq_feat_EditHandle efh;"<< endl;
214traversal_output_file << endl;
215traversal_output_file <<
" CRef<CSeq_feat> new_feat;"<< endl;
216traversal_output_file << endl;
217traversal_output_file <<
" try {"<< endl;
218traversal_output_file <<
" // Try to use an edit handle so we can update the object manager"<< endl;
219traversal_output_file <<
" efh = CSeq_feat_EditHandle( m_Scope.GetSeq_featHandle( arg0_raw ) );"<< endl;
220traversal_output_file <<
" new_feat.Reset( new CSeq_feat );"<< endl;
221traversal_output_file <<
" new_feat->Assign( arg0_raw );"<< endl;
222traversal_output_file <<
" } catch(...) {"<< endl;
223traversal_output_file <<
" new_feat.Reset( &arg0_raw );"<< endl;
224traversal_output_file <<
" }"<< endl;
225traversal_output_file << endl;
226traversal_output_file <<
" CSeq_feat &arg0 = *new_feat;"<< endl;
227traversal_output_file << endl;
233traversal_output_file << endl;
238traversal_output_file <<
" "<< (*func_iter)->GetUserFuncName() <<
"( arg0";
240 _ASSERT( (*extra_arg_iter)->GetDoStoreArg() );
241traversal_output_file <<
", *"<< (*extra_arg_iter)->GetStoredArgVariable();
243 ITERATE( vector<string>, constant_arg_iter, (*func_iter)->GetConstantArgs() ) {
244traversal_output_file <<
", "<< *constant_arg_iter;
246traversal_output_file <<
" );"<< endl;
259traversal_output_file <<
" switch( arg0.Which() ) {"<< endl;
261 stringcase_name = (*child_iter)->GetVarName();
262case_name[0] = (char)
toupper(case_name[0]);
264traversal_output_file <<
" case "<<
m_InputClassName<<
"::e_"<< case_name <<
":"<< endl;;
265 stringargString =
string(
"arg0.Set") + case_name +
"()";
267traversal_output_file <<
" break;"<< endl;
269traversal_output_file <<
" default:"<< endl;
270traversal_output_file <<
" break;"<< endl;
271traversal_output_file <<
" }"<< endl;
277 stringcase_name = (*child_iter)->GetVarName();
278case_name[0] = (char)
toupper(case_name[0]);
280traversal_output_file <<
" if( arg0.IsSet"<< case_name <<
"() ) {"<< endl;;
281 stringargString =
string(
"arg0.Set") + case_name +
"()";
283traversal_output_file <<
" }"<< endl;
291 stringcase_name = child_call->GetVarName();
293case_name[0] = (char)
toupper(case_name[0]);
300 const boolneeds_isset = ( needs_set &&
304traversal_output_file <<
" if( arg0.IsSet() ) {"<< endl;
307 stringargString = ( needs_set ?
"arg0.Set()":
"arg0");
311traversal_output_file <<
" }"<< endl;
319 stringcase_name = child_call->GetVarName();
321case_name[0] = (char)
toupper(case_name[0]);
324traversal_output_file <<
" NON_CONST_ITERATE( "<< input_class_prefix <<
m_InputClassName<<
", iter, arg0 ) { "<< endl;
326 intlevelsOfDereference = 1;
328++levelsOfDereference;
331++levelsOfDereference;
333 stringargString =
string(levelsOfDereference,
'*') +
"iter";
335traversal_output_file <<
" }"<< endl;
339 throwruntime_error(
"Unknown node type. Probably bug in code generator.");
345traversal_output_file <<
" "<< (*a_func_iter)->GetUserFuncName() <<
"( arg0";
347 _ASSERT( (*extra_arg_iter)->GetDoStoreArg() );
348traversal_output_file <<
", *"<< (*extra_arg_iter)->GetStoredArgVariable();
350 ITERATE( vector<string>, constant_arg_iter, (*a_func_iter)->GetConstantArgs() ) {
351traversal_output_file <<
", "<< *constant_arg_iter;
353traversal_output_file <<
" );"<< endl;
358traversal_output_file << endl;
364traversal_output_file << endl;
365traversal_output_file <<
" if( efh ) {"<< endl;
366traversal_output_file <<
" efh.Replace(arg0);"<< endl;
367traversal_output_file <<
" arg0_raw.Assign( arg0 );"<< endl;
368traversal_output_file <<
" }"<< endl;
369traversal_output_file << endl;
373traversal_output_file <<
"} // end of "<<
m_FuncName<< endl;
374traversal_output_file << endl;
382TVarNameToCallersMap var_name_to_callers_map;
384var_name_to_callers_map[(*caller_iter)->GetVarName()].push_back( (*caller_iter)->GetNode() );
390 if( var_name_to_callers_map.size() < 2 ) {
394 ITERATE( TVarNameToCallersMap, mapping_iter, var_name_to_callers_map ) {
395 const string&var_name = mapping_iter->first;
396 const TNodeVec&callers_for_this_var_name = mapping_iter->second;
401new_node->
AddCaller( var_name, *caller_to_add_iter );
411 constvector<string> &constant_args )
412: m_UserFuncName( user_func_name ), m_ExtraArgNodes(extra_arg_nodes),
413m_ConstantArgs(constant_args)
416(*extra_arg_iter)->m_ReferencingUserCalls.push_back(
CRef<CUserCall>(
this) );
424 x_DepthFirst( callback, node_path, nodesSeen, traversal_opts );
429 static const stringkSequence =
"Sequence";
430 static const stringkChoice =
"Choice";
431 static const stringkPrimitive =
"Primitive";
432 static const stringkNull =
"Null";
433 static const stringkEnum =
"Enum";
434 static const stringkReference =
"Reference";
435 static const stringkUniSequence =
"UniSequence";
437 static const string kUnknown=
"???";
494 if( *node_iter == node_to_merge_into_this->
Ref() ) {
502 AddCaller( (*their_caller)->GetVarName(), (*their_caller)->GetNode() );
513node_to_merge_into_this->
Clear();
524(*caller_iter)->GetNode()->m_Callees.erase( node_ref );
531(*callee_iter)->GetNode()->m_Callers.erase( node_ref );
546node_path.push_back(
Ref() );
548 const boolpost_traversal =
550 const boolallow_cycles =
553 const boolseen_before = ( nodesSeen.find(
Ref()) != nodesSeen.end() );
556 if( seen_before && (post_traversal || ! allow_cycles) ) {
557node_path.pop_back();
565 if( ! post_traversal ) {
566 if( ! callback.
Call( *
this, node_path, is_cyclic ) ) {
567node_path.pop_back();
572 const boolup_callers =
577nodesSeen.insert(
Ref() );
579(*child_iter)->GetNode()->x_DepthFirst( callback, node_path, nodesSeen, traversal_opts );
581nodesSeen.erase(
Ref() );
584 if( post_traversal ) {
586callback.
Call( *
this, node_path, is_cyclic );
589node_path.pop_back();
596traversal_output_file <<
" "<< child->
m_FuncName<<
"();"<< endl;
599traversal_output_file <<
" _ASSERT( sizeof(int) == sizeof("<< arg <<
") );"<< endl;
600traversal_output_file <<
" // the casting, etc. is a hack to get around the fact that we sometimes use TSeqPos "<< endl;
601traversal_output_file <<
" // instead of int, but we can't tell where by looking at the .asn file."<< endl;
602traversal_output_file <<
" "<< child->
m_FuncName<<
"( *(int*)&"<< arg <<
" );"<< endl;
604traversal_output_file <<
" "<< child->
m_FuncName<<
"( "<< arg <<
" );"<< endl;
622string::iterator pos =
type_name.begin();
627 if( next_bad_char !=
type_name.end() ) {
673string::size_type last_underscore =
result->m_FuncName.find_last_of(
"_");
674 if( string::npos == last_underscore ) {
675last_underscore =
result->m_FuncName.length();
678 result->m_FuncName.resize( last_underscore );
682(*callee_iter)->GetNode()->AddCaller( (*callee_iter)->GetVarName(),
result);
690 static const stringkObjectsStr =
"objects";
692string::size_type objects_pos = asn_file_name.find( kObjectsStr );
693string::size_type slash_after_objects = objects_pos + kObjectsStr.length();
694string::size_type last_backslash_pos = asn_file_name.find_last_of(
"\\/");
695 if( (objects_pos == string::npos) ||
696(slash_after_objects >= asn_file_name.length() ) ||
697( asn_file_name[slash_after_objects] !=
'\\'&& asn_file_name[slash_after_objects] !=
'/') ||
698( last_backslash_pos == string::npos ) ||
699( last_backslash_pos <= slash_after_objects ) )
702 msg+=
"All ASN file names must contain 'objects' in their path so ";
703 msg+=
"we can extract the location of .hpp files in the ";
704 msg+=
"include/objects directory. Example: C:/foo/bar/objects/seqloc/seqloc.asn. ";
705 msg+=
"You gave this file name: '"+ asn_file_name +
"'";
706 throwruntime_error(
msg);
712asn_file_name.begin() + slash_after_objects + 1,
713asn_file_name.begin() + last_backslash_pos );
723 constncbi::CRef<CNodeCall> ref1,
constncbi::CRef<CNodeCall> ref2)
const 728 intvar_comp =
NStr::Compare( ref1->GetVarName(), ref2->GetVarName() );
729 if( var_comp != 0 ) {
730 return( var_comp < 0 );
733 return( ref1->GetNode() < ref2->GetNode() );
bool IsEnumType(void) const
virtual AutoPtr< CTypeStrings > GetFullCType(void) const
string GetFullName(void) const
const CDataType * GetParentType(void) const
bool IsReference(void) const
const string & GetSourceFileName(void) const
bool IsContainer(void) const
bool IsStdType(void) const
virtual const CDataType * Resolve(void) const override
virtual bool Call(CTraversalNode &node, const TNodeVec &node_path, ECallType is_cyclic)=0
CUserCall(const std::string &user_func_name, const TNodeVec &extra_arg_nodes, const vector< string > &constant_args)
string x_ExtractIncludePathFromFileName(const string &asn_file_name)
void x_GenerateChildCall(CNcbiOstream &traversal_output_file, CRef< CTraversalNode > child, const string &arg)
std::string m_IncludePath
const string GetStoredArgVariable(void) const
@ fTraversalOpts_UpCallers
@ fTraversalOpts_AllowCycles
void x_LoadDataFromASNNode(CDataType *asn_node)
static int ms_FuncUniquerInt
TUserCallVec m_PostCalleesUserCalls
CRef< CTraversalNode > x_CloneWithoutCallers(const string &var_name) const
const string & GetTypeAsString(void) const
void x_DepthFirst(CDepthFirstCallback &callback, TNodeVec &node_path, TNodeSet &nodesSeen, TTraversalOpts traversal_opts)
void SplitByVarName(void)
static void x_MergeNames(string &result, const string &name1, const string &name2)
TUserCallVec m_PreCalleesUserCalls
@ eGenerateMode_Prototypes
@ eGenerateMode_Definitions
std::vector< CRef< CUserCall > > TUserCallVec
static CRef< CTraversalNode > Create(CRef< CTraversalNode > caller, const string &var_name, CDataType *asn_node)
const std::string & GetInputClassName(void) const
TUserCallVec m_ReferencingUserCalls
@ eMergeNameAllowed_AllowNameChange
std::vector< CRef< CTraversalNode > > TNodeVec
std::string m_InputClassName
void RemoveXFromFuncName(void)
void GenerateCode(const string &func_class_name, CNcbiOstream &traversal_output_file, EGenerateMode generate_mode)
std::set< CRef< CNodeCall >, SRefNodeCallLessthan > TNodeCallSet
void x_TemplatizeType(std::string &type_name)
unsigned int TTraversalOpts
void AddPostCalleesUserCall(CRef< CUserCall > user_call)
void DepthFirst(CDepthFirstCallback &callback, TTraversalOpts traversal_opts=0)
CRef< CTraversalNode > Ref()
std::map< CDataType *, CRef< CTraversalNode > > TASNNodeToNodeMap
static TASNNodeToNodeMap m_ASNNodeToNodeMap
void AddPreCalleesUserCall(CRef< CUserCall > user_call)
static set< CTraversalNode * > * ms_EveryNode
std::set< CRef< CTraversalNode > > TNodeSet
void AddCaller(const std::string &var_name, CRef< CTraversalNode > caller)
bool Merge(CRef< CTraversalNode > node_to_merge_into_this, EMergeNameAllowed merge_name_allowed=eMergeNameAllowed_AllowNameChange)
virtual string GetCType(const CNamespace &ns) const =0
virtual const CNamespace & GetNamespace(void) const
iterator_bool insert(const value_type &val)
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
#define NON_CONST_ITERATE(Type, Var, Cont)
Non constant version of ITERATE macro.
TObjectType * GetPointerOrNull(void) THROWS_NONE
Get pointer value.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
static SIZE_TYPE FindNoCase(const CTempString str, const CTempString pattern, SIZE_TYPE start, SIZE_TYPE end, EOccurrence which=eFirst)
Find the pattern in the specified range of a string using a case insensitive search.
static bool EndsWith(const CTempString str, const CTempString end, ECase use_case=eCase)
Check if a string ends with a specified suffix value.
static string IntToString(int value, TNumToStringFlags flags=0, int base=10)
Convert int to string.
static SIZE_TYPE Find(const CTempString str, const CTempString pattern, ECase use_case=eCase, EDirection direction=eForwardSearch, SIZE_TYPE occurrence=0)
Find the pattern in the string.
static string & Replace(const string &src, const string &search, const string &replace, string &dst, SIZE_TYPE start_pos=0, SIZE_TYPE max_replace=0, SIZE_TYPE *num_replace=0)
Replace occurrences of a substring within a string.
static int Compare(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2, ECase use_case=eCase)
Compare of a substring with another string.
static bool StartsWith(const CTempString str, const CTempString start, ECase use_case=eCase)
Check if a string starts with a specified prefix value.
static string & ReplaceInPlace(string &src, const string &search, const string &replace, SIZE_TYPE start_pos=0, SIZE_TYPE max_replace=0, SIZE_TYPE *num_replace=0)
Replace occurrences of a substring within a string.
const char *const kEmptyCStr
Empty "C" string (points to a '\0').
static string & ToLower(string &str)
Convert string to lower case â string& version.
double value_type
The numeric datatype used by the parser.
static SLJIT_INLINE sljit_ins msg(sljit_gpr r, sljit_s32 d, sljit_gpr x, sljit_gpr b)
bool operator()(const char &ch)
bool operator()(const char &ch)
bool operator()(const CRef< CNodeCall > ref1, const CRef< CNodeCall > ref2) const
static const char * kUnknown
static const char * type_name(CS_INT value)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4