mummy
1.0.2
|
00001 //---------------------------------------------------------------------------- 00002 // 00003 // $Id: MummyGenerator.cxx 2 2007-12-17 18:15:56Z david.cole $ 00004 // 00005 // $Author: david.cole $ 00006 // $Date: 2007-12-17 13:15:56 -0500 (Mon, 17 Dec 2007) $ 00007 // $Revision: 2 $ 00008 // 00009 // Copyright (C) 2006-2007 Kitware, Inc. 00010 // 00011 //---------------------------------------------------------------------------- 00012 00013 #include "MummyGenerator.h" 00014 #include "MummyLineOrientedTextFileReader.h" 00015 #include "MummyLog.h" 00016 #include "MummySettings.h" 00017 00018 #include "cableClass.h" 00019 00020 #include "gxsys/RegularExpression.hxx" 00021 00022 00023 //---------------------------------------------------------------------------- 00024 MummyGenerator::MummyGenerator() 00025 { 00026 this->Settings = 0; 00027 this->TargetClass = 0; 00028 this->HeaderFileReader = 0; 00029 } 00030 00031 00032 //---------------------------------------------------------------------------- 00033 MummyGenerator::~MummyGenerator() 00034 { 00035 if (this->HeaderFileReader) 00036 { 00037 delete this->HeaderFileReader; 00038 this->HeaderFileReader = 0; 00039 } 00040 } 00041 00042 00043 //---------------------------------------------------------------------------- 00044 MummySettings* MummyGenerator::GetSettings() 00045 { 00046 return this->Settings; 00047 } 00048 00049 00050 //---------------------------------------------------------------------------- 00051 void MummyGenerator::SetSettings(MummySettings* settings) 00052 { 00053 this->Settings = settings; 00054 } 00055 00056 00057 //---------------------------------------------------------------------------- 00058 const cable::Class* MummyGenerator::GetTargetClass() 00059 { 00060 return this->TargetClass; 00061 } 00062 00063 00064 //---------------------------------------------------------------------------- 00065 void MummyGenerator::SetTargetClass(const cable::Class *c) 00066 { 00067 this->TargetClass = c; 00068 } 00069 00070 00071 //---------------------------------------------------------------------------- 00072 bool MummyGenerator::FundamentalTypeIsWrappable(const cable::Type*) 00073 { 00074 return false; 00075 } 00076 00077 00078 //---------------------------------------------------------------------------- 00079 bool MummyGenerator::TypeIsWrappable(const cable::Type*) 00080 { 00081 return false; 00082 } 00083 00084 00085 //---------------------------------------------------------------------------- 00086 bool MummyGenerator::FunctionTypeIsWrappable(const cable::FunctionType*) 00087 { 00088 return false; 00089 } 00090 00091 00092 //---------------------------------------------------------------------------- 00093 bool MummyGenerator::MethodIsWrappable(const cable::Method*, const cable::Context::Access&) 00094 { 00095 return false; 00096 } 00097 00098 00099 //---------------------------------------------------------------------------- 00100 bool MummyGenerator::ClassIsWrappable(const cable::Class* c) 00101 { 00102 MummySettings* settings = this->GetSettings(); 00103 if (settings) 00104 { 00105 return settings->ClassIsWrappable(c); 00106 } 00107 00108 return false; 00109 } 00110 00111 00112 //---------------------------------------------------------------------------- 00113 MummyLineOrientedTextFileReader* MummyGenerator::GetHeaderFileReader(const cable::Class* c) 00114 { 00115 if (0 == this->HeaderFileReader) 00116 { 00117 this->HeaderFileReader = new MummyLineOrientedTextFileReader; 00118 00119 MummySettings* settings = this->GetSettings(); 00120 if (settings) 00121 { 00122 ClassWrappingSettings cws; 00123 00124 if (settings->FindClassWrappingSettings(GetFullyQualifiedNameForCPlusPlus(c).c_str(), &cws)) 00125 { 00126 this->HeaderFileReader->SetExcludeMarkedLines(cws.excludeMarkedLines); 00127 this->HeaderFileReader->SetBeginExcludeRegex(cws.beginExcludeRegex); 00128 this->HeaderFileReader->SetEndExcludeRegex(cws.endExcludeRegex); 00129 } 00130 else 00131 { 00132 LogError(me_NoClassWrappingSettings, 00133 << "Could not find class wrapping settings for class '" << GetFullyQualifiedNameForCPlusPlus(c).c_str() << "'"); 00134 } 00135 } 00136 00137 this->HeaderFileReader->SetFileName(c->GetFile()); 00138 } 00139 else 00140 { 00141 if (this->HeaderFileReader->GetFileName() != c->GetFile()) 00142 { 00143 LogError(me_InternalError, 00144 << "Trying to open a different file for HeaderFileReader..." << gxsys_stl::endl 00145 << " class: " << GetFullyQualifiedNameForCPlusPlus(c).c_str() << gxsys_stl::endl 00146 << " c->GetFile(): " << c->GetFile() << gxsys_stl::endl 00147 << " this->HeaderFileReader->GetFileName(): " << this->HeaderFileReader->GetFileName() << gxsys_stl::endl 00148 ); 00149 } 00150 } 00151 00152 return this->HeaderFileReader; 00153 } 00154 00155 00156 //---------------------------------------------------------------------------- 00157 void MummyGenerator::EmitMummyVersionComments(gxsys_ios::ostream &os, const char *lineCommentString) 00158 { 00159 gxsys_stl::string mummy_version(this->GetSettings()->GetMummyVersion()); 00160 00161 if (!lineCommentString) 00162 { 00163 lineCommentString = "//"; 00164 } 00165 00166 Emit(os, lineCommentString); 00167 Emit(os, "----------------------------------------------------------------------------\n"); 00168 Emit(os, lineCommentString); 00169 Emit(os, "\n"); 00170 Emit(os, lineCommentString); 00171 Emit(os, " This file was machine generated by:\n"); 00172 Emit(os, lineCommentString); 00173 Emit(os, " "); 00174 Emit(os, mummy_version.c_str()); 00175 Emit(os, "\n"); 00176 Emit(os, lineCommentString); 00177 Emit(os, "\n"); 00178 Emit(os, lineCommentString); 00179 Emit(os, " Manual changes to this file may be overwritten by the next build.\n"); 00180 Emit(os, lineCommentString); 00181 Emit(os, "\n"); 00182 }