Title: Automatic Coding Rule Conformance Checking Using Logic Programs
ArXiv ID: 0711.0344
Date: 2007-11-06
Authors: 정보 없음 (논문에 저자 정보가 제공되지 않음)
📝 Abstract
Some approaches to increasing program reliability involve a disciplined use of programming languages so as to minimise the hazards introduced by error-prone features. This is realised by writing code that is constrained to a subset of the a priori admissible programs, and that, moreover, may use only a subset of the language. These subsets are determined by a collection of so-called coding rules.
💡 Deep Analysis
📄 Full Content
Some approaches to increasing program reliability involve a disciplined use of programming languages so as to minimise the hazards introduced by error-prone features. This is realised by writing code that is constrained to a subset of the a priori admissible programs, and that, moreover, may use only a subset of the language. These subsets are determined by a collection of so-called coding rules. Standard coding rule sets exist that target different languages (e.g. MISRA-C for the C language or HICPP for C++) and application domains. Some organisations do set up their own coding rule sets.
A major drawback of actual coding rule sets is that they are written in natural language, which bears ambiguity and undermines any effort to enforce them automatically. This work aims at defining a framework to formalise coding rules and check for conformity with them, using logic programming. It is part of the Global GCC project (http://www.ggcc.info/)
, an ITEA funded EU programme intended to enrich the GNU Compiler Collection with advanced project-wide analysis capacities.
The overwhelming diversity of rules (they range from being trivially enforceable to expressing non-computable properties) has obliged us to focus first on a particular class that we have termed structural rules: those which deal with static entities in the code (classes, member functions, etc.) and their properties and relationships (inheritance, overriding, etc.) We have identified a significant number of rules of this kind that can be statically checked, being at the same time more interesting than those purely syntactic.
Rules are formalised using first order logic: relationships between program entities are encoded as facts (thus giving an abstract description of the program) and a formula is generated for every coding rule. When these, together, are inconsistent, the program violates the coding rule. We automate this process by generating a program-dependent set of Prolog facts and program-independent predicates which describe rule violations. For example, a violation of rule 3.3.15 of HICPP, which reads “ensure base classes common to more than one derived class are virtual “, is codified as: Successful queries to this predicate pinpoint infringements of the rule and the answer substitutions identify a source of the violation.
As rule-writers may not be proficient in Prolog, we provide a user-friendly domainspecific language (DSL) that also increases expressiveness by, e.g., allowing quantification over some specific domains or providing facilities for defining closures. At the DSL core there is a set of predefined predicates describing (structural) program properties, such as those used in the above rule, that are gathered during the compilation process.