⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 metre.doc

📁 这是一个C程序分析工具
💻 DOC
📖 第 1 页 / 共 3 页
字号:
              int c;           } d;        } e;Preprocessor StatementsAs counted by Metre, a preprocessor statement is a source line thatbegins with optional whitespace followed by a '#' character that is notcontained within a comment. If you run Metre against the output of apreprocessor, most preprocessor statements will have been processed andremoved, so this count may be unusually low or even 0. The preprocessormay pass some #pragma's through and may also insert #line statements, sothe count of preprocessor statements may have little bearing on thenumber present in the original source file.Metre does not recognize a preprocessor statement that has beencontinued onto another line. It will most likely cause a syntax errorwhen Metre tries to parse the continued line. In this case, you mustpreprocess the source first to remove all continued preprocessorstatements.Function PointsFunction points are estimated using what is known as "backfiring." Ithas been determined that it takes an average of 128 C statements(executable, declaration, and preprocessor statements) to code onefunction point. This assumes moderately complex code. From Capers Jonesbook, _Applied Software Measurement_,        In essence, it takes fewer statements to implement one function        point for simple applications than it does for complex ones.        This concept is also true in reverse: When function points are        backfired, highly complex code will contain fewer function        points than the same volume of simple code. This concept is        counterintuitive, but it appears to be empirically correct.So, for example, if the code you are measuring contains a lot offunctions that have a high cyclomatic complexity index, such as 38, thebackfired function points that Metre generates will be a bit high--thecode actually represents fewer function points.Note: If you run your code through the preprocessor first, the number ofpreprocessor statements will likely be reduced. This then reduces thebackfired function points. However, it has been my experience thatpreprocessor statements make up only a small percentage of the totalnumber of statements in a C program. Likewise, if your preprocessorincludes line directives, e.g., # 23 "filex.c", Metre counts them aspreprocessor statements. This also distorts the backfired functionpoints. So in order to get the most accurate estimates, try to run Metreagainst your original source. Use the -D command-line option to performany needed translations in lieu of the preprocessor.Adjusting Function PointsIn the SPR's 1985 backfire method, described in Capers' book, theinitial backfired function points can be adjusted up or down based onthe combined logic, data, and problem complexities. These are subjectivemetrics and use a different scale than that of cyclomatic complexity. Ithas not been established in the literature how one would use cyclomaticcomplexity to adjust backfired function points for a more accurateestimate.However, having said that, I use the following table, based on Table2.16 in _Applied Software Measurement_, to adjust the initialfunction-points metric when the -a command-line option is specified.This is not the default behavior because my adjustment algorithm isunsanctioned--there is no standard that I know of for adjusting functionpoints based on cyclomatic complexity.I look up in this table the multiplier that corresponds to thecyclomatic complexity and divide the initial function-points metric bythis value. I use the same range of multipliers as Capers does in hisbook (0.70 - 1.30), I use the same qualities, "Simple" to "Verycomplex," to characterize complexity, and I use his discussion of thedegrees of cyclomatic complexity to determine how to map them to theappropriate multipliers. The curve of this function is asymptotic to the1.30 multiplier; however, not truely, because I clip the factor at thecyclomatic complexity of 54--all complexities at or above 54 have thesame multiplier of 1.30. See the graph that follows the table.Modification of TABLE 2.16 for Cyclomatic complexity adjustment    Cyclomatic                   Code size adjustment    complexity                        multiplier        1          Simple               0.70        2                               0.80        3          Moderate             0.85        4-5                             0.90        6-8                             0.95        9-11       Average              1.00        12-16                           1.05        17-21                           1.10        22-27      Complex              1.15        28-36                           1.20        37-53                           1.25        54-        Very complex         1.30Graph of Modification of TABLE 2.16 for Cyclomatic complexity adjustment   1.30                                         .      .      .      .                                .   1.15                .                  .   1.00        .             .   0.85    .          .   0.70  --------------------------------------------------------------          1 3  10           25                     54     Simple   Average     Complex                  Very complex         ModerateMtree Call-Tree Tool--------------------The set of rules in trerules.c define the tool, Mtree, that printscall-hierarchy trees and an optional function table of contents.Briefly, from the command line, you can name the root function, selectan alternate graphic character set for the tree or select no tree atall, specify the width of the file-name margin, specify the degree ofindention, specify whether to print the table of contents, and selectwhether to ignore library calls. Here is the help text, displayed withthe -h command-line option, that identifies the command-line options andtheir function.METRE Version 2.3  Copyright (c) 1993-1995 by Paul Long  All rights reserved.Syntax: MTREE [ option | file ]...-Dxxx=[xxx] Define identifier          -oxxx       Name of output file-Sxxx       Substitute file name       -C          Copy input to output-w          Suppress warnings          -h          This help-fxxx       Response file-rxxx       Root function name         -cN         Indent columns per level [4]-g          Alternate-character tree   -t          Print table of contents-n          No tree                    -l          Ignore library calls-mN         File name margin [12]Basic OperationMtree accepts one or more C source files and prints one or more calltrees. If the name of a root function is specified on the command linewith the -r option, as in -rlog_transaction, Mtree starts the first treewith that function. If not specified, Mtree starts with the functionnamed "main." If there is no main function, Mtree starts with the firstfunction it encounters.Once this first call tree has been printed, Mtree prints separate calltrees for functions that have not yet taken part in a call tree. This isespecially useful for function libraries, where there is not just oneroot function.If you want Mtree to ignore calls to the Standard C library, such as toprintf(), use the -l command-line option. This is useful if you want toconsider the library as part of the language.Mtree normally just prints the call trees and then stops. However, youcan instruct it to print a table of contents after the trees with the -tcommand-line option. This lists all functions by file name along withthe line number on which they are defined. Mtree's file, function, andline are analogous to a book's part, chapter, and page.Formatting Command-Line OptionsUse the -c command-line option to tell Mtree how many columns to indenteach call level. For example, -c8 causes Mtree to indent each level byeight columns. The default is by four columns.Use the -m command-line option to specify how wide the left margin iswithin which Mtree prints the name of the file that contains thefunction. Mtree right-justifies the file name within this margin andtruncates any extras characters to the left so that some pathinformation may be lost. This assures that at least the file name can beseen. The default margin width is 12 columns (do I detect an MS-DOS biashere?). For example, -m20 allows for a margin for potentially longerUNIX file names. Here is a tip: Specify -m0 if you do not want the filename in the output.Mtree draws a "tree" to show the calling hierarchy. This graphicallyconnects calling functions with called functions. By default, Mtree usesASCII characters to draw the tree lines so that its output isdisplayable on virtually all output devices. However, you can select analternate set of graphic characters with the -g command-line option.This causes Mtree to use line-draw characters from the IBM graphiccharacter set. Trees drawn with these characters look much nicer. Manyprinters, including laser printers, have a font that contains thesecharacters. If you want something else, change the alternate charactersin trerules.c. If you do not want Mtree to draw the tree at all, use the-n command-line option.LimitationsFor the name of a called function, Mtree uses the identifier immediatelybefore the call's '('. This may give misleading results if a function iscalled through an expression that yields a function pointer.Mtree ignores duplicate function names. This should only cause a problemif you have functions in different files with interal linkage (e.g,static foo() { ... }) that have the same name. Mtree ignores thesecond and subsequent functions with the same name.Commercial Metrics Tools------------------------The only metric tool I have ever used is Metre. If you feel you need amore robust or complete product or just want the support of a commercialproduct, here are a couple of commercial metrics tools. They bothsupport C and C++, run under several operating systems, and cost severalhundred dollars. Metre was inspired by CodeCheck, but the rules are notportable between the two products.        CodeCheck                Abraxas Software                5530 SW Kelley Ave.                Portland, OR 97201                USA                Phone: 503-244-5253                Fax: 503-244-8375                AppleLink: D2205                MCI: ABRAXAS        PC-METRIC                SET Laboratories, Inc.                P.O. Box 868                Mulino, OR 97042                USA                Phone: 503-829-7123                Fax: 503-829-7220                Internet: info@setlabs.or97042.sai.comBibliography------------Halstead, M., _Elements of Software Science_, Elsevier North Holland,New York 1977.Jones, C., _Applied Software Measurement_, McGraw-Hill, New York, NY,1991, 493 pages.Kitchenham, Pickardm, and Linkman, "An evaluation of some designmetrics," _Software Engineering Journal_, 5(1), January 1990, pp. 50-58.Lassez, et al., "A critical examination of software science," _Journalof Systems and Software_, 2, 1981, pp. 105-112.McCabe, T., "A Complexity Measure," _IEEE Transactions on SoftwareEngineering_, vol. SE-12(4), December 1976, pp. 308-320.Miller, et al., "A software science counting strategy for the full Adalanguage," _SIGPLAN Notices_, 22(5), May 1987, pp. 32-41.Munson and Khoshgoftaar, "The dimensionality of program complexity,"_Proceedings of the 11th International Conference on SoftwareEngineering_, 1989, pp. 245-253.Myers, G., "An Extension to the Cyclomatic Measure of ProgramComplexity," _SIGPLAN Notices_, 12(10), October 1977, pp. 61-64.Shepperd, "An evaluation of software product metrics," _Information andSoftware Technology_, 30(3), April 1988, pp. 177-188.Shepperd and Ince, _Journal of Systems and Software_, October (?) 1994.Bugs----1. In Metre, all typedef definitions have file scope. I have never seenanyone use block-scoped typedef definitions, so I doubt whether thiswill catch anyone. Here is an example of what you cannot do:                     typedef int a;                     main()                     {                        typedef char *a;                     }Metre declares a syntax error at the second "a" because it thinks thatit is a type specifier, like "int," and not an identifier.typedef scoping would not be that hard to implement. For example,replace the current symbol table with a stack. Mark the beginning of anew scope. Push typedef names onto the stack. Search the table from themost recently pushed names. At the end of a scope, pop all typedef namesoff up to the first-encountered scope mark.2. Another typedef bug. You will not encounter it, though, unless youuse an identifier for a member name that is the same as a visible typename. Luckily, programmers often use a naming convention that eliminatesthis possibility. For example, if member names are always in lower caseand type names are always in upper case, this bug will never occur. Asan example of the bug, Metre declares a syntax error for the memberdeclaration in this code.                     typedef int bool;                     struct {                        int bool;                     } foo;Type names have the name space as object names, so if this memberdeclaration appeared outside the struct as an object declaration, itwould be invalid syntax. However, member names have a unique name spacefor the struct within which they are declared, so this code isvalid--the two bool identifiers should occupy different name spaces.Unfortunately, Metre does not take the unique name spaces of structsinto consideration, hence the bug. To Metre, "int bool;" looks like "intint;", which would of course be invalid syntax.Only one person has reported this bug, so I will delay its fix, maybewhen I go ahead and fix the other bug by performing typedef scoping.Possible Enhancements---------------------Here are some enhancements that I have thought about implementing inMetre.Features- Calculate essential complexity. (Requires control-flow analysis,        though, which is not trivial).- Distinguish between executable and non-executable code lines in LOC        metrics.- Count commented-code lines.Infrastructure- Do not display line number for module & project messages.- Recognize C++ comments.- Recognize C++.- Optionally recognize the common "asm { ... }" construct.- Perform preprocessor file inclusion but do not accumulate metrics for        the included source.- Recognize preprocessor statements that are continued onto another        line.Trademarks----------Trademarks are the property of their respective owners.Disclaimer----------THE METRE SOURCE AND INCLUDED ACCESSORY FILES ("THE SOFTWARE") ARE NOTWARRANTED IN ANY WAY TO BE SUITABLE FOR YOUR SITUATION. YOU USE THESOFTWARE ENTIRELY AT YOUR OWN RISK.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -