Docsity

CSE687 Project 2 - Code Analyzer - Prof. James Fawcett, Study Guides, Projects, Research of Engineering

Toggle sidebar
bg1
CSE687 – Object Oriented Design S 2002
Project #2 – Code Analyzer due
Monday, Mar 04
Purpose:
The purpose of this project is to build a program using a set of C++ modules that examine
and record in an XML file the results of analyzing one or more source code files.
Specifically, you will analyze each file matching a pattern supplied on the command line
and display to the user, and record in an XML file, the following:
Correct header preprocessor statements (yes or no)
Prologue comments (number of lines of comments)1
Correct test stub preprocessor statements (yes or no)
A main function inside the test stub (number of lines of code)
A sequence of line counts for each function definition, sorted in descending order
A sequence of cyclomatic complexities for each function definition, sorted in
descending order
The sum of the function sizes and sum of the cyclomatic complexities
Requirements:
Your ANALYZER program:
1. shall compile and link from the command line, using VC++ 6.0, as provided in the ECS cluster
and operate in the environment provided there2.
2. shall provide an executive module that reads a userid and one or more file patterns 3 from the
command line. It shall delegate all analysis to an analysis module.
3. shall provide an analysis module that defines an analysis class. This class shall be templatized
on a parameter used to specify an analysis functor4.
4. shall provide an analysis functor class for each of the analysis tasks listed above. The
implications of this design strategy are 1) the analysis tasks are nicely partitioned into relatively
simple operations, 2) each analysis task will require rescanning the file, and finally 3) you will
create an analysis class object for each task, templatized on the appropriate functor. Note that
the analysis class delegates all the analyzing activities to its functors. It simply is charged with
scanning the file and applying its functor object to scanned items. For questions about
scanning, see the comments on the next page.
5. The client display output shall consist of a series of blocks, one block for each file. Each block
contains a series of lines of output, one line for each analysis operation. A block should begin
with a file name. Each subsequent line of the block contains analysis information about the file.
For cyclomatic complexity and function sizes, please display one line with the analysis type, e.g.,
cyclo or sizes, and a sequence of integers sorted in descending order, representing the analysis
results. Please terminate the line with the sum of the integer sequence.
6. The client shall also write this information out to a file in XML format, starting with the userid
collected in item #2, above. The client shall provide a mode of operation in which it reads an
existing XML file and displays the analysis information, without doing any analysis other than
parsing the XML file. Please invoke this operation by naming an XML file for inspection. Thus,
1 For a header file the prologue includes manual and maintenance pages.
2 See notes on project submissions, handed out during the first class.
3 A file pattern is a string of the form “*.h *.cpp”
4 A functor is an object of a class providing an operator()(…) member function.
pf2

Partial preview of the text

Download CSE687 Project 2 - Code Analyzer - Prof. James Fawcett and more Study Guides, Projects, Research Engineering in PDF only on Docsity!

CSE687 – Object Oriented Design S 2002

Project #2 – Code Analyzer due

Monday, Mar 04

Purpose:

The purpose of this project is to build a program using a set of C++ modules that examine and record in an XML file the results of analyzing one or more source code files. Specifically, you will analyze each file matching a pattern supplied on the command line and display to the user, and record in an XML file, the following:  Correct header preprocessor statements (yes or no)  Prologue comments (number of lines of comments)^1  Correct test stub preprocessor statements (yes or no)  A main function inside the test stub (number of lines of code)  A sequence of line counts for each function definition, sorted in descending order  A sequence of cyclomatic complexities for each function definition, sorted in descending order  The sum of the function sizes and sum of the cyclomatic complexities

Requirements:

Your ANALYZER program:

  1. shall compile and link from the command line, using VC++ 6.0, as provided in the ECS cluster and operate in the environment provided there^2.
  2. shall provide an executive module that reads a userid and one or more file patterns^3 from the command line. It shall delegate all analysis to an analysis module.
  3. shall provide an analysis module that defines an analysis class. This class shall be templatized on a parameter used to specify an analysis functor^4.
  4. shall provide an analysis functor class for each of the analysis tasks listed above. The implications of this design strategy are 1) the analysis tasks are nicely partitioned into relatively simple operations, 2) each analysis task will require rescanning the file, and finally 3) you will create an analysis class object for each task, templatized on the appropriate functor. Note that the analysis class delegates all the analyzing activities to its functors. It simply is charged with scanning the file and applying its functor object to scanned items. For questions about scanning, see the comments on the next page.
  5. The client display output shall consist of a series of blocks, one block for each file. Each block contains a series of lines of output, one line for each analysis operation. A block should begin with a file name. Each subsequent line of the block contains analysis information about the file. For cyclomatic complexity and function sizes, please display one line with the analysis type, e.g., cyclo or sizes, and a sequence of integers sorted in descending order, representing the analysis results. Please terminate the line with the sum of the integer sequence.
  6. The client shall also write this information out to a file in XML format, starting with the userid collected in item #2, above. The client shall provide a mode of operation in which it reads an existing XML file and displays the analysis information, without doing any analysis other than parsing the XML file. Please invoke this operation by naming an XML file for inspection. Thus, (^1) For a header file the prologue includes manual and maintenance pages. (^2) See notes on project submissions, handed out during the first class. (^3) A file pattern is a string of the form “*.h *.cpp” (^4) A functor is an object of a class providing an operator()(…) member function.

CSE687 – Object Oriented Design S 2002

files with extensions “.h” or “.cpp” are analyzed, while files with extensions “.xml” are used for display. You are encouraged to use the semi and tok modules, provided in proj #2 help folder in the class directory, to scan a file for analysis. One way to organize your design is for the analysis class to extract semiexpressons^5 , the output of the semi module, to present to the analysis functor. If the semiexpression is useful for analysis it will be the source information gathered by the functor. Otherwise the functor simply ignores the semiexpression and returns. To help you understand the display requirements, here is a sample acceptable output format: JohnDoe Exec.cpp Preprocessor statements: no Prologue lines: 43 Main line count: 11 cyclo: 12, 11, 8 – 31 sizes: 35, 22, 12 – 69 Analysis.h Preprocessor statements: yes Prologue lines: 65 cyclo: 1, 1, 1 - 3 sizes: 5, 3, 3 – 11 Analysis.cpp Preprocessor statements: yes Prologue lines: 7 Main line count: 22 cyclo: 11, 7, 7, 5, 1, 1 - 32 sizes: 55, 37, 31, 22, 15, 5 - 165 Note that there are a number of opportunities for elegant partitioning of your design. For example, you may wish to have your functors provide a display function that is responsible for one line of output for each block. The analysis module then simply asks each functor to analyze then display its results. You are further encouraged to find other places in your design to use templates to simplify the design or implementation. (^5) A semi expression is a sequence of tokens that are particularly useful for code analysis. We will discuss semiexpressions in class.