Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

Prototyper Class Reference

Inheritance diagram for Prototyper:

Inheritance graph
[legend]
Collaboration diagram for Prototyper:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 Prototyper (bool static_functions=false)
void begin ()
void filter (const cmt_string &line)
void end ()

Private Attributes

bool m_running
cmt_string m_out_file_name
FILE * m_output
bool m_static_functions
cmt_string m_full_line
cmt_string m_prev_line
cmt_string m_suffix
cmt_string m_define_suffix

Constructor & Destructor Documentation

Prototyper::Prototyper bool  static_functions = false  )  [inline]
 

Definition at line 1267 of file cmt_generators.cxx.

References m_define_suffix, m_static_functions, and m_suffix.

01267                                              :
01268     m_static_functions(static_functions)
01269   {
01270     if (m_static_functions)
01271       {
01272         m_suffix = "_static.phnew";
01273         m_define_suffix = "_static_ph";
01274       }
01275     else
01276       {
01277         m_suffix = ".phnew";
01278         m_define_suffix = "_ph";
01279       }
01280   }


Member Function Documentation

void Prototyper::begin  )  [inline, virtual]
 

Reimplemented from Awk.

Definition at line 1282 of file cmt_generators.cxx.

References CmtSystem::basename(), cmt_string::c_str(), CmtSystem::file_separator(), CmtSystem::get_dot_suffix(), m_define_suffix, m_out_file_name, m_output, m_running, m_suffix, and Awk::stop().

01283   {
01284     m_running = false;
01285 
01286     static cmt_string suffix;
01287     static cmt_string name;
01288 
01289     CmtSystem::get_dot_suffix (m_file_name, suffix);
01290     CmtSystem::basename (m_file_name, suffix, name);
01291 
01292     m_out_file_name  = "";
01293 
01294     if (m_dir_name != "")
01295       {
01296         m_out_file_name  = m_dir_name;
01297         m_out_file_name += CmtSystem::file_separator ();
01298       }
01299 
01300     m_out_file_name += name;
01301     m_out_file_name += m_suffix;
01302 
01303     CmtSystem::basename (m_file_name, suffix, m_file_name);
01304 
01305     m_output = fopen (m_out_file_name.c_str (), "wb");
01306 
01307     if (m_output != 0)
01308       {
01309         fprintf (m_output, "#ifndef __%s%s__\n", m_file_name.c_str (),
01310                  m_define_suffix.c_str ());
01311         fprintf (m_output, "#define __%s%s__\n", m_file_name.c_str (),
01312                  m_define_suffix.c_str ());
01313 
01314         fprintf (m_output, "\n");
01315         fprintf (m_output, "#ifdef __cplusplus\n");
01316         fprintf (m_output, "extern \"C\" {\n");
01317         fprintf (m_output, "#endif\n");
01318         fprintf (m_output, "\n");
01319       }
01320     else
01321       {
01322         stop ();
01323       }
01324   }

void Prototyper::end  )  [inline, virtual]
 

Reimplemented from Awk.

Definition at line 1394 of file cmt_generators.cxx.

References CmtGenerator::check(), m_out_file_name, and m_output.

01395   {
01396     if (m_output != 0)
01397       {
01398         fprintf (m_output, "\n");
01399         fprintf (m_output, "#ifdef __cplusplus\n");
01400         fprintf (m_output, "}\n");
01401         fprintf (m_output, "#endif\n");
01402         fprintf (m_output, "\n");
01403         fprintf (m_output, "#endif\n");
01404         fprintf (m_output, "\n");
01405 
01406         fclose (m_output);
01407       }
01408 
01409     CmtGenerator::check (m_out_file_name);
01410   }

void Prototyper::filter const cmt_string line  )  [inline, virtual]
 

Reimplemented from Awk.

Definition at line 1326 of file cmt_generators.cxx.

References cmt_string::c_str(), CmtSystem::cmt_string_vector, cmt_string::find(), m_full_line, m_output, m_prev_line, m_running, m_static_functions, cmt_string::replace(), and CmtSystem::split().

01327   {
01328     char c = line[0];
01329 
01330     if (!m_running)
01331       {
01332         if ((c == ' ') ||
01333             (c == '/') ||
01334             (c == '|') ||
01335             (c == '\t') ||
01336             (c == '#')) return;
01337         if (line.find ('(') == cmt_string::npos)
01338           {
01339             m_prev_line = line;
01340             return;
01341           }
01342 
01343         m_running = true;
01344         m_full_line = line;
01345         m_full_line.replace ("(", " (");
01346 
01347         static CmtSystem::cmt_string_vector words;
01348 
01349         CmtSystem::split (m_full_line, " \t", words);
01350 
01351         const cmt_string& second = words[1];
01352         if (second[0] == '(')
01353           {
01354             m_full_line = m_prev_line;
01355             m_full_line += " ";
01356             m_full_line += line;
01357 
01358             m_prev_line = "";
01359           }
01360       }
01361     else
01362       {
01363         m_full_line += line;
01364       }
01365     if (line.find (')') == cmt_string::npos) return;
01366     m_running = false;
01367 
01368     if (m_full_line.find (';') != cmt_string::npos) return;
01369     if (m_full_line.find ("::") != cmt_string::npos) return;
01370     if (m_full_line.find ('<') != cmt_string::npos) return;
01371     if (m_full_line.find ('>') != cmt_string::npos) return;
01372     if (m_full_line.find ('{') != cmt_string::npos) return;
01373     if (m_full_line.find ('}') != cmt_string::npos) return;
01374     if (m_full_line.find ("typedef") != cmt_string::npos) return;
01375     if (m_full_line.find ("yy") != cmt_string::npos) return;
01376     if (m_full_line.find ("YY") != cmt_string::npos) return;
01377     if (m_static_functions)
01378       {
01379         if (m_full_line.find ("static") == cmt_string::npos) return;
01380       }
01381     else
01382       {
01383         if (m_full_line.find ("static") != cmt_string::npos) return;
01384       }
01385 
01386     m_full_line += ";";
01387 
01388     if (m_output != 0)
01389       {
01390         fprintf (m_output, "%s\n", m_full_line.c_str ());
01391       }
01392   }


Member Data Documentation

cmt_string Prototyper::m_define_suffix [private]
 

Definition at line 1420 of file cmt_generators.cxx.

Referenced by begin(), and Prototyper().

cmt_string Prototyper::m_full_line [private]
 

Definition at line 1417 of file cmt_generators.cxx.

Referenced by filter().

cmt_string Prototyper::m_out_file_name [private]
 

Definition at line 1414 of file cmt_generators.cxx.

Referenced by begin(), and end().

FILE* Prototyper::m_output [private]
 

Definition at line 1415 of file cmt_generators.cxx.

Referenced by begin(), end(), and filter().

cmt_string Prototyper::m_prev_line [private]
 

Definition at line 1418 of file cmt_generators.cxx.

Referenced by filter().

bool Prototyper::m_running [private]
 

Definition at line 1413 of file cmt_generators.cxx.

Referenced by begin(), and filter().

bool Prototyper::m_static_functions [private]
 

Definition at line 1416 of file cmt_generators.cxx.

Referenced by filter(), and Prototyper().

cmt_string Prototyper::m_suffix [private]
 

Definition at line 1419 of file cmt_generators.cxx.

Referenced by begin(), and Prototyper().


The documentation for this class was generated from the following file:
Generated on Mon May 2 10:25:58 2005 for CMT by doxygen 1.3.5