CCCC - C and C++ Code Counter  9999-git
CCCC Development version (post-3.1.4)
Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
ParseStore Class Reference

#include <cccc_utl.h>

Collaboration diagram for ParseStore:
[legend]

Public Member Functions

 ParseStore (const string &filename)
 
 ~ParseStore ()
 
void IncrementCount (LexicalCount lc)
 
void endOfLine (int line)
 
void record_module_extent (int startLine, int endLine, const string &moduleName, const string &moduleType, const string &description, UseType ut)
 
void record_function_extent (int startLine, int endLine, const string &returnType, const string &moduleName, const string &memberName, const string &paramList, const string &description, Visibility visibility, UseType ut)
 
void record_userel_extent (int startLine, int endLine, const string &clientName, const string &memberName, const string &serverName, const string &description, Visibility visibility, UseType ut)
 
void record_other_extent (int startLine, int endLine, const string &description)
 
void record_file_balance_extent (string)
 
void insert_extent (CCCC_Item &, int, int, const string &, const string &, UseType, bool allocate_lexcounts)
 
int get_flag (PSFlag) const
 
void set_flag (PSFlag, int)
 
void set_flag (Visibility)
 
Visibility get_visibility ()
 
string filename ()
 
char * flags ()
 

Static Public Member Functions

static ParseStorecurrentInstance ()
 

Private Types

typedef std::vector< int > LexicalCountArray
 
typedef std::map< int, LexicalCountArrayLineLexicalCountMatrix
 
typedef std::vector< char > CharArray
 

Private Member Functions

 ParseStore (const ParseStore &)
 
const ParseStoreoperator= (const ParseStore &)
 

Private Attributes

string theFilename
 
LexicalCountArray pendingLexicalCounts
 
LineLexicalCountMatrix lineLexicalCounts
 
CharArray flag
 

Static Private Attributes

static ParseStoretheCurrentInstance =NULL
 

Detailed Description

Definition at line 209 of file cccc_utl.h.

Member Typedef Documentation

typedef std::vector<char> ParseStore::CharArray
private

Definition at line 281 of file cccc_utl.h.

typedef std::vector<int> ParseStore::LexicalCountArray
private

Definition at line 275 of file cccc_utl.h.

Definition at line 278 of file cccc_utl.h.

Constructor & Destructor Documentation

ParseStore::ParseStore ( const string &  filename)

Definition at line 234 of file cccc_utl.cc.

236 , pendingLexicalCounts(static_cast<int>(tcLAST),0)
237 , flag(static_cast<int>(psfLAST)+1,'?')
238 {
239  // This is designed as a serial-singleton class (e.g. many
240  // instances may exist over time but no more than one at a
241  // time).
242  // For the lifetime of an instance, the static member theCurrentInstance
243  // points to it. When no instance exists, this pointer is null.
244  assert(theCurrentInstance==NULL);
245  theCurrentInstance=this;
246  flag[psfLAST]='\0';
247 }
LexicalCountArray pendingLexicalCounts
Definition: cccc_utl.h:276
CharArray flag
Definition: cccc_utl.h:282
string filename()
Definition: cccc_utl.cc:281
static ParseStore * theCurrentInstance
Definition: cccc_utl.h:271
string theFilename
Definition: cccc_utl.h:273
ParseStore::~ParseStore ( )

Definition at line 249 of file cccc_utl.cc.

250 {
251  // If the current object came from the default constructor
252  // it is the primary singleton instance and we wish to
253  // set the static pointer to itself back to null. Otherwise,
254  // it was a cached copy, and we don't really care.
255  if(theCurrentInstance==this)
256  {
257  theCurrentInstance=NULL;
258  }
259 }
static ParseStore * theCurrentInstance
Definition: cccc_utl.h:271
ParseStore::ParseStore ( const ParseStore )
private

Member Function Documentation

static ParseStore* ParseStore::currentInstance ( )
inlinestatic

Definition at line 269 of file cccc_utl.h.

