Reusing Static Analysis across Different Domain-Specific Languages using Reference Attribute Grammars

Context: Domain-specific languages (DSLs) enable domain experts to specify tasks and problems themselves, while enabling static analysis to elucidate issues in the modelled domain early. Although language workbenches have simplified the design of DSLs and extensions to general purpose languages, static analyses must still be implemented manually. Inquiry: Moreover, static analyses, e.g., complexity metrics, dependency analysis, and declaration-use analysis, are usually domain-dependent and cannot be easily reused. Therefore, transferring existing static analyses to another DSL incurs a huge implementation overhead. However, this overhead is not always intrinsically necessary: in many cases, while the concepts of the DSL on which a static analysis is performed are domain-specific, the underlying algorithm employed in the analysis is actually domain-independent and thus can be reused in principle, depending on how it is specified. While current approaches either implement static analyses internally or with an external Visitor, the implementation is tied to the language's grammar and cannot be reused easily. Thus far, a commonly used approach that achieves reusable static analysis relies on the transformation into an intermediate representation upon which the analysis is performed. This, however, entails a considerable additional implementation effort. Approach: To remedy this, it has been proposed to map the necessary domain-specific concepts to the algorithm's domain-independent data structures, yet without a practical implementation and the demonstration of reuse. Thus, to make static analysis reusable again, we employ relational Reference Attribute Grammars (RAGs) by creating such a mapping to a domain-independent overlay structure using higher-order attributes. Knowledge: We describe how static analysis can be specified on analysis-specific data structures, how relational RAGs can help with the specification, and how a mapping from the domain-specific language can be performed. Furthermore, we demonstrate how a static analysis for a DSL can be externalized and reused in another general purpose language. Grounding: The approach was evaluated using the RAG system JastAdd. To illustrate reusability, we implemented two analyses with two addressed languages each: a cycle detection analysis used in a small state machine DSL and for detecting circular dependencies in Java types and packages, and an analysis of variable shadowing, applied to both Java and the Modelica modelling language. Thereby, we demonstrate the reuse of two analysis algorithms in three completely different domains. Additionally, we use the cycle detection analysis to evaluate the efficiency by comparing our external analysis to an internal reference implementation analysing all Java programs in the Qualitas Corpus and thereby are able to show that an externalized analysis incurs only minimal overhead. Importance: We make static analysis reusable, again, showing the practicality and efficiency of externalizing static analysis for both DSLs and general purpose languages using relational RAGs.

[1]  João Saraiva Component-Based Programming for Higher-Order Attribute Grammars , 2002, GPCE.

[2]  Vikram S. Adve,et al.  LLVM: a compilation framework for lifelong program analysis & transformation , 2004, International Symposium on Code Generation and Optimization, 2004. CGO 2004..

[3]  Gordon J. Pace,et al.  StaRVOOrS: A Tool for Combined Static and Runtime Verification of Java , 2015, RV.

[4]  Uwe Aßmann,et al.  Incremental Runtime-generation of Optimisation Problems using RAG-controlled Rewriting , 2016, MoDELS@Run.time.

[5]  Anjana Gosain,et al.  Static Analysis: A Survey of Techniques and Tools , 2015 .

[6]  Karl-Erik Årzén,et al.  Modeling and optimization with Optimica and JModelica.org - Languages and tools for solving large-scale dynamic optimization problems , 2010, Comput. Chem. Eng..

[7]  Sebastian Erdweg,et al.  SugarJ: library-based syntactic language extensibility , 2011, OOPSLA '11.

[8]  Donald E. Knuth,et al.  Semantics of context-free languages , 1968, Mathematical systems theory.

[9]  M. Sharir,et al.  A strong-connectivity algorithm and its applications in data flow analysis. , 2018 .

[10]  Armando Solar-Lezama,et al.  One tool, many languages: language-parametric transformation with incremental parametric syntax , 2017, ACM SIGPLAN International Conference on Systems, Programming, Languages and Applications: Software for Humanity.

[11]  Lorenzo Bettini Implementing type systems for the IDE with Xsemantics , 2016, J. Log. Algebraic Methods Program..

[12]  John Beidler,et al.  Data Structures and Algorithms , 1996, Wiley Encyclopedia of Computer Science and Engineering.

[13]  Eelco Visser,et al.  The spoofax language workbench: rules for declarative specification of languages and IDEs , 2010, OOPSLA.

[14]  Görel Hedin An Introductory Tutorial on JastAdd Attribute Grammars , 2009, GTTSE.

[15]  Eelco Visser,et al.  Evaluating and comparing language workbenches: Existing results and benchmarks for the future , 2015, Comput. Lang. Syst. Struct..

[16]  Jing Li,et al.  The Qualitas Corpus: A Curated Collection of Java Code for Empirical Studies , 2010, 2010 Asia Pacific Software Engineering Conference.

[17]  Görel Hedin,et al.  Incremental Evaluation of Reference Attribute Grammars using Dynamic Dependency Tracking , 2012 .

[18]  Anthony M. Sloane,et al.  Decorated Attribute Grammars . Attribute Evaluation Meets Strategic Programming ( Extended Technical Report ) , 2008 .

[19]  S. Doaitse Swierstra,et al.  Higher order attribute grammars , 1989, PLDI '89.

[20]  Görel Hedin,et al.  Reference Attributed Grammars , 2000, Informatica.

[21]  Bor-Yuh Evan Chang,et al.  Boogie: A Modular Reusable Verifier for Object-Oriented Programs , 2005, FMCO.

[22]  Gordon J. Pace,et al.  A Specification Language for Static and Runtime Verification of Data and Control Properties , 2015, FM.

[23]  Torbjörn Ekman,et al.  Extensible intraprocedural flow analysis at the abstract syntax tree level , 2013, Sci. Comput. Program..

[24]  Walter Cazzola,et al.  Apples and oranges: comparing top-down and bottom-up language product lines , 2016, SPLC.

[25]  Terence Parr Language Implementation Patterns: Create Your Own Domain-Specific and General Programming Languages , 2009 .

[26]  Bernhard Rumpe,et al.  MontiCore: a framework for compositional development of domain specific languages , 2010, International Journal on Software Tools for Technology Transfer.

[27]  Robert C. Seacord,et al.  Java Coding Guidelines: 75 Recommendations for Reliable and Secure Programs , 2013 .

[28]  Torbjörn Ekman,et al.  Pluggable checking and inferencing of nonnull types for Java , 2007, J. Object Technol..

[29]  Simon L. Peyton Jones,et al.  Hoopl: a modular, reusable library for dataflow analysis and transformation , 2010, Haskell.

[30]  Olivier Barais,et al.  Melange: a meta-language for modular and reusable development of DSLs , 2015, SLE.

[31]  Görel Hedin,et al.  Continuous model validation using reference attribute grammars , 2018, SLE.

[32]  Tom Mens,et al.  Language-independent detection of object-oriented design patterns , 2004, Comput. Lang. Syst. Struct..

[33]  Görel Hedin,et al.  JastAdd--an aspect-oriented compiler construction system , 2003, Sci. Comput. Program..

[34]  David Darais,et al.  Galois transformers and modular abstract interpreters: reusable metatheory for program analysis , 2014, OOPSLA.

[35]  Torbjörn Ekman,et al.  The jastadd extensible java compiler , 2007, OOPSLA.

[36]  Eric Bodden,et al.  Inter-procedural data-flow analysis with IFDS/IDE and Soot , 2012, SOAP '12.

[37]  Johannes Mey,et al.  Relational reference attribute grammars: Improving continuous model validation , 2020, J. Comput. Lang..