From 314e962edf0fce8552f3699b0adc18a974ba6565 Mon Sep 17 00:00:00 2001 From: Alex Lin Date: Mon, 11 Apr 2016 08:01:54 -0500 Subject: [PATCH] Ignore privacy Removed the requirement of passing flags throughout ICG indicating if we are in an inherited class or not. Removed the init_attr friends throughout Trick core headers. --- include/trick/ABM_Integrator.hh | 9 ---- include/trick/DRHDF5.hh | 6 +-- include/trick/DataRecordDispatcher.hh | 6 +-- include/trick/Euler_Cromer_Integrator.hh | 9 ---- include/trick/Euler_Integrator.hh | 9 ---- include/trick/Event.hh | 2 - include/trick/EventManager.hh | 2 - include/trick/EventProcessor.hh | 6 +-- include/trick/Executive.hh | 5 -- include/trick/GetTimeOfDayClock.hh | 2 +- include/trick/IPPython.hh | 3 +- include/trick/IPPythonEvent.hh | 2 - include/trick/JITEvent.hh | 2 - include/trick/JSONVariableServer.hh | 3 -- include/trick/MM4_Integrator.hh | 9 ---- include/trick/MemoryManager.hh | 4 +- include/trick/MonteCarlo.hh | 5 -- include/trick/NL2_Integrator.hh | 9 ---- include/trick/RK2_Integrator.hh | 9 ---- include/trick/RK4_Integrator.hh | 9 ---- include/trick/RKF45_Integrator.hh | 9 ---- include/trick/RKF78_Integrator.hh | 9 ---- include/trick/RKG4_Integrator.hh | 9 ---- include/trick/ThreadBase.hh | 10 ---- include/trick/VariableServer.hh | 3 -- include/trick/VariableServerListenThread.hh | 3 -- include/trick/VariableServerThread.hh | 3 -- .../Interface_Code_Gen/ClassValues.cpp | 54 +++++++------------ .../codegen/Interface_Code_Gen/ClassValues.hh | 19 ++----- .../Interface_Code_Gen/ClassVisitor.cpp | 34 ++++++------ .../Interface_Code_Gen/ClassVisitor.hh | 2 - .../Interface_Code_Gen/FieldDescription.cpp | 9 ++-- .../Interface_Code_Gen/FieldDescription.hh | 3 +- .../Interface_Code_Gen/FieldVisitor.cpp | 7 ++- .../Interface_Code_Gen/FieldVisitor.hh | 3 +- .../PrintFileContents10.cpp | 41 ++------------ .../TranslationUnitVisitor.cpp | 2 +- .../Interface_Code_Gen/TypedefVisitor.cpp | 4 +- .../Interface_Code_Gen/VariableVisitor.cpp | 2 +- 39 files changed, 75 insertions(+), 262 deletions(-) diff --git a/include/trick/ABM_Integrator.hh b/include/trick/ABM_Integrator.hh index bfd29ce5..8cc96b0b 100644 --- a/include/trick/ABM_Integrator.hh +++ b/include/trick/ABM_Integrator.hh @@ -23,11 +23,6 @@ namespace Trick { * Helper class for ABM_Integrator */ class ABM_IntegratorHelper { -#ifndef SWIG - friend class InputProcessor; - friend void init_attrTrick__ABM_IntegratorHelper(); -#endif - protected: er7_utils::ABM4IntegratorConstructor @@ -42,10 +37,6 @@ protected: class ABM_Integrator : protected ABM_IntegratorHelper, public er7_utils::TrickFirstOrderOdeIntegrator { -#ifndef SWIG - friend class InputProcessor; - friend void init_attrTrick__ABM_Integrator(); -#endif public: diff --git a/include/trick/DRHDF5.hh b/include/trick/DRHDF5.hh index c444329d..7fd94aac 100644 --- a/include/trick/DRHDF5.hh +++ b/include/trick/DRHDF5.hh @@ -126,10 +126,10 @@ GROUP "/" { protected: #ifdef HDF5 - std::vector parameters; + std::vector parameters; // trick_io(**) - hid_t file; - hid_t root_group, header_group; + hid_t file; // trick_io(**) + hid_t root_group, header_group; // trick_io(**) #endif } ; diff --git a/include/trick/DataRecordDispatcher.hh b/include/trick/DataRecordDispatcher.hh index 369403c4..c89eec87 100644 --- a/include/trick/DataRecordDispatcher.hh +++ b/include/trick/DataRecordDispatcher.hh @@ -37,8 +37,8 @@ namespace Trick { virtual void * thread_body() ; virtual void dump( std::ostream & oss = std::cout ) ; protected: - Trick::DRDMutexes & drd_mutexes ; - std::vector & groups ; + Trick::DRDMutexes & drd_mutexes ; // trick_io(**) + std::vector & groups ; // trick_io(**) private: void operator =(const Trick::DRDWriterThread &) ; @@ -115,7 +115,7 @@ namespace Trick { std::vector groups ; /* trick_io(**) trick_units(--) */ /** mutexes shared with writer thread */ - DRDMutexes drd_mutexes ; + DRDMutexes drd_mutexes ; // trick_io(**) private: diff --git a/include/trick/Euler_Cromer_Integrator.hh b/include/trick/Euler_Cromer_Integrator.hh index 558c3dd8..27b5ec7a 100644 --- a/include/trick/Euler_Cromer_Integrator.hh +++ b/include/trick/Euler_Cromer_Integrator.hh @@ -25,11 +25,6 @@ namespace Trick { * Helper class for Euler_Cromer_Integrator */ class Euler_Cromer_IntegratorHelper { -#ifndef SWIG - friend class InputProcessor; - friend void init_attrTrick__Euler_Cromer_IntegratorHelper(); -#endif - protected: er7_utils::SymplecticEulerIntegratorConstructor @@ -44,10 +39,6 @@ protected: class Euler_Cromer_Integrator : protected Euler_Cromer_IntegratorHelper, public er7_utils::TrickSecondOrderOdeIntegrator { -#ifndef SWIG - friend class InputProcessor; - friend void init_attrTrick__Euler_Cromer_Integrator(); -#endif public: diff --git a/include/trick/Euler_Integrator.hh b/include/trick/Euler_Integrator.hh index a772f84d..661e1c1f 100644 --- a/include/trick/Euler_Integrator.hh +++ b/include/trick/Euler_Integrator.hh @@ -23,11 +23,6 @@ namespace Trick { * Helper class for Euler_Integrator */ class Euler_IntegratorHelper { -#ifndef SWIG - friend class InputProcessor; - friend void init_attrTrick__Euler_IntegratorHelper(); -#endif - protected: er7_utils::EulerIntegratorConstructor @@ -42,10 +37,6 @@ protected: class Euler_Integrator : protected Euler_IntegratorHelper, public er7_utils::TrickFirstOrderOdeIntegrator { -#ifndef SWIG - friend class InputProcessor; - friend void init_attrTrick__Euler_Integrator(); -#endif public: diff --git a/include/trick/Event.hh b/include/trick/Event.hh index fc23b3cd..f07509e3 100644 --- a/include/trick/Event.hh +++ b/include/trick/Event.hh @@ -25,8 +25,6 @@ enum EventBeforeAfter { */ class Event { - TRICK_MM_FRIENDS(Trick__Event) - public: /** diff --git a/include/trick/EventManager.hh b/include/trick/EventManager.hh index ee0b3dec..4f8b80bb 100644 --- a/include/trick/EventManager.hh +++ b/include/trick/EventManager.hh @@ -34,8 +34,6 @@ namespace Trick { class EventManager { - TRICK_MM_FRIENDS(Trick__EventManager) - public: /** diff --git a/include/trick/EventProcessor.hh b/include/trick/EventProcessor.hh index b35f73f5..9d98107f 100644 --- a/include/trick/EventProcessor.hh +++ b/include/trick/EventProcessor.hh @@ -72,15 +72,15 @@ namespace Trick { private: - Trick::JobData * process_event_job ; + Trick::JobData * process_event_job ; // trick_io(**) /** Use an ordered set to store the events. The events are sorted by their next execution time. The set allows us to add/remove items at any time.\n */ - std::multiset< Trick::Event *, CompareEventPtrs > event_set ; + std::multiset< Trick::Event *, CompareEventPtrs > event_set ; // trick_io(**) /** Added events are put in the staging area called pending events. The add_pending_events job moves pending events to the event_set.\n */ - std::vector< Trick::Event * > pending_events ; + std::vector< Trick::Event * > pending_events ; // trick_io(**) } ; diff --git a/include/trick/Executive.hh b/include/trick/Executive.hh index 640e1036..4d370705 100644 --- a/include/trick/Executive.hh +++ b/include/trick/Executive.hh @@ -43,11 +43,6 @@ namespace Trick { class Executive : public Trick::Scheduler { - friend class InputProcessor ; -#ifndef SWIG - friend void init_attrTrick__Executive() ; -#endif - protected: /** Attempts to attach a debugger in the event a signal shuts down the simulation.\n */ bool attach_debugger; /**< trick_units(--) */ diff --git a/include/trick/GetTimeOfDayClock.hh b/include/trick/GetTimeOfDayClock.hh index 4712639a..ac01bff3 100644 --- a/include/trick/GetTimeOfDayClock.hh +++ b/include/trick/GetTimeOfDayClock.hh @@ -56,7 +56,7 @@ namespace Trick { protected: #ifdef __linux - clockid_t clk_id ; + clockid_t clk_id ; // trick_io(**) #endif } ; diff --git a/include/trick/IPPython.hh b/include/trick/IPPython.hh index 821d3c5b..57378123 100644 --- a/include/trick/IPPython.hh +++ b/include/trick/IPPython.hh @@ -36,8 +36,7 @@ namespace Trick { /** Returned value from event condition evaluation.\n */ int return_val ; /**< trick_io(**) trick_units(--) */ - /** Input processor mutex for protection for var server and event processing.\n */ - pthread_mutex_t ip_mutex; /**< trick_io(**) trick_units(--) */ + /** Input processor mutex for protection for var server and event processing.\n */ pthread_mutex_t ip_mutex; /**< trick_io(**) trick_units(--) */ /** @brief Constructor. diff --git a/include/trick/IPPythonEvent.hh b/include/trick/IPPythonEvent.hh index ed04d798..490f89b8 100644 --- a/include/trick/IPPythonEvent.hh +++ b/include/trick/IPPythonEvent.hh @@ -72,8 +72,6 @@ namespace Trick { class IPPythonEvent : public Trick::Event { - TRICK_MM_FRIENDS(Trick__IPPythonEvent) - public: /** True when event is in the event_list to be processed; false when it is to be removed from event_list.\n */ diff --git a/include/trick/JITEvent.hh b/include/trick/JITEvent.hh index adb59b36..56bb1867 100644 --- a/include/trick/JITEvent.hh +++ b/include/trick/JITEvent.hh @@ -27,8 +27,6 @@ namespace Trick { */ class JITEvent : public Trick::Event { - TRICK_MM_FRIENDS(Trick__JITEvent) - public: JITEvent() ; diff --git a/include/trick/JSONVariableServer.hh b/include/trick/JSONVariableServer.hh index 4db14096..17f71cb0 100644 --- a/include/trick/JSONVariableServer.hh +++ b/include/trick/JSONVariableServer.hh @@ -19,9 +19,6 @@ namespace Trick { */ class JSONVariableServer : public Trick::ThreadBase { - friend class InputProcessor ; - friend void init_attrTrick__JSONVariableServer() ; - public: JSONVariableServer() ; virtual ~JSONVariableServer() ; diff --git a/include/trick/MM4_Integrator.hh b/include/trick/MM4_Integrator.hh index 86891c07..1f1a4f38 100644 --- a/include/trick/MM4_Integrator.hh +++ b/include/trick/MM4_Integrator.hh @@ -23,11 +23,6 @@ namespace Trick { * Helper class for MM4_Integrator */ class MM4_IntegratorHelper { -#ifndef SWIG - friend class InputProcessor; - friend void init_attrTrick__MM4_IntegratorHelper(); -#endif - protected: er7_utils::MM4IntegratorConstructor @@ -42,10 +37,6 @@ protected: class MM4_Integrator : protected MM4_IntegratorHelper, public er7_utils::TrickSecondOrderOdeIntegrator { -#ifndef SWIG - friend class InputProcessor; - friend void init_attrTrick__MM4_Integrator(); -#endif public: diff --git a/include/trick/MemoryManager.hh b/include/trick/MemoryManager.hh index 221a3441..addb8201 100644 --- a/include/trick/MemoryManager.hh +++ b/include/trick/MemoryManager.hh @@ -660,8 +660,8 @@ namespace Trick { static int instance_count; /**< -- Number of instances of MemoryManager. Not allowed to exceed 1.*/ const char* local_anon_var_prefix; /**< -- Temporary-variable-name prefix. */ const char* extern_anon_var_prefix; /**< -- Temporary-variable-name prefix. */ - CheckPointAgent* currentCheckPointAgent; /**< -- currently active Check point agent. */ - CheckPointAgent* defaultCheckPointAgent; /**< -- the classic Check point agent. */ + CheckPointAgent* currentCheckPointAgent; /**< ** currently active Check point agent. */ + CheckPointAgent* defaultCheckPointAgent; /**< ** the classic Check point agent. */ bool reduced_checkpoint; /**< -- true = Don't write zero valued variables in the checkpoint. false= Write all values. */ bool hexfloat_checkpoint; /**< -- true = Represent floating point values as hexidecimal to preserve precision. false= Normal. */ diff --git a/include/trick/MonteCarlo.hh b/include/trick/MonteCarlo.hh index b8a47867..5c9d46bf 100644 --- a/include/trick/MonteCarlo.hh +++ b/include/trick/MonteCarlo.hh @@ -242,11 +242,6 @@ namespace Trick { */ class MonteCarlo : public Trick::Scheduler { - friend class InputProcessor; -#ifndef SWIG - friend void init_attrTrick__MonteCarlo(); -#endif - public: /** Verbosity of message reporting. */ enum Verbosity { diff --git a/include/trick/NL2_Integrator.hh b/include/trick/NL2_Integrator.hh index e52e05d9..8dac3513 100644 --- a/include/trick/NL2_Integrator.hh +++ b/include/trick/NL2_Integrator.hh @@ -23,11 +23,6 @@ namespace Trick { * Helper class for NL2_Integrator */ class NL2_IntegratorHelper { -#ifndef SWIG - friend class InputProcessor; - friend void init_attrTrick__NL2_IntegratorHelper(); -#endif - protected: er7_utils::NystromLear2IntegratorConstructor @@ -42,10 +37,6 @@ protected: class NL2_Integrator : protected NL2_IntegratorHelper, public er7_utils::TrickSecondOrderOdeIntegrator { -#ifndef SWIG - friend class InputProcessor; - friend void init_attrTrick__NL2_Integrator(); -#endif public: diff --git a/include/trick/RK2_Integrator.hh b/include/trick/RK2_Integrator.hh index ae3e2742..7ef0883a 100644 --- a/include/trick/RK2_Integrator.hh +++ b/include/trick/RK2_Integrator.hh @@ -23,11 +23,6 @@ namespace Trick { * Helper class for RK2_Integrator */ class RK2_IntegratorHelper { -#ifndef SWIG - friend class InputProcessor; - friend void init_attrTrick__RK2_IntegratorHelper(); -#endif - protected: er7_utils::RK2HeunIntegratorConstructor @@ -42,10 +37,6 @@ protected: class RK2_Integrator : protected RK2_IntegratorHelper, public er7_utils::TrickFirstOrderOdeIntegrator { -#ifndef SWIG - friend class InputProcessor; - friend void init_attrTrick__RK2_Integrator(); -#endif public: diff --git a/include/trick/RK4_Integrator.hh b/include/trick/RK4_Integrator.hh index 672a7023..108a5701 100644 --- a/include/trick/RK4_Integrator.hh +++ b/include/trick/RK4_Integrator.hh @@ -23,11 +23,6 @@ namespace Trick { * Helper class for RK4_Integrator */ class RK4_IntegratorHelper { -#ifndef SWIG - friend class InputProcessor; - friend void init_attrTrick__RK4_IntegratorHelper(); -#endif - protected: er7_utils::RK4IntegratorConstructor @@ -42,10 +37,6 @@ protected: class RK4_Integrator : protected RK4_IntegratorHelper, public er7_utils::TrickFirstOrderOdeIntegrator { -#ifndef SWIG - friend class InputProcessor; - friend void init_attrTrick__RK4_Integrator(); -#endif public: diff --git a/include/trick/RKF45_Integrator.hh b/include/trick/RKF45_Integrator.hh index 33d97a77..385d81d4 100644 --- a/include/trick/RKF45_Integrator.hh +++ b/include/trick/RKF45_Integrator.hh @@ -23,11 +23,6 @@ namespace Trick { * Helper class for RKF45_Integrator */ class RKF45_IntegratorHelper { -#ifndef SWIG - friend class InputProcessor; - friend void init_attrTrick__RKF45_IntegratorHelper(); -#endif - protected: er7_utils::RKFehlberg45IntegratorConstructor @@ -42,10 +37,6 @@ protected: class RKF45_Integrator : protected RKF45_IntegratorHelper, public er7_utils::TrickFirstOrderOdeIntegrator { -#ifndef SWIG - friend class InputProcessor; - friend void init_attrTrick__RKF45_Integrator(); -#endif public: diff --git a/include/trick/RKF78_Integrator.hh b/include/trick/RKF78_Integrator.hh index 8abfce77..4806d7b9 100644 --- a/include/trick/RKF78_Integrator.hh +++ b/include/trick/RKF78_Integrator.hh @@ -23,11 +23,6 @@ namespace Trick { * Helper class for RKF78_Integrator */ class RKF78_IntegratorHelper { -#ifndef SWIG - friend class InputProcessor; - friend void init_attrTrick__RKF78_IntegratorHelper(); -#endif - protected: er7_utils::RKFehlberg78IntegratorConstructor @@ -42,10 +37,6 @@ protected: class RKF78_Integrator : protected RKF78_IntegratorHelper, public er7_utils::TrickFirstOrderOdeIntegrator { -#ifndef SWIG - friend class InputProcessor; - friend void init_attrTrick__RKF78_Integrator(); -#endif public: diff --git a/include/trick/RKG4_Integrator.hh b/include/trick/RKG4_Integrator.hh index 3d14abb3..d19c877a 100644 --- a/include/trick/RKG4_Integrator.hh +++ b/include/trick/RKG4_Integrator.hh @@ -23,11 +23,6 @@ namespace Trick { * Helper class for RKG4_Integrator */ class RKG4_IntegratorHelper { -#ifndef SWIG - friend class InputProcessor; - friend void init_attrTrick__RKG4_IntegratorHelper(); -#endif - protected: er7_utils::RKGill4IntegratorConstructor @@ -42,10 +37,6 @@ protected: class RKG4_Integrator : protected RKG4_IntegratorHelper, public er7_utils::TrickFirstOrderOdeIntegrator { -#ifndef SWIG - friend class InputProcessor; - friend void init_attrTrick__RKG4_Integrator(); -#endif public: diff --git a/include/trick/ThreadBase.hh b/include/trick/ThreadBase.hh index 85fc0220..8e51990b 100644 --- a/include/trick/ThreadBase.hh +++ b/include/trick/ThreadBase.hh @@ -31,9 +31,6 @@ namespace Trick { */ class ThreadBase { - friend class InputProcessor ; - friend void init_attrTrick__ThreadBase() ; - public: /** @@ -51,13 +48,6 @@ namespace Trick { */ pthread_t get_pthread_id() ; -#if 0 - /** - * Sets the thread pthread ID. - */ - void set_pthread_id( pthread_t in_pthread_id ) ; -#endif - /** * Gets the thread process ID. */ diff --git a/include/trick/VariableServer.hh b/include/trick/VariableServer.hh index 309ba6c3..bbb7b0a1 100644 --- a/include/trick/VariableServer.hh +++ b/include/trick/VariableServer.hh @@ -28,9 +28,6 @@ namespace Trick { class VariableServer { - friend class InputProcessor ; - friend void init_attrTrick__VariableServer() ; - public: /** @brief Constructor. diff --git a/include/trick/VariableServerListenThread.hh b/include/trick/VariableServerListenThread.hh index 0023bdd0..a79dcd56 100644 --- a/include/trick/VariableServerListenThread.hh +++ b/include/trick/VariableServerListenThread.hh @@ -19,9 +19,6 @@ namespace Trick { */ class VariableServerListenThread : public Trick::ThreadBase { - friend class InputProcessor ; - friend void init_attrTrick__VariableServerListenThread() ; - public: VariableServerListenThread() ; virtual ~VariableServerListenThread() ; diff --git a/include/trick/VariableServerThread.hh b/include/trick/VariableServerThread.hh index ab8579a5..860e5b1c 100644 --- a/include/trick/VariableServerThread.hh +++ b/include/trick/VariableServerThread.hh @@ -24,9 +24,6 @@ namespace Trick { */ class VariableServerThread : public Trick::ThreadBase { - friend class InputProcessor ; - friend void init_attrTrick__VariableServerThread() ; - public: enum ConnectionType { TCP, UDP, MCAST } ; diff --git a/trick_source/codegen/Interface_Code_Gen/ClassValues.cpp b/trick_source/codegen/Interface_Code_Gen/ClassValues.cpp index f1c5bad6..19ee3e09 100644 --- a/trick_source/codegen/Interface_Code_Gen/ClassValues.cpp +++ b/trick_source/codegen/Interface_Code_Gen/ClassValues.cpp @@ -5,9 +5,7 @@ #include "ClassValues.hh" #include "FieldDescription.hh" -ClassValues::ClassValues(bool in_inherit, bool in_virtual_inherit) : - inherited(in_inherit) , - virtual_inherited(in_virtual_inherit) , +ClassValues::ClassValues() : has_init_attr_friend(false) , is_pod(false) , is_abstract(false) , @@ -20,19 +18,11 @@ ClassValues::~ClassValues() { for ( fdit = field_descripts.begin() ; fdit != field_descripts.end() ; fdit++ ) { delete (*fdit) ; } - - std::vector::iterator cvit ; - for ( cvit = inherited_classes.begin() ; cvit != inherited_classes.end() ; cvit++ ) { - delete (*cvit) ; - } } void ClassValues::addFieldDescription(FieldDescription * in_fdes) { field_descripts.push_back(in_fdes) ; -// This section creates code that clang on the Mac cannot compile. -// So, we cannot handle overloaded names on the Mac. -#ifndef __APPLE__ // Test to see if the new field overloads a field of the same name. If it does // then fully qualify the name of the inherited field (the one already in field_name_to_info). std::map< std::string , FieldDescription * >::iterator mit = field_name_to_info_map.find(in_fdes->getName()) ; @@ -44,7 +34,6 @@ void ClassValues::addFieldDescription(FieldDescription * in_fdes) { field_name_to_info_map.erase(mit) ; } } -#endif field_name_to_info_map[in_fdes->getName()] = in_fdes ; } @@ -53,14 +42,14 @@ void ClassValues::addInheritedFieldDescriptions(std::vector // Make a copy of all of the FieldDescription variables. field_descripts.insert(field_descripts.end(), in_fdes.begin() , in_fdes.end()) ; -// This section creates code that clang on the Mac cannot compile. -// So, we cannot handle overloaded names on the Mac. std::vector::iterator fdit ; // Loop through the incoming inherited variable names for ( fdit = in_fdes.begin() ; fdit != in_fdes.end() ; fdit++ ) { + (*fdit)->setInherited( true ) ; + // Adds the class offset to the field offset giving the total offset to the inherited variable (*fdit)->addOffset( class_offset ) ; -#ifndef __APPLE__ + std::string in_name = (*fdit)->getName() ; // search existing names for incoming inherited variable name. std::map< std::string , FieldDescription * >::iterator mit = field_name_to_info_map.find(in_name) ; @@ -92,7 +81,6 @@ void ClassValues::addInheritedFieldDescriptions(std::vector field_name_to_info_map[(*fdit)->getName()] = *fdit ; } } -#endif } } @@ -170,30 +158,14 @@ void ClassValues::clearFieldDescription() { field_descripts.clear() ; } -void ClassValues::addInheritedClass(ClassValues * in_cv) { - inherited_classes.push_back(in_cv) ; +void ClassValues::addInheritedClass(std::string class_name) { + inherited_classes.push_back(class_name) ; } void ClassValues::clearInheritedClass() { inherited_classes.clear() ; } -void ClassValues::setInherited(bool in_inh) { - inherited = in_inh ; -} - -bool ClassValues::isInherited() { - return inherited ; -} - -void ClassValues::setVirtualInherited(bool in_inh) { - virtual_inherited = in_inh ; -} - -bool ClassValues::isVirtualInherited() { - return virtual_inherited ; -} - void ClassValues::setHasInitAttrFriend(bool in_val) { has_init_attr_friend = in_val ; } @@ -234,6 +206,20 @@ bool ClassValues::getHasPublicDestructor() { return has_public_destructor ; } +std::string ClassValues::getFullyQualifiedTypeName() { + std::ostringstream oss ; + NamespaceIterator ni ; + + for ( ni = namespace_begin() ; ni != namespace_end() ; ni++ ) { + oss << (*ni) << "::" ; + } + for ( ni = container_class_begin() ; ni != container_class_end() ; ni++ ) { + oss << (*ni) << "::" ; + } + oss << name ; + return oss.str() ; +} + void ClassValues::setMangledTypeName( std::string in_val ) { mangled_type_name = in_val ; } diff --git a/trick_source/codegen/Interface_Code_Gen/ClassValues.hh b/trick_source/codegen/Interface_Code_Gen/ClassValues.hh index d1f6edd0..4fbf8d57 100644 --- a/trick_source/codegen/Interface_Code_Gen/ClassValues.hh +++ b/trick_source/codegen/Interface_Code_Gen/ClassValues.hh @@ -27,7 +27,7 @@ class FieldDescription ; class ClassValues : public ConstructValues { public: - ClassValues(bool inherit , bool virtual_inherit) ; + ClassValues() ; ~ClassValues() ; @@ -48,7 +48,7 @@ class ClassValues : public ConstructValues { FieldIterator field_end() { return field_descripts.end() ; } ; /** Appends an inherited class name to the list this class inherits from */ - void addInheritedClass( ClassValues * in_cv ) ; + void addInheritedClass( std::string class_name ) ; void saveInheritAncestry( ClassValues * in_cv ) ; void setContainerClassForFields() ; @@ -56,13 +56,11 @@ class ClassValues : public ConstructValues { void clearInheritedClass() ; - typedef std::vector< ClassValues * >::iterator InheritedClassesIterator ; + typedef std::vector< std::string >::iterator InheritedClassesIterator ; InheritedClassesIterator inherit_classes_begin() { return inherited_classes.begin() ; } ; InheritedClassesIterator inherit_classes_end() { return inherited_classes.end() ; } ; unsigned int getNumInheritedClasses() { return inherited_classes.size() ; } ; - void setInherited(bool in_inh) ; - bool isInherited() ; void setVirtualInherited(bool in_inh) ; bool isVirtualInherited() ; void setHasInitAttrFriend(bool in_val) ; @@ -75,9 +73,8 @@ class ClassValues : public ConstructValues { bool getHasDefaultConstructor() ; void setHasPublicDestructor(bool in_val) ; bool getHasPublicDestructor() ; + std::string getFullyQualifiedTypeName() ; void setMangledTypeName( std::string in_val ) ; - bool getInvadePrivacy() ; - void setInvadePrivacy( bool in_val ) ; std::string getMangledTypeName() ; std::string getFullyQualifiedMangledTypeName() ; @@ -93,17 +90,11 @@ class ClassValues : public ConstructValues { std::set< std::string > field_names_to_qualify ; /** List of classes we inherit from */ - std::vector< ClassValues * > inherited_classes ; + std::vector< std::string > inherited_classes ; /** Map of all inherited classes. Counts how many times a class is inherited. */ std::map< std::string , unsigned int > all_inherited_class_names_map ; - /** Is this class being processed as an inherited class */ - bool inherited ; - - /** Is this class being processed as an virtual inherited class */ - bool virtual_inherited ; - /** Does this class a "friend class init_attr" statement */ bool has_init_attr_friend ; diff --git a/trick_source/codegen/Interface_Code_Gen/ClassVisitor.cpp b/trick_source/codegen/Interface_Code_Gen/ClassVisitor.cpp index 833bbcd8..321f32e4 100644 --- a/trick_source/codegen/Interface_Code_Gen/ClassVisitor.cpp +++ b/trick_source/codegen/Interface_Code_Gen/ClassVisitor.cpp @@ -23,14 +23,12 @@ CXXRecordVisitor::CXXRecordVisitor( CommentSaver & in_cs , HeaderSearchDirs & in_hsd , PrintAttributes & in_pa , - bool in_inherited , - bool in_virtual_inherited , bool in_include_virtual_base ) : ci(in_ci) , cs(in_cs) , hsd(in_hsd) , pa(in_pa) , - cval(in_inherited , in_virtual_inherited) , + cval() , include_virtual_base(in_include_virtual_base) {} CXXRecordVisitor::~CXXRecordVisitor() { @@ -57,7 +55,7 @@ bool CXXRecordVisitor::TraverseDecl(clang::Decl *d) { clang::RecordDecl * rd = crd->getDefinition() ; if ( rd != NULL and rd->getAccess() == clang::AS_public ) { if ( isInUserCode(ci , crd->getRBraceLoc(), hsd) ) { - CXXRecordVisitor embedded_cvis(ci , cs, hsd , pa, false, false, true) ; + CXXRecordVisitor embedded_cvis(ci , cs, hsd , pa, true) ; embedded_cvis.TraverseCXXRecordDecl(static_cast(d)) ; pa.printClass(embedded_cvis.get_class_data()) ; } @@ -70,14 +68,12 @@ bool CXXRecordVisitor::TraverseDecl(clang::Decl *d) { if ( ed->getAccess() == clang::AS_public ) { EnumVisitor evis(ci, hsd) ; evis.TraverseDecl(ed) ; - //if ( evis.get_enum_data() != NULL ) { - pa.printEnum(evis.get_enum_data()) ; - //} + pa.printEnum(evis.get_enum_data()) ; } } break ; case clang::Decl::Field : { - FieldVisitor fvis(ci , hsd , cs, pa, cval.getName() , cval.isInherited() ) ; + FieldVisitor fvis(ci , hsd , cs, pa, cval.getName()) ; fvis.TraverseFieldDecl(static_cast(d)) ; cval.addFieldDescription(fvis.get_field_data()) ; } @@ -88,13 +84,11 @@ bool CXXRecordVisitor::TraverseDecl(clang::Decl *d) { break ; case clang::Decl::Var : { /* Static fields appear as vars. Treat it as a field. */ - FieldVisitor fvis(ci , hsd , cs, pa, cval.getName() , cval.isInherited() ) ; + FieldVisitor fvis(ci , hsd , cs, pa, cval.getName()) ; fvis.TraverseVarDecl(static_cast(d)) ; cval.addFieldDescription(fvis.get_field_data()) ; } break ; - case clang::Decl::AccessSpec : - break ; default : break ; } @@ -192,7 +186,7 @@ bool CXXRecordVisitor::VisitCXXRecordDecl( clang::CXXRecordDecl *rec ) { inherit_class_offset = record_layout.getBaseClassOffset(llvm::cast(rd)).getQuantity() ; //std::cout << " inherit_class_offset = " << inherit_class_offset << "" << std::endl ; //std::cout << " " << getFileName(ci , rd->getRBraceLoc(), hsd) << "" << std::endl ; - CXXRecordVisitor inherit_cvis(ci , cs, hsd , pa, true, bcii->isVirtual(), false) ; + CXXRecordVisitor inherit_cvis(ci , cs, hsd , pa, false) ; inherit_cvis.TraverseCXXRecordDecl(static_cast(rd)) ; cval.addInheritedFieldDescriptions(inherit_cvis.get_class_data()->getFieldDescription(), inherit_class_offset) ; // clear the field list in the inherited class so they are not freed when inherit_cvis goes out of scope. @@ -209,7 +203,7 @@ bool CXXRecordVisitor::VisitCXXRecordDecl( clang::CXXRecordDecl *rec ) { icv->clearInheritedClass() ; // Save the copy of the inherited class to the current class - cval.addInheritedClass(icv) ; + cval.addInheritedClass(inherit_cvis.get_class_data()->getFullyQualifiedTypeName()) ; } } } @@ -217,7 +211,9 @@ bool CXXRecordVisitor::VisitCXXRecordDecl( clang::CXXRecordDecl *rec ) { } //std::cout << " end inheritance" << std::endl ; - /* Virtual base classes are parsed once at the top. Each inherited class call to CXXRecordVisitor sets this flag to false. */ + // Virtual base classes are parsed once + // When processing inherited classes include_virtual_base will be set to true + // so we don't process virtual inherited classes multiple times. if ( include_virtual_base ) { for ( bcii = rec->vbases_begin() ; bcii != rec->vbases_end() ; bcii++ ) { const clang::Type * temp = bcii->getType().getTypePtr() ; @@ -225,19 +221,20 @@ bool CXXRecordVisitor::VisitCXXRecordDecl( clang::CXXRecordDecl *rec ) { const clang::RecordType * rt = temp->getAs() ; if ( rt != NULL ) { clang::RecordDecl * rd = rt->getDecl() ; - //std::cout << " " << cval.getName() << " virtually inherits from " << rd->getNameAsString() << "" << std::endl ; + //std::cout << " " << cval.getName() << " virtually inherits from " + // << rd->getNameAsString() << "" << std::endl ; //rd->dump() ; std::cout << std::endl ; if ( isInUserOrTrickCode(ci , rd->getRBraceLoc(), hsd) ) { const clang::ASTRecordLayout &record_layout = rec->getASTContext().getASTRecordLayout(rec); unsigned int inherit_class_offset ; // Virtual base classes have a fixed offset that cannot be accessed at runtime. We have clang's calculation - // to where the base class will be here. Hopefully it matches what other compilers calculate. :( + // to where the base class will be. inherit_class_offset = record_layout.getVBaseClassOffset(llvm::cast(rd)).getQuantity() ; //std::cout << " inherit_class_offset = " << inherit_class_offset << "" << std::endl ; //std::cout << " " << getFileName(ci , rd->getRBraceLoc(), hsd) << "" << std::endl ; - CXXRecordVisitor inherit_cvis(ci , cs, hsd , pa, true, bcii->isVirtual(), false) ; + CXXRecordVisitor inherit_cvis(ci , cs, hsd , pa, false) ; inherit_cvis.TraverseCXXRecordDecl(static_cast(rd)) ; cval.addInheritedFieldDescriptions(inherit_cvis.get_class_data()->getFieldDescription(), inherit_class_offset) ; // clear the field list in the inherited class so they are not freed when inherit_cvis goes out of scope. @@ -251,7 +248,7 @@ bool CXXRecordVisitor::VisitCXXRecordDecl( clang::CXXRecordDecl *rec ) { icv->clearInheritedClass() ; // Save the copy of the inherited class to the current class - cval.addInheritedClass(icv) ; + cval.addInheritedClass(inherit_cvis.get_class_data()->getFullyQualifiedTypeName()) ; } } } @@ -269,6 +266,7 @@ bool CXXRecordVisitor::VisitCXXRecordDecl( clang::CXXRecordDecl *rec ) { return true; } +// Test if we have a friend with the name "init_attr" bool CXXRecordVisitor::VisitFriendDecl( clang::FriendDecl *fd ) { //std::cout << " ClassVisitor::VisitFriendDecl" << std::endl ; clang::TypeSourceInfo * tsi = fd->getFriendType() ; diff --git a/trick_source/codegen/Interface_Code_Gen/ClassVisitor.hh b/trick_source/codegen/Interface_Code_Gen/ClassVisitor.hh index d12c94c6..61f05120 100644 --- a/trick_source/codegen/Interface_Code_Gen/ClassVisitor.hh +++ b/trick_source/codegen/Interface_Code_Gen/ClassVisitor.hh @@ -38,8 +38,6 @@ class CXXRecordVisitor : public clang::RecursiveASTVisitor { CommentSaver & in_cs , HeaderSearchDirs & in_hsd , PrintAttributes & in_pa , - bool in_inherited , - bool in_virtual_inherited , bool in_include_virtual_base ) ; ~CXXRecordVisitor() ; diff --git a/trick_source/codegen/Interface_Code_Gen/FieldDescription.cpp b/trick_source/codegen/Interface_Code_Gen/FieldDescription.cpp index 6d370e2f..a9d03845 100644 --- a/trick_source/codegen/Interface_Code_Gen/FieldDescription.cpp +++ b/trick_source/codegen/Interface_Code_Gen/FieldDescription.cpp @@ -15,12 +15,11 @@ #include "trick/units_conv.h" FieldDescription::FieldDescription( - std::string in_container_class , - bool in_inherited ) : + std::string in_container_class ) : container_class(in_container_class) , field_offset(0) , field_width(0) , - inherited(in_inherited) , + inherited(false) , units("--") , line_no(0) , io(3) , @@ -316,6 +315,10 @@ std::string FieldDescription::getDescription() { return description ; } +void FieldDescription::setInherited(bool in_inherited) { + inherited = in_inherited ; +} + bool FieldDescription::isInherited() { return inherited ; } diff --git a/trick_source/codegen/Interface_Code_Gen/FieldDescription.hh b/trick_source/codegen/Interface_Code_Gen/FieldDescription.hh index 3669de42..e5d12ca8 100644 --- a/trick_source/codegen/Interface_Code_Gen/FieldDescription.hh +++ b/trick_source/codegen/Interface_Code_Gen/FieldDescription.hh @@ -29,7 +29,7 @@ class FieldDescription : public ConstructValues { public: /* Default the inheritance to false */ - FieldDescription( std::string in_container_class , bool inherited ) ; + FieldDescription( std::string in_container_class ) ; /* Extracts units and io code from a comment */ void parseComment(std::string) ; @@ -75,6 +75,7 @@ class FieldDescription : public ConstructValues { bool hasSTLClear() ; void setStatic( bool yes_no ) ; bool isStatic() ; + void setInherited( bool yes_no ) ; bool isInherited() ; void setAccess( clang::AccessSpecifier in_val ) ; clang::AccessSpecifier getAccess() ; diff --git a/trick_source/codegen/Interface_Code_Gen/FieldVisitor.cpp b/trick_source/codegen/Interface_Code_Gen/FieldVisitor.cpp index ed40ac6c..223cf970 100644 --- a/trick_source/codegen/Interface_Code_Gen/FieldVisitor.cpp +++ b/trick_source/codegen/Interface_Code_Gen/FieldVisitor.cpp @@ -21,13 +21,12 @@ FieldVisitor::FieldVisitor(clang::CompilerInstance & in_ci , HeaderSearchDirs & in_hsd , CommentSaver & in_cs , PrintAttributes & in_pa , - std::string container_class , - bool in_inherited ) : + std::string container_class ) : ci(in_ci) , hsd(in_hsd) , cs(in_cs) , pa(in_pa) { - fdes = new FieldDescription(container_class, in_inherited ) ; + fdes = new FieldDescription(container_class) ; } bool FieldVisitor::VisitDecl(clang::Decl *d) { @@ -273,7 +272,7 @@ bool FieldVisitor::ProcessTemplate(std::string in_name , clang::CXXRecordDecl * fdes->getName() + "_" + mangled_name ; // Traverse the template declaration - CXXRecordVisitor template_spec_cvis(ci , cs, hsd , pa, false, false, true) ; + CXXRecordVisitor template_spec_cvis(ci , cs, hsd , pa, true) ; template_spec_cvis.get_class_data()->setMangledTypeName(processed_templates[in_name]) ; template_spec_cvis.TraverseCXXRecordDecl(crd) ; diff --git a/trick_source/codegen/Interface_Code_Gen/FieldVisitor.hh b/trick_source/codegen/Interface_Code_Gen/FieldVisitor.hh index f8951e74..b61582cc 100644 --- a/trick_source/codegen/Interface_Code_Gen/FieldVisitor.hh +++ b/trick_source/codegen/Interface_Code_Gen/FieldVisitor.hh @@ -31,8 +31,7 @@ class FieldVisitor : public clang::RecursiveASTVisitor { HeaderSearchDirs & in_hsd , CommentSaver & cs , PrintAttributes & in_pa , - std::string container_class , - bool inherited ) ; + std::string container_class ) ; /* VisitDecl and VisitType are here for debug printing. */ bool VisitDecl(clang::Decl *d) ; diff --git a/trick_source/codegen/Interface_Code_Gen/PrintFileContents10.cpp b/trick_source/codegen/Interface_Code_Gen/PrintFileContents10.cpp index 528441df..17e1dd87 100644 --- a/trick_source/codegen/Interface_Code_Gen/PrintFileContents10.cpp +++ b/trick_source/codegen/Interface_Code_Gen/PrintFileContents10.cpp @@ -124,7 +124,7 @@ void PrintFileContents10::print_class_attr(std::ofstream & outfile , ClassValues } } // Print an empty sentinel attribute at the end of the class. - FieldDescription * new_fdes = new FieldDescription(std::string(""), false) ; + FieldDescription * new_fdes = new FieldDescription(std::string("")) ; print_field_attr(outfile, new_fdes) ; outfile << " };" << std::endl ; delete new_fdes ; @@ -137,7 +137,7 @@ void PrintFileContents10::print_field_init_attr_stmts( std::ofstream & outfile , // Static bitfields do not get to this point, they are filtered out in determinePrintAttr - // Always print offset of a static variable + // Always print offset as address of the static variable if ( fdes->isStatic() ) { // print a special offsetof statement if this is a static outfile << " attr" ; @@ -149,8 +149,9 @@ void PrintFileContents10::print_field_init_attr_stmts( std::ofstream & outfile , outfile << cv->getName() << "::" << fdes->getName() << " ;\n" ; } + // if this is a bitfield... + // TODO: may not need to write out offset... if ( fdes->isBitField() ) { - // else if this is a bitfield outfile << " attr" ; printNamespaces( outfile, cv , "__" ) ; printContainerClasses( outfile, cv , "__" ) ; @@ -163,35 +164,6 @@ void PrintFileContents10::print_field_init_attr_stmts( std::ofstream & outfile , printContainerClasses( outfile, cv , "__" ) ; outfile << cv->getMangledTypeName() << "[i].size = sizeof(unsigned int) ;\n" ; } -#if 0 - } else if ( fdes->isVirtualInherited() ) { - // else if we have a virtually inherited class. - outfile << " attr" ; - printNamespaces( outfile, cv , "__" ) ; - printContainerClasses( outfile, cv , "__" ) ; - outfile << cv->getMangledTypeName() << "[i].offset = " << fdes->getBaseClassOffset() ; - outfile << " + offsetof(" ; - //printNamespaces( cv , "::" ) ; - //printContainerClasses( cv , "::" ) ; - outfile << fdes->getContainerClass() << "," << fdes->getName() << ") ;\n" ; - } else if ( cv->getMangledTypeName() != cv->getName() ) { - // else if we have a template type where mangled_type_name is different then name. - outfile << " attr" ; - printNamespaces( outfile, cv , "__" ) ; - printContainerClasses( outfile, cv , "__" ) ; - outfile << cv->getMangledTypeName() << "[i].offset = offsetof(" ; - outfile << cv->getMangledTypeName() << "," << fdes->getName() << ") ;\n" ; - } else { - // else print an offsetof statement if this is not a special case - outfile << " attr" ; - printNamespaces( outfile, cv , "__" ) ; - printContainerClasses( outfile, cv , "__" ) ; - outfile << cv->getMangledTypeName() << "[i].offset = offsetof(" ; - printNamespaces( outfile, cv , "::" ) ; - printContainerClasses( outfile, cv , "::" ) ; - outfile << cv->getMangledTypeName() << "," << fdes->getName() << ") ;\n" ; - } -#endif if ( !fdes->isRecord() and !fdes->isEnum() and !fdes->isBitField() and !fdes->isSTL()) { outfile << " attr" ; @@ -264,10 +236,7 @@ void PrintFileContents10::print_inherited_add_attr_info( std::ofstream & outfile outfile << "\n ATTRIBUTES temp_attr ;\n\n" ; } for ( cit = cv->inherit_classes_begin() ; cit != cv->inherit_classes_end() ; cit++ ) { - outfile << " next_attr = \"" ; - printNamespaces( outfile, *cit , "::" ) ; - printContainerClasses( outfile, *cit , "::" ) ; - outfile << (*cit)->getName() << "\" ;\n" ; + outfile << " next_attr = \"" << *cit << "\" ;\n" ; outfile << " mm->add_attr_info( next_attr , &temp_attr , __FILE__ , __LINE__ ) ;\n" ; } } diff --git a/trick_source/codegen/Interface_Code_Gen/TranslationUnitVisitor.cpp b/trick_source/codegen/Interface_Code_Gen/TranslationUnitVisitor.cpp index 327ae9d6..13352eac 100644 --- a/trick_source/codegen/Interface_Code_Gen/TranslationUnitVisitor.cpp +++ b/trick_source/codegen/Interface_Code_Gen/TranslationUnitVisitor.cpp @@ -49,7 +49,7 @@ bool TranslationUnitVisitor::TraverseDecl(clang::Decl *d) { if ( rd != NULL and ! getFileName(ci , crd->getRBraceLoc(), hsd).empty() ) { //crd->dump() ; std::cout << std::endl ; if ( isInUserCode(ci , crd->getRBraceLoc(), hsd) ) { - CXXRecordVisitor cvis(ci , cs, hsd , pa, false, false, true) ; + CXXRecordVisitor cvis(ci , cs, hsd , pa, true) ; cvis.TraverseCXXRecordDecl(static_cast(d)) ; pa.printClass(cvis.get_class_data()) ; diff --git a/trick_source/codegen/Interface_Code_Gen/TypedefVisitor.cpp b/trick_source/codegen/Interface_Code_Gen/TypedefVisitor.cpp index 9eb8874b..c37a430b 100644 --- a/trick_source/codegen/Interface_Code_Gen/TypedefVisitor.cpp +++ b/trick_source/codegen/Interface_Code_Gen/TypedefVisitor.cpp @@ -70,7 +70,7 @@ bool TypedefVisitor::VisitRecordType(clang::RecordType *rt) { } if ( rd != NULL and ! has_dims ) { - CXXRecordVisitor cvis(ci, cs, hsd, pa, false, false, true) ; + CXXRecordVisitor cvis(ci, cs, hsd, pa, true) ; cvis.TraverseCXXRecordDecl(clang::cast(rd)) ; /* Test to see if the typedef name and the struct/union have the same name. If they do, we won't add the typedeffed record */ @@ -104,7 +104,7 @@ bool TypedefVisitor::VisitTemplateSpecializationType(clang::TemplateSpecializati if ( debug_level >=2 ) { td->dump() ; std::cout << std::endl ; } - CXXRecordVisitor cvis(ci, cs, hsd, pa, false, false, true) ; + CXXRecordVisitor cvis(ci, cs, hsd, pa, true) ; cvis.TraverseCXXRecordDecl(clang::cast(td)) ; cval = cvis.get_class_data() ; // Check to see if this typedef is to a STL. If it is we don't want it. diff --git a/trick_source/codegen/Interface_Code_Gen/VariableVisitor.cpp b/trick_source/codegen/Interface_Code_Gen/VariableVisitor.cpp index 7f93eb15..dd58f44c 100644 --- a/trick_source/codegen/Interface_Code_Gen/VariableVisitor.cpp +++ b/trick_source/codegen/Interface_Code_Gen/VariableVisitor.cpp @@ -57,7 +57,7 @@ bool VariableVisitor::VisitTemplateSpecializationType(clang::TemplateSpecializat if ( debug_level >=2 ) { td->dump() ; std::cout << std::endl ; } - CXXRecordVisitor cvis(ci, cs, hsd, pa, false, false, true) ; + CXXRecordVisitor cvis(ci, cs, hsd, pa, true) ; cval = cvis.get_class_data() ; cvis.TraverseCXXRecordDecl(clang::cast(td)) ; // Check to see if this typedef is to a STL. If it is we don't want it.