Easy Ada tooling with Libadalang Raphaël Amiard

Slides:



Advertisements
Similar presentations
Ruby The Gem of new programming languages. An interpreted scripting language.
Advertisements

Computer Science 210 Computer Organization Introduction to C.
Game Programming © Wiley Publishing All Rights Reserved. The L Line The Express Line to Learning L Line L.
PHP TUTORIAL. HISTORY OF PHP  PHP as it's known today is actually the successor to a product named PHP/FI.  Created in 1994 by Rasmus Lerdorf, the very.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Python – Part 1 Python Programming Language 1. What is Python? High-level language Interpreted – easy to test and use interactively Object-oriented Open-source.
Oracle Data Integrator Procedures, Advanced Workflows.
Joe Hummel, the compiler is at your service Chicago Code Camp 2014.
Python – May 11 Briefing Course overview Introduction to the language Lab.
AdaSlicer: An Ada Program Slicer Ricky E. Sward Department of Computer Science USAF Academy, CO A.T. Chamillard Computer Science.
Introducing Python CS 4320, SPRING Lexical Structure Two aspects of Python syntax may be challenging to Java programmers Indenting ◦Indenting is.
Chapter 1 Introduction. Chapter 1 - Introduction 2 The Goal of Chapter 1 Introduce different forms of language translators Give a high level overview.
CS105 Computer Programming PYTHON (based on CS 11 Python track: lecture 1, CALTECH)
Slide: 1 Copyright © AdaCore Your First Ada Program Presented by Quentin Ochem University.adacore.com.
Scion Macros How to make macros for Scion The Fast and Easy Guide.
1 PHP Intro PHP Introduction After this lecture, you should be able to: Know the fundamental concepts of Web Scripting Languages in general, PHP in particular.
BY: JAKE TENBERG & CHELSEA SHIPP PROJECT REVIEW: JGIBBERISH.
FUNCTIONAL PROGRAMING AT WORK - HASKELL AND DOMAIN SPECIFIC LANGUAGES Dr. John Peterson Western State Colorado University.
CSE 4939 Alex Riordan Brian Pruitt-Goddard. Design an interactive source control application that works between an android phone and a project located.
Dr. Abdullah Almutairi Spring PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used,
Programming Languages Concepts Chapter 1: Programming Languages Concepts Lecture # 4.
Dr. Hussien Sharaf Dr Emad Nabil. Dr. Hussien M. Sharaf 2 position := initial + rate * Lexical analyzer 2. Syntax analyzer id 1 := id 2 + id 3 *
GPS The GNAT Programming Studio GPS The GNAT Programming Studio Presentation cover page EU Vincent Celier FOSDEM 8-9 February 2009 Senior.
AdaControl A free ASIS based tool J-P. Rosen Adalog.
Chapter 1. Introduction.
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
PHP using MySQL Database for Web Development (part II)
Functional Programming
Lesson 06: Functions Class Participation: Class Chat:
Development Environment
Computer Science 210 Computer Organization
PRINCIPLES OF COMPILER DESIGN
Introduction to Compiler Construction
Python: Experiencing IDLE, writing simple programs
Introduction to Python
Compiler Construction (CS-636)
Data Virtualization Tutorial… OAuth Example using Google Sheets
Overview of Compilation The Compiler BACK End
Topic: Functions – Part 2
Variables, Expressions, and IO
CS 536 / Fall 2017 Introduction to programming languages and compilers
Intro to PHP & Variables
Introduction to Compiler Construction
Computer Science 210 Computer Organization
What Is a Program? A program is like an algorithm, but describes a process that is ready or can be made ready to run on a real computer Retrieved from:
CodePeer Update Arnaud Charlet CodePeer Update Arnaud Charlet
Introduction to Python
Easy Ada tooling with Libadalang Raphaël Amiard.
GNAT Pro Update Arnaud Charlet GNAT Pro Update Arnaud Charlet
QGen and TQL-1 Qualification
Python integration in GPS
CodePeer Update Arnaud Charlet CodePeer Update Arnaud Charlet
GNAT Pro Update Arnaud Charlet GNAT Pro Update Arnaud Charlet
Lecture 15 (Notes by P. N. Hilfinger and R. Bodik)
Overview of Compilation The Compiler BACK End
PHP.
Lesson 06: Functions Class Chat: Attendance: Participation
API DOCUMENTATION Swetha Mohandas Microsoft Connect 2016
Lecture 2 Python Programming & Data Types
Fundamentals of Python: First Programs
Intro to PHP.
Introduction to Compiler Construction
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Chapter 1: Programming Basics, Python History and Program Components
PHP an introduction.
General Computer Science for Engineers CISC 106 Lecture 03
Update & Roadmap. Update & Roadmap Established Ada market “Helping to preserve investments done with Ada” “Provide new cost-effective ways to develop.
L L Line CSE 420 Computer Games Lecture #3 Introduction to Python.
Python Basics. Topics Features How does Python work Basic Features I/O in Python Operators Control Statements Function/Scope of variables OOP Concepts.
SEEM 4540 Tutorial 4 Basic PHP based on w3Schools
Presentation transcript:

Easy Ada tooling with Libadalang Raphaël Amiard 2018-10-04

Previous episodes - What is libadalang A library that allows users to query/alter data about Ada sources Both low & high level APIs: What is the type of this expression? How many references to this variable? Give me the source location of this token Rename this entity Multi-language: Easy binding generation to other languages/ecosystems Today: Python, Ada, C Easy scripting: Be able to create a prototype quickly & interactively

WRT. ASIS Implementation benefits API benefits Incremental Error recovery Syntax only Semantic tolerance Adapted for long running apps API benefits Higher level API Bindings to other languages Tree rewriting Global XREFs

API Part 1: Tokens Code Outputs -- main.adb procedure Main is null; Token: <Token Procedure u'procedure' at 1:1-1:10> Token: <Token Identifier u'Main' at 1:11-1:15> Token: <Token Is u'is' at 1:16-1:18> Token: <Token Null u'null' at 1:19-1:23> Token: <Token Semicolon u';' at 1:23-1:24> ctx = lal.AnalysisContext() unit = ctx.get_from_file('main.adb') for token in unit.root.tokens: print 'Token: {}'.format(token)

API Part 2: Syntax Code Outputs -- main.adb procedure Main is A : Integer := 12; B, C : Integer := 15; begin A := B + C; end Main; 2:4-2:22 A : Integer := 12; 3:4-3:25 B, C : Integer := 15; for o in unit.root.findall(lal.ObjectDecl): print o.sloc_range, o.text

API Part 3: Semantic Code Outputs with Ada.Text_IO; use Ada.Text_IO; procedure Main is function Double (I : Integer) return Integer is (I * 2); function Double (I : Float) return Float is (I * 2.0); begin Put_Line (Integer'Image (Double (12))); end Main; function Double (I : Integer) return Integer is (I * 2); double_call = unit.root.find( lambda n: n.is_a(lal.CallExpr) and n.f_name.text == 'Double' ) print double_call.f_name.p_referenced_decl.text

API Part 4: Tree rewriting (WIP) Code Outputs procedure Main is begin Put_Line ("Hello world"); end Main; procedure Main is begin Put_Line ("Bye world"); end Main; call = unit.root.find(lal.CallExpr) # Find the call diff = ctx.start_rewriting() # Start a rewriting # Get the param of the call param_diff = diff.get_node(call.f_suffix[0]) # Replace the expression of the parameter with a new # node param_diff.f_expr = lal.rewriting.StringLiteral( '"Bye world"' ) diff.apply()

An example checker import sys import libadalang as lal def check_ident(ident): if not ident.text[0].isupper(): print '{}:{}: variable name "{}" should be capitalized'.format( ident.unit.filename, ident.sloc_range.start, ident.text ) ctx = lal.AnalysisContext() for filename in sys.argv[1:]: u = ctx.get_from_file(filename) for d in u.diagnostics: print '{}:{}'.format(filename, d) if u.root: for decl in u.root.findall(lal.ObjectDecl): for ident in decl.f_ids: check_ident(ident)

Demo HTML Syntax highlighter + Xrefs

Syntax based static analyzers def has_same_operands(binop): def same_tokens(left, right): return len(left) == len(right) and all( le.is_equivalent(ri) for le, ri in zip(left, right) ) return same_tokens(list(binop.f_left.tokens), list(binop.f_right.tokens)) def interesting_oper(op): return not op.is_a(lal.OpMult, lal.OpPlus, lal.OpDoubleDot, lal.OpPow, lal.OpConcat)) for b in unit.root.findall(lal.BinOp): if interesting_oper(b.f_op) and has_same_operands(b): print 'Same operands for {} in {}'.format( b, source_file ) Those 20 lines of code found: 1 bug in GNAT 3 bugs in CodePeer 1 bug in GPS despite extensive testing and static analysis. More complex checkers based on the same approach being integrated into Codepeer.

Semantic based static analyzers with Ada.Text_IO; use Ada.Text_IO; procedure Main is Input : File_Type; begin Open (File => Input, Mode => In_File, Name => "input.txt"); while not End_Of_File (Input) loop declare Line : String := Get_Line (Input); -- WARNING: File might be closed begin Put_Line (Line); Close (Input); -- WARNING: File might be closed end; end loop; end Main; Very simple and targeted abstract interpretation DSL to specify new checkers Work in progress! Some of the work is being integrated into Codepeer https://github.com/AdaCore/lal-checkers

Already used in&out of AdaCore This year GNATpp Up to 10x time faster Error tolerance --syntax-only mode GNATstub Incremental mode GNATmetric New metrics Next year IDEs Syntax highlighting Xrefs Completion Microsoft LSP: Support for many editors Clients using it already: Code instrumentation Automatic refactorings Generation of serializers/deserializers

What do you want to build with Libadalang ? :) Conclusion Sources are on GitHub Come open issues and create pull requests! First stable version in upcoming release API will be incrementally improved after that We’ll try to avoid breakage as much as possible But allow ourselves to make it better for the future :) What do you want to build with Libadalang ? :)