请输入您要查询的百科知识:

 

词条 SrcML
释义

  1. srcML Toolkit

  2. srcML Format

  3. Single File Conversion

  4. Project Conversion

  5. Program Transformation with srcML

  6. Fact Extraction with srcML

  7. Source Code Difference Analysis with srcML

  8. Examples

  9. See also

  10. References

  11. External links

{{DISPLAYTITLE:srcML}}{{Infobox software
| name = srcML
| logo =
| developer = Michael L. Collard Jonathan I. Maletic
| released =
| latest_release_version =
| latest_release_date =
| operating_system =
| genre =
| programming_language = c c++ java
| status = Maintained
| license = GPL
| website = {{URL|http://www.srcml.org/}}
}}srcML (source M L) is a document-oriented XML representation of source code. It was created in a collaborative effort between Michael L. Collard and Jonathan I. Maletic. The abbreviation, srcML, is short for Source Markup Language. srcML wraps source code (text) with information from the Abstract Syntax Tree or AST (tags) into a single XML document. All original text is preserved so that the original source code document can be recreated from the srcML markup. The only exception is the possibility of newline normalization.[1]

The purpose of srcML is to provide full access to the source code at the lexical, documentary, structural, and syntactic levels. The format also provides easy support for fact-extraction and transformation. It is supported by the srcML toolkit maintained on the SDML website and has been shown to perform scalable, lightweight fact-extraction and transformation.

srcML Toolkit

The srcML toolkit consists of the command-line programs src2srcml, which translates from source code to srcML, and srcml2src, which translates from srcML to source code. srcml2src also supports direct queries and transformations of srcML archives using tools like XPath, XSLT, and RELAXNG. They are actively maintained, and currently support C, C++, and Java.

srcML Format

The srcML format consists of all text from the original source code file plus XML tags. Specifically, the text is wrapped with srcML elements that indicate the syntactic structure of the code. In short, this explicitly identifies all syntactic structures in the code.[2]

The tags used in srcML are listed out below along with what category they fall within.

Category srcML Elements
File/Project unit
Statement asm, block, break, case, comment, condition, constraint, continue, decl, decl_stmt, default, do else empty_stmt, enum, expr, expr_stmt, extern, for, goto, if, incr, index, init, label, macro, name, namespace, range, requires, switch, template, then, type, typedef, using, while
Function/Method argument, argument_list, call, function, function_decl, param, parameter_list, return, specifier
Class class, class_decl, constructor, constructor_decl, destructor, destructor_decl, friend, member_list, private, protected, public, super
Struct and Union struct, struct_decl, union, union_decl
Exception catch, throw, throws, try
C-Preprocessor cpp:define, cpp:directive, cpp:elif, cpp:endif, cpp:error, cpp:file, cpp:if, cpp:ifdef, cpp:ifndef, cpp:include, cpp:line, cpp:pragma, cpp:undef
K&R C krparam, krparameter_list
Java extends, finally, implements, import, package
Extra Markup lit:literal, type:modifier, op:operator
Debug marker, mode, parse
Misc escape

srcML uses XML namespaces. Below is a list of the prefix used to denote each namespace, and the namespaces themselves.

Prefix Namespace
src http://www.sdml.info/srcML/src
cpp http://www.sdml.info/srcML/cpp
pos http://www.sdml.info/srcML/position
op http://www.sdml.info/srcML/operator
lit http://www.sdml.info/srcML/literal
type http://www.sdml.info/srcML/modifier
err http://www.sdml.info/srcML/srcerr

Note: for a srcML archive, the entire project will be contained within a single root unit element, and each individual file will be contained as a unit element within the root unit element.

Single File Conversion

The following shows how src2srcml and srcml2src can be used on single files.

The following example converts the C++ file main.cpp to the srcML file main.cpp.xml:

{{code|lang=shell|src2srcml main.cpp -o main.cpp.xml}}

The following command will extract the source code from the file main.cpp.xml and place it into the C++ file main.cpp:

{{code|lang=shell|srcml2src main.cpp.xml -o main.cpp}}

Project Conversion

The following shows how src2srcml and srcml2src can be used with an entire project:

The following example converts the project 'project' to the srcML file project.xml

{{code|lang=shell|src2srcml project -o project.xml}}

The following command will extract the source code files from the file project.xml and place it into the directory project:

{{code|lang=shell|srcml2src—to-dir project project.xml}}

Program Transformation with srcML

srcML allows the use of most if not all current XML APIs and tools to write transformations. It also allows for the use of XSLT directly using the argument—xslt={name}.xls on the srcml2src command. Using srcML's markup with XSLT allows the user to apply Program Transformations on an XML-like structure(srcML) to obtain transformed xml which can then be written back its source code representation using the srcml2src tool. The application of srcML to program transformation is explained, in detail, by Collard et al.[1]

The following command will run the XSLT program program.xsl on the srcML archive project.xml

{{code|lang=shell|srcml2src—xslt program.xsl project.xml}}

Fact Extraction with srcML

In it simplest form, Fact Extraction using srcML leverages XPath in order to address parts of the srcML document and pull information about various entities or characteristics of the source code. Of course, it is not limited to this. Any standard XML API may be used. The application of srcML to fact extraction is explained, in detail, by Kagdi et al.[4]

cpp:directive, cpp:file, cpp:include, cpp:define, cpp:undef, cpp:line, cpp:if, cpp:ifdef, cpp:ifndef, cpp:else, cpp:elif, cpp:endif, cpp:then, cpp:pragma, cpp:errorliteral, operator, modifier

An example to create a srcML archive from an entire software project.

The following command runs the XPath path on a srcML archive project.xml

{{code|lang=shell|srcml2src—xpath "xpath" project.xml}}

Work is being done on providing convenient extension functions.

Source Code Difference Analysis with srcML

srcML brings a lot of advantages to doing difference analysis on source code. One of these advantages is the ability to query for differences between specific sections of a codebase as well as across versions of the same codebase. The application of srcML for difference Analysis is explained, in detail, by Maletic et al.[5]

Examples

As an example of how srcML is used, here is an XPath expression that could be used to find all classes in a source document:

//src:class

Another example might be finding all comments within functions:

/src:function//src:comment

Due to the fact that srcML is based on xml, all XML tools can be used with srcML, which provides rich functionality.

See also

  • DMS Software Reengineering Toolkit
  • Program Transformation
  • TXL programming language

References

[1][2][3][4][5][6][7]
1. ^{{cite web|url= |title= Lightweight Transformation and Fact Extraction with the srcML Toolkit |publisher=Proceedings of the 11th IEEE International Working Conference on Source Code Analysis and Manipulation (SCAM'11) |author=Collard, M.L., Decker, M., Maletic, J. I.,|pages=10 pages |year=2011}}
2. ^{{cite web|url=|title=A Lightweight Transformational Approach to Support Large Scale Adaptive Changes |publisher=Proceedings of the IEEE 26th IEEE International Conference on Software Maintenance (ICSM'10) |author=Collard, M.L, Maletic, J. I., Robinson, B.P.,|pages=10 pages |year=2010}}
3. ^{{cite web|url= |title= An XML-Based Lightweight C++ Fact Extractor |publisher= Proceedings of the 11th IEEE International Workshop on Program Comprehension (IWPC'03) |author=Collard, Michael L., Kagdi, Huzefa, Maletic, Jonathan I.,|pages=10 pages |year=2003}}
4. ^{{cite web|url= |title= Supporting Source Code Difference Analysis |publisher=Proceedings of the IEEE International Conference on Software Maintenance (ICSM'04) |author=Maletic, Jonathan I., Collard, Michael L.,|pages=10 pages |year=2004}}
5. ^{{cite web|url= |title= Leveraging XML Technologies in Developing Program Analysis Tools |publisher=Proceedings of the 4th International Workshop on Adoption-Centric Software Engineering (ACSE'04) |author=Maletic, Jonathan I., Collard, Michael L., Kagdi, Huzefa,|pages=6 pages |year=2004}}
6. ^{{cite web|url= |title= Supporting Document and Data Views of Source Code |publisher= Proceedings of the 2nd ACM Symposium on Document Engineering (DocEng'02) |author=Collard, Michael L., Maletic, Jonathan I., Marcus, Andrian,|pages=8 pages |year=2002}}
7. ^{{cite web|url= |title= Source Code Files as Structured Documents |publisher= Proceedings of the 10th IEEE International Workshop on Program Comprehension (IWPC'02) |author=Maletic, Jonathan I., Collard, Michael L., Marcus, Andrian,|pages=4 pages |year=2002}}

External links

  • srcML website

3 : XML markup languages|Program transformation|Software maintenance

随便看

 

开放百科全书收录14589846条英语、德语、日语等多语种百科知识,基本涵盖了大多数领域的百科知识,是一部内容自由、开放的电子版国际百科全书。

 

Copyright © 2023 OENC.NET All Rights Reserved
京ICP备2021023879号 更新时间:2024/11/11 11:39:49