269 { return theCurrentInstance; }
static ParseStore * theCurrentInstance
Definition: cccc_utl.h:271

Here is the caller graph for this function:

void ParseStore::endOfLine ( int  line)

Definition at line 587 of file cccc_utl.cc.

588 {
589  // We only do the processing below if the line which has just
590  // ended contained at least one non-skippable token
591  // The flag which tells us whether this is true is set in the
592  // token constructor
594  {
596  LineLexicalCountMatrix::value_type
597  vt(line,LexicalCountArray(static_cast<int>(tcLAST),0));
598 
599  for(int i=0; i<tcLAST; i++)
600  {
601  vt.second[i]=pendingLexicalCounts[i];
603  }
604  lineLexicalCounts.insert(vt);
605 
606  // reset the flat for next time
607  ANTLRToken::bCodeLine=false;
608  }
609 }
std::vector< int > LexicalCountArray
Definition: cccc_utl.h:275
LineLexicalCountMatrix lineLexicalCounts
Definition: cccc_utl.h:279
LexicalCountArray pendingLexicalCounts
Definition: cccc_utl.h:276
static int bCodeLine
Definition: cccc_tok.h:65
string ParseStore::filename ( )

Definition at line 281 of file cccc_utl.cc.

282 {
283  return theFilename;
284 }
string theFilename
Definition: cccc_utl.h:273

Here is the caller graph for this function:

char* ParseStore::flags ( )
inline

Definition at line 261 of file cccc_utl.h.

261 { return &(*flag.begin()); }
CharArray flag
Definition: cccc_utl.h:282

Here is the caller graph for this function:

int ParseStore::get_flag ( PSFlag  psf) const

Definition at line 261 of file cccc_utl.cc.

261  {
262  return int(flag[psf]);
263 }
CharArray flag
Definition: cccc_utl.h:282
Visibility ParseStore::get_visibility ( )

Definition at line 276 of file cccc_utl.cc.

277 {
278  return static_cast<Visibility>(flag[psfVISIBILITY]);
279 }
Visibility
Definition: cccc_utl.h:52
CharArray flag
Definition: cccc_utl.h:282
void ParseStore::IncrementCount ( LexicalCount  lc)
inline

Definition at line 215 of file cccc_utl.h.

215 { pendingLexicalCounts[lc]++; }
LexicalCountArray pendingLexicalCounts
Definition: cccc_utl.h:276
void ParseStore::insert_extent ( CCCC_Item os,
int  startLine,
int  endLine,
const string &  description,
const string &  flags,
UseType  ut,
bool  allocate_lexcounts 
)

Definition at line 288 of file cccc_utl.cc.

291 {
292  os.Insert(theFilename);
293  os.Insert(startLine);
294  os.Insert(description);
295  os.Insert(flags);
296  int i;
297  int lexical_counts_for_this_extent[tcLAST];
298  for(i=0; i<tcLAST; i++)
299  {
300  lexical_counts_for_this_extent[i]=0;
301  }
302 
303  if(allocate_lexcounts==true)
304  {
305  LineLexicalCountMatrix::iterator extentStartIter =
306  lineLexicalCounts.lower_bound(startLine);
307  LineLexicalCountMatrix::iterator extentEndIter =
308  lineLexicalCounts.upper_bound(endLine-1);
309  LineLexicalCountMatrix::iterator llcmIter;
310  for(llcmIter=extentStartIter;
311  llcmIter!=extentEndIter;
312  ++llcmIter)
313  {
314  // This record relates to a line within the current
315  // extent.
316  for(i=0; i<tcLAST; i++)
317  {
318  lexical_counts_for_this_extent[i]+=(*llcmIter).second[i];
319  }
320  }
321  // The lexical occurrences mentioned in the records processed
322  // above are now been accounted for in the database, so we
323  // purge these records. This has the effect of allowing
324  // accurate accounting on nested extents (i.e. the outer
325  // extent will only be reported as containing lines which
326  // are not already listed in the inner extent).
327  lineLexicalCounts.erase(extentStartIter,extentEndIter);
328 
329  ostringstream lexcount_str;
330 
331  lexcount_str << "LOC:" << lexical_counts_for_this_extent[tcCODELINES]
332  << " COM:" << lexical_counts_for_this_extent[tcCOMLINES]
333  << " MVG:" << lexical_counts_for_this_extent[tcMCCABES_VG]
334  << ends;
335 
336  os.Insert(lexcount_str.str().c_str());
337 
338  }
339  else
340  {
341  os.Insert("*");
342  }
343  os.Insert((char)flag[psfVISIBILITY]);
344  os.Insert((char)ut);
345 }
bool Insert(const string &s)
Definition: cccc_itm.cc:31
LineLexicalCountMatrix lineLexicalCounts
Definition: cccc_utl.h:279
CharArray flag
Definition: cccc_utl.h:282
char * flags()
Definition: cccc_utl.h:261
string theFilename
Definition: cccc_utl.h:273

Here is the call graph for this function:

Here is the caller graph for this function:

const ParseStore& ParseStore::operator= ( const ParseStore )
private
void ParseStore::record_file_balance_extent ( string  )
void ParseStore::record_function_extent ( int  startLine,
int  endLine,
const string &  returnType,
const string &  moduleName,
const string &  memberName,
const string &  paramList,
const string &  description,
Visibility  visibility,
UseType  ut 
)

Definition at line 368 of file cccc_utl.cc.

376 {
377  // We require every call to this function to specify a member
378  // function name and a parameter list.
379  if(memberName.size()>0)
380  {
381  // If the moduleName is an empty string, we remap this to the
382  // string "anonymous". This implies that we treat all
383  // C-style functions as belonging to a single module.
384  string mappedModuleName = moduleName;
385  if(mappedModuleName.size()==0)
386  {
387  mappedModuleName = "anonymous";
388  }
389 
390  CCCC_Item function_line;
391  function_line.Insert(mappedModuleName);
392  function_line.Insert(memberName);
393  function_line.Insert(returnType);
394  function_line.Insert(paramList);
395 
396  string baseFlags=flags();
397  baseFlags[psfVISIBILITY]=visibility;
398 
399  insert_extent(function_line,startLine,endLine,
400  description,baseFlags,ut,true);
401  prj->add_member(function_line);
402  }
403 }
bool Insert(const string &s)
Definition: cccc_itm.cc:31
CCCC_Project * prj
Definition: ccccmain.cc:49
void add_member(CCCC_Item &member_data_line)
Definition: cccc_prj.cc:88
void insert_extent(CCCC_Item &, int, int, const string &, const string &, UseType, bool allocate_lexcounts)
Definition: cccc_utl.cc:288
char * flags()
Definition: cccc_utl.h:261

Here is the call graph for this function:

void ParseStore::record_module_extent ( int  startLine,
int  endLine,
const string &  moduleName,
const string &  moduleType,
const string &  description,
UseType  ut 
)

Definition at line 349 of file cccc_utl.cc.

354 {
355  // See the lengthy comment in record_userel_extent about
356  // why we are filtering for empty module names.
357  if(moduleName.size()>0)
358  {
359  CCCC_Item module_line;
360  module_line.Insert(moduleName);
361  module_line.Insert(moduleType);
362  insert_extent(module_line,startLine,endLine,
363  description,flags(),ut,true);
364  prj->add_module(module_line);
365  }
366 }
bool Insert(const string &s)
Definition: cccc_itm.cc:31
CCCC_Project * prj
Definition: ccccmain.cc:49
void add_module(CCCC_Item &module_data_line)
Definition: cccc_prj.cc:56
void insert_extent(CCCC_Item &, int, int, const string &, const string &, UseType, bool allocate_lexcounts)
Definition: cccc_utl.cc:288
char * flags()
Definition: cccc_utl.h:261

Here is the call graph for this function:

void ParseStore::record_other_extent ( int  startLine,
int  endLine,
const string &  description 
)

Definition at line 452 of file cccc_utl.cc.

454 {
455  CCCC_Item rejext_line;
456  insert_extent(rejext_line,startLine,endLine,description,flags(),utREJECTED,true);
457  prj->add_rejected_extent(rejext_line);
458 }
void add_rejected_extent(CCCC_Item &rejected_data_line)
Definition: cccc_prj.cc:145
CCCC_Project * prj
Definition: ccccmain.cc:49
void insert_extent(CCCC_Item &, int, int, const string &, const string &, UseType, bool allocate_lexcounts)
Definition: cccc_utl.cc:288
char * flags()
Definition: cccc_utl.h:261

Here is the call graph for this function:

void ParseStore::record_userel_extent ( int  startLine,
int  endLine,
const string &  clientName,
const string &  memberName,
const string &  serverName,
const string &  description,
Visibility  visibility,
UseType  ut 
)

Definition at line 405 of file cccc_utl.cc.

412 {
413  CCCC_Item userel_line;
414 
415  // This function should not be invoked unless the clientName
416  // and serverName are non-empty strings, however it appears
417  // that in test case prn16.java the parser does execute the
418  // actions of the 'implementsClause' rule, even though there
419  // is no 'implements' keyword outside comments in the program
420  // text.
421  // I don't understand this, but as a workaround, I filter at
422  // this point and ensure that if either clientName or serverName
423  // is empty, no action is taken.
424  if(clientName.size()>0 && serverName.size()>0)
425  {
426  userel_line.Insert(clientName);
427  userel_line.Insert(memberName);
428  userel_line.Insert(serverName);
429 
430  // for data member definitions, we record lexical data for the
431  // extent,
432  // for inheritance and parameter relationships we do not
433  bool record_lexcounts=false;
434  switch(ut)
435  {
436  case utHASBYVAL:
437  case utHASBYREF:
438  record_lexcounts=true;
439  break;
440  default:
441  record_lexcounts=false;
442  }
443 
444  string baseFlags=flags();
445  baseFlags[psfVISIBILITY]=visibility;
446  insert_extent(userel_line,startLine,endLine,
447  description,baseFlags,ut,record_lexcounts);
448  prj->add_userel(userel_line);
449  }
450 }
bool Insert(const string &s)
Definition: cccc_itm.cc:31
CCCC_Project * prj
Definition: ccccmain.cc:49
void insert_extent(CCCC_Item &, int, int, const string &, const string &, UseType, bool allocate_lexcounts)
Definition: cccc_utl.cc:288
char * flags()
Definition: cccc_utl.h:261
void add_userel(CCCC_Item &use_data_line)
Definition: cccc_prj.cc:125

Here is the call graph for this function:

void ParseStore::set_flag ( PSFlag  psf,
int  value 
)

Definition at line 265 of file cccc_utl.cc.

265  {
266  flag[psf]=value;
267 }
CharArray flag
Definition: cccc_utl.h:282
void ParseStore::set_flag ( Visibility  value)

Definition at line 269 of file cccc_utl.cc.

269  {
270  MAKE_STRSTREAM(ofstr);
271  ofstr << value;
272  flag[psfVISIBILITY]=(ofstr.str())[0];
273  RELEASE_STRSTREAM(ofstr);
274 }
CharArray flag
Definition: cccc_utl.h:282
#define RELEASE_STRSTREAM(X)
Definition: cccc.h:69
#define MAKE_STRSTREAM(X)
Definition: cccc.h:67

Member Data Documentation

CharArray ParseStore::flag
private

Definition at line 282 of file cccc_utl.h.

LineLexicalCountMatrix ParseStore::lineLexicalCounts
private

Definition at line 279 of file cccc_utl.h.

LexicalCountArray ParseStore::pendingLexicalCounts
private

Definition at line 276 of file cccc_utl.h.

ParseStore * ParseStore::theCurrentInstance =NULL
staticprivate

Definition at line 271 of file cccc_utl.h.

string ParseStore::theFilename
private

Definition at line 273 of file cccc_utl.h.


The documentation for this class was generated from the following files: