Designing Language-Agnostic Code Transformation Engines - TEL - Thèses en ligne Accéder directement au contenu
Thèse Année : 2019

Designing Language-Agnostic Code Transformation Engines

Construction de moteurs de transformation de code automatique agnostiques du langage

Résumé

Code transformations are needed in various cases: refactorings, migra- tions, code specialization, and so on. Code transformation engines work by finding a pattern in the source code and rewriting its occurrences according to the transformation. The transformation either rewrites the occurrences, elements of the intermediate representation (IR) of the language, into new elements or di- rectly rewrites the source code. In this work, we focused on source rewriting since it offers more flexibility through arbitrary transformations, especially for migrations and specializations. Matching patterns come in two different flavours, explicit and syntactic. The former requires the user to know the IR of the language, a heavy knowledge burden. The latter only relies on the syntax of the matched language and not its IR, but requires significantly more work to implement the language back-ends. Language experts tend to know the IR and the syntax of a language, while other users know only the syntax. We propose a pattern matching engine offering a hybrid pattern representation: both explicit and syntactic matching are available in the same pattern. The engine always defaults to syntactic as it is the lowest barrier to entry for patterns. To counterbalance the implementation cost of language back-ends for syntactic pattern matching, we take a generative approach. We combine the hybrid pattern matching engine with a parser generator. The parser generator generates generalized LR (GLR) parsers capable of not only parsing the source but also the hybrid pattern. The back-end implementer only needs to add one line to the grammar of the language to activate the pattern matching engine. This approach to pattern matching requires GLR parsers capable of forking and keeping track of each individual fork. These GLR implementations suffer the more forking is done to handle ambiguities and patterns require even more forking. To prevent an explosion, our Fibered-GLR parsers merge more often and allow for classic disambiguation during the parse through side-effects.
Les transformations automatiques de code apparaissent dans diverses situations, les refactorings, les migrations inter-langages ou encore la sp ́ecialisation de code. Les mo- teurs supportant ces transformations cherchent dans le code source les occurrences de motifs sp ́ecifi ́es par l’utilisateur, puis les r ́e ́ecrivent grˆace a` une transformation. Cette transformation peut soit modifier les occurrences elles-mˆemes, des ́el ́ements de la repr ́esentation interm ́ediaire (IR) du langage, en nouveaux ́el ́ements ou r ́e ́ecrire leur code source. Nous nous concentrons sur la r ́e ́ecriture de code source qui offre une meilleure flexibilit ́e grˆace `a des transformations arbitraires particuli`erement utiles `a la migration et `a la sp ́ecialisation de code. Les motifs sont divis ́es en deux cat ́egories : les motifs explicites et syntaxiques. Les premiers de- mandent que l’utilisateur connaisse l’IR du langage, un effort d’apprentissage non n ́egligeable. Les sec- onds demandent seulement de connaˆıtre la syntaxe du langage et non son IR, mais requi`erent un effort d’impl ́ementation suppl ́ementaire pour les back-ends de langage du moteur. Tandis que les experts en langage connaissent l’IR et la syntaxe du langage, les autres utilisateurs connaissent seulement la syntaxe. Nous proposons un moteur de reconnaissance de motifs offrant une repr ́esentation hybride des motifs : les motifs peuvent ˆetre `a la fois explicites et syntaxiques. Par d ́efaut, le moteur se rabat sur un fonctionnement syntaxique, car la barri`ere `a l’entr ́ee est plus basse. Pour palier au coup d’impl ́ementation des back-ends de langage pour la reconnaissance syntaxique, nous prenons une approche g ́en ́erative. Le moteur de reconnaissance hybride est coupl ́e avec un moteur de g ́en ́eration d’analyseurs syntaxiques. Ce dernier g ́en`ere des analyseurs syntaxiques LR g ́en ́eralis ́es (GLR) capables d’analyser non seulement le code source `a r ́e ́ecrire, mais ́egalement le motif `a reconnaˆıtre. L’impl ́ementeur du back-end de langage n’a alors qu’`a ajouter une ligne `a la grammaire pour avoir acc`es au moteur de reconnaissance de motifs pour ce langage. L’approche est bas ́ee sur des analyseurs syntaxiques GLR pouvant se dupliquer et traquant ses sous- analyseurs. Ces impl ́ementations particuli`eres de GLR ne passent pas `a l’ ́echelle quand trop de duplica- tions sont n ́ecessaires pour g ́erer les ambigu ̈ıt ́es et notre approche ajoute de la duplication. Pour ́eviter une explosion du temps d’ex ́ecution, nos analyseurs syntaxiques FGLR fusionnent plus r ́eguli`erement et permettent une d ́esambigu ̈ısation `a la vol ́ee pendant l’analyse via des effets de bord.
Fichier principal
Vignette du fichier
50376-2019-Lecerf.pdf (1.07 Mo) Télécharger le fichier
Origine : Fichiers produits par l'(les) auteur(s)

Dates et versions

tel-03356307 , version 1 (27-09-2021)

Identifiants

  • HAL Id : tel-03356307 , version 1

Citer

Jason Lecerf. Designing Language-Agnostic Code Transformation Engines. Programming Languages [cs.PL]. Université de Lille, 2019. English. ⟨NNT : ⟩. ⟨tel-03356307⟩
86 Consultations
351 Téléchargements

Partager

Gmail Facebook X LinkedIn More