From 6775b9edf9d146414222a34209f3e1b90878f754 Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Wed, 2 May 2012 13:28:14 +0200 Subject: [PATCH] other slides about XTS --- .../listings/Makefile | 9 +- .../listings/ts.lang | 3 +- .../listings/xts-attributeref.ts | 1 + .../listings/xts-attributeref.ts.tex | 5 + .../listings/xts-characteristics.ts | 6 + .../listings/xts-characteristics.ts.tex | 10 ++ .../listings/xts-literals.ts | 4 + .../listings/xts-literals.ts.tex | 8 + .../listings/xts-settingup.ts | 3 + .../listings/xts-settingup.ts.tex | 8 + .../listings/xts-types.ts | 3 + .../listings/xts-types.ts.tex | 7 + .../listings/xts-types2.ts | 10 ++ .../listings/xts-types2.ts.tex | 14 ++ .../listings/xts-types3.ts | 12 ++ .../listings/xts-types3.ts.tex | 16 ++ .../typesys/GuiDlsTypesystemGenerated.java | 23 +++ EclipseDayFlorence-presentation/xts.tex | 138 +++++++++++++----- tsarticle/6-xts.tex | 2 +- tsarticle/lstlang0.sty | 2 +- 20 files changed, 247 insertions(+), 37 deletions(-) create mode 100644 EclipseDayFlorence-presentation/listings/xts-attributeref.ts create mode 100644 EclipseDayFlorence-presentation/listings/xts-attributeref.ts.tex create mode 100644 EclipseDayFlorence-presentation/listings/xts-characteristics.ts create mode 100644 EclipseDayFlorence-presentation/listings/xts-characteristics.ts.tex create mode 100644 EclipseDayFlorence-presentation/listings/xts-literals.ts create mode 100644 EclipseDayFlorence-presentation/listings/xts-literals.ts.tex create mode 100644 EclipseDayFlorence-presentation/listings/xts-settingup.ts create mode 100644 EclipseDayFlorence-presentation/listings/xts-settingup.ts.tex create mode 100644 EclipseDayFlorence-presentation/listings/xts-types.ts create mode 100644 EclipseDayFlorence-presentation/listings/xts-types.ts.tex create mode 100644 EclipseDayFlorence-presentation/listings/xts-types2.ts create mode 100644 EclipseDayFlorence-presentation/listings/xts-types2.ts.tex create mode 100644 EclipseDayFlorence-presentation/listings/xts-types3.ts create mode 100644 EclipseDayFlorence-presentation/listings/xts-types3.ts.tex create mode 100644 EclipseDayFlorence-presentation/src-gen/org/typesys/xts/guidsl/typesys/GuiDlsTypesystemGenerated.java diff --git a/EclipseDayFlorence-presentation/listings/Makefile b/EclipseDayFlorence-presentation/listings/Makefile index 1b2b077..0dbfd6c 100644 --- a/EclipseDayFlorence-presentation/listings/Makefile +++ b/EclipseDayFlorence-presentation/listings/Makefile @@ -5,7 +5,14 @@ TOPROCESS = SimpleRules.xsemantics SimpleRules2.xsemantics \ intro.gui \ xbase-gettype.xtend \ xts-typecoerce.java \ - xts-plus.ts + xts-plus.ts \ + xts-settingup.ts \ + xts-literals.ts \ + xts-types.ts \ + xts-types2.ts \ + xts-types3.ts \ + xts-attributeref.ts \ + xts-characteristics.ts # plain-typeconf.xtend \ # plain-gettype.xtend diff --git a/EclipseDayFlorence-presentation/listings/ts.lang b/EclipseDayFlorence-presentation/listings/ts.lang index eb69f90..f5471bd 100644 --- a/EclipseDayFlorence-presentation/listings/ts.lang +++ b/EclipseDayFlorence-presentation/listings/ts.lang @@ -1,4 +1,5 @@ include "java.lang" keyword = "subtype|base|characteristic|common", - "ensureType|ensureCompatibility|char|as|typeof|def|override|dispatch" + "ensureType|ensureCompatibility|char|as|typeof|def|override|dispatch", + "typesystem|ecore|file|language|package|section|javacode|clone|feature|ancestor" diff --git a/EclipseDayFlorence-presentation/listings/xts-attributeref.ts b/EclipseDayFlorence-presentation/listings/xts-attributeref.ts new file mode 100644 index 0000000..e699242 --- /dev/null +++ b/EclipseDayFlorence-presentation/listings/xts-attributeref.ts @@ -0,0 +1 @@ +typeof AttributeRef -> feature attr \ No newline at end of file diff --git a/EclipseDayFlorence-presentation/listings/xts-attributeref.ts.tex b/EclipseDayFlorence-presentation/listings/xts-attributeref.ts.tex new file mode 100644 index 0000000..9ef976e --- /dev/null +++ b/EclipseDayFlorence-presentation/listings/xts-attributeref.ts.tex @@ -0,0 +1,5 @@ +% Generator: GNU source-highlight, by Lorenzo Bettini, http://www.gnu.org/software/src-highlite +\begin{tabular}[t]{l} +\noindent +\mbox{}\textbf{\textcolor{Plum}{typeof}}\ AttributeRef\ -$>$\ \textbf{\textcolor{Plum}{feature}}\ attr +\end{tabular} diff --git a/EclipseDayFlorence-presentation/listings/xts-characteristics.ts b/EclipseDayFlorence-presentation/listings/xts-characteristics.ts new file mode 100644 index 0000000..1c87e83 --- /dev/null +++ b/EclipseDayFlorence-presentation/listings/xts-characteristics.ts @@ -0,0 +1,6 @@ +characteristic COMPARABLE { + IntType, FloatType, BooleanType, StringType +} +characteristic NUMERIC { + IntType, FloatType +} \ No newline at end of file diff --git a/EclipseDayFlorence-presentation/listings/xts-characteristics.ts.tex b/EclipseDayFlorence-presentation/listings/xts-characteristics.ts.tex new file mode 100644 index 0000000..0e56254 --- /dev/null +++ b/EclipseDayFlorence-presentation/listings/xts-characteristics.ts.tex @@ -0,0 +1,10 @@ +% Generator: GNU source-highlight, by Lorenzo Bettini, http://www.gnu.org/software/src-highlite +\begin{tabular}[t]{l} +\noindent +\mbox{}\textbf{\textcolor{Plum}{characteristic}}\ COMPARABLE\ \{ \\ +\mbox{}\ \ \ \ IntType,\ FloatType,\ BooleanType,\ StringType \\ +\mbox{}\}\ \ \\ +\mbox{}\textbf{\textcolor{Plum}{characteristic}}\ NUMERIC\ \{ \\ +\mbox{}\ \ \ \ IntType,\ FloatType \\ +\mbox{}\}\ +\end{tabular} diff --git a/EclipseDayFlorence-presentation/listings/xts-literals.ts b/EclipseDayFlorence-presentation/listings/xts-literals.ts new file mode 100644 index 0000000..d38a5ce --- /dev/null +++ b/EclipseDayFlorence-presentation/listings/xts-literals.ts @@ -0,0 +1,4 @@ +section "Literals" + typeof StringLiteral -> StringType + typeof BooleanLiteral -> BooleanType + typeof NumberLiteral -> javacode \ No newline at end of file diff --git a/EclipseDayFlorence-presentation/listings/xts-literals.ts.tex b/EclipseDayFlorence-presentation/listings/xts-literals.ts.tex new file mode 100644 index 0000000..ecc28c6 --- /dev/null +++ b/EclipseDayFlorence-presentation/listings/xts-literals.ts.tex @@ -0,0 +1,8 @@ +% Generator: GNU source-highlight, by Lorenzo Bettini, http://www.gnu.org/software/src-highlite +\begin{tabular}[t]{l} +\noindent +\mbox{}\textbf{\textcolor{Plum}{section}}\ \textcolor{RoyalBlue}{"{}Literals"{}} \\ +\mbox{}\ \ \ \ \ \ \textbf{\textcolor{Plum}{typeof}}\ StringLiteral\ -$>$\ StringType \\ +\mbox{}\ \ \ \ \ \ \textbf{\textcolor{Plum}{typeof}}\ BooleanLiteral\ -$>$\ BooleanType \\ +\mbox{}\ \ \ \ \ \ \textbf{\textcolor{Plum}{typeof}}\ NumberLiteral\ -$>$\ \textbf{\textcolor{Plum}{javacode}} +\end{tabular} diff --git a/EclipseDayFlorence-presentation/listings/xts-settingup.ts b/EclipseDayFlorence-presentation/listings/xts-settingup.ts new file mode 100644 index 0000000..1334fcf --- /dev/null +++ b/EclipseDayFlorence-presentation/listings/xts-settingup.ts @@ -0,0 +1,3 @@ +typesystem org.typesys.xts.guidsl.typesys.GuiDlsTypesystem + ecore file "platform:/.../GuiDsl.ecore" + language package org.typesys.xts.guidsl.guiDsl.GuiDslPackage diff --git a/EclipseDayFlorence-presentation/listings/xts-settingup.ts.tex b/EclipseDayFlorence-presentation/listings/xts-settingup.ts.tex new file mode 100644 index 0000000..72adcef --- /dev/null +++ b/EclipseDayFlorence-presentation/listings/xts-settingup.ts.tex @@ -0,0 +1,8 @@ +% Generator: GNU source-highlight, by Lorenzo Bettini, http://www.gnu.org/software/src-highlite +\begin{tabular}[t]{l} +\noindent +\mbox{}\textbf{\textcolor{Plum}{typesystem}}\ org.typesys.xts.guidsl.typesys.GuiDlsTypesystem\ \\ +\mbox{}\ \ \ \ \textbf{\textcolor{Plum}{ecore}}\ \textbf{\textcolor{Plum}{file}}\ \textcolor{RoyalBlue}{"{}platform:/.../GuiDsl.ecore"{}} \\ +\mbox{}\ \ \ \ \textbf{\textcolor{Plum}{language}}\ \textbf{\textcolor{Plum}{package}}\ org.typesys.xts.guidsl.guiDsl.GuiDslPackage\ \\ +\mbox{} +\end{tabular} diff --git a/EclipseDayFlorence-presentation/listings/xts-types.ts b/EclipseDayFlorence-presentation/listings/xts-types.ts new file mode 100644 index 0000000..6f3266b --- /dev/null +++ b/EclipseDayFlorence-presentation/listings/xts-types.ts @@ -0,0 +1,3 @@ +section "Types" + typeof Type+ -> clone + subtype IntType base FloatType \ No newline at end of file diff --git a/EclipseDayFlorence-presentation/listings/xts-types.ts.tex b/EclipseDayFlorence-presentation/listings/xts-types.ts.tex new file mode 100644 index 0000000..3259513 --- /dev/null +++ b/EclipseDayFlorence-presentation/listings/xts-types.ts.tex @@ -0,0 +1,7 @@ +% Generator: GNU source-highlight, by Lorenzo Bettini, http://www.gnu.org/software/src-highlite +\begin{tabular}[t]{l} +\noindent +\mbox{}\textbf{\textcolor{Plum}{section}}\ \textcolor{RoyalBlue}{"{}Types"{}} \\ +\mbox{}\ \ \ \ \textbf{\textcolor{Plum}{typeof}}\ Type+\ -$>$\ \textbf{\textcolor{Plum}{clone}} \\ +\mbox{}\ \ \ \ \textbf{\textcolor{Plum}{subtype}}\ IntType\ \textbf{\textcolor{Plum}{base}}\ FloatType +\end{tabular} diff --git a/EclipseDayFlorence-presentation/listings/xts-types2.ts b/EclipseDayFlorence-presentation/listings/xts-types2.ts new file mode 100644 index 0000000..a42afdb --- /dev/null +++ b/EclipseDayFlorence-presentation/listings/xts-types2.ts @@ -0,0 +1,10 @@ +typeof Comparison -> BooleanType { + ensureType left :<=: char(COMPARABLE) + ensureType right :<=: char(COMPARABLE) + ensureCompatibility left :<=>: right +} +typeof Minus -> common left right { + ensureType left :<=: char(NUMERIC) + ensureType right :<=: char(NUMERIC) + ensureCompatibility left :<=>: right +} \ No newline at end of file diff --git a/EclipseDayFlorence-presentation/listings/xts-types2.ts.tex b/EclipseDayFlorence-presentation/listings/xts-types2.ts.tex new file mode 100644 index 0000000..dc6ef50 --- /dev/null +++ b/EclipseDayFlorence-presentation/listings/xts-types2.ts.tex @@ -0,0 +1,14 @@ +% Generator: GNU source-highlight, by Lorenzo Bettini, http://www.gnu.org/software/src-highlite +\begin{tabular}[t]{l} +\noindent +\mbox{}\textbf{\textcolor{Plum}{typeof}}\ Comparison\ -$>$\ BooleanType\ \{ \\ +\mbox{}\ \ \ \ \ \textbf{\textcolor{Plum}{ensureType}}\ left\ :$<$=:\ \textbf{\textcolor{Plum}{char}}(COMPARABLE) \\ +\mbox{}\ \ \ \ \ \textbf{\textcolor{Plum}{ensureType}}\ right\ :$<$=:\ \textbf{\textcolor{Plum}{char}}(COMPARABLE) \\ +\mbox{}\ \ \ \ \ \textbf{\textcolor{Plum}{ensureCompatibility}}\ left\ :$<$=$>$:\ right \\ +\mbox{}\} \\ +\mbox{}\textbf{\textcolor{Plum}{typeof}}\ Minus\ -$>$\ \textbf{\textcolor{Plum}{common}}\ left\ right\ \{ \\ +\mbox{}\ \ \ \ \textbf{\textcolor{Plum}{ensureType}}\ left\ :$<$=:\ \textbf{\textcolor{Plum}{char}}(NUMERIC) \\ +\mbox{}\ \ \ \ \textbf{\textcolor{Plum}{ensureType}}\ right\ :$<$=:\ \textbf{\textcolor{Plum}{char}}(NUMERIC) \\ +\mbox{}\ \ \ \ \textbf{\textcolor{Plum}{ensureCompatibility}}\ left\ :$<$=$>$:\ right \\ +\mbox{}\} +\end{tabular} diff --git a/EclipseDayFlorence-presentation/listings/xts-types3.ts b/EclipseDayFlorence-presentation/listings/xts-types3.ts new file mode 100644 index 0000000..8a04f3c --- /dev/null +++ b/EclipseDayFlorence-presentation/listings/xts-types3.ts @@ -0,0 +1,12 @@ +// text widgets may only refer to non-boolean attributes +typeof TextWidget -> feature attr { + ensureType length :<=: IntType + ensureType attr :<=: StringType, IntType, FloatType + ensureType validate :<=: BooleanType +} + +// checkbox widgets may only refer to boolean attributes +typeof CheckBoxWidget -> feature attr { + ensureType attr :<=: BooleanType + ensureType validate :<=: BooleanType +} \ No newline at end of file diff --git a/EclipseDayFlorence-presentation/listings/xts-types3.ts.tex b/EclipseDayFlorence-presentation/listings/xts-types3.ts.tex new file mode 100644 index 0000000..528b895 --- /dev/null +++ b/EclipseDayFlorence-presentation/listings/xts-types3.ts.tex @@ -0,0 +1,16 @@ +% Generator: GNU source-highlight, by Lorenzo Bettini, http://www.gnu.org/software/src-highlite +\begin{tabular}[t]{l} +\noindent +\mbox{}\textcolor{Green}{//\ text\ widgets\ may\ only\ refer\ to\ non-boolean\ attributes\ } \\ +\mbox{}\textbf{\textcolor{Plum}{typeof}}\ TextWidget\ -$>$\ \textbf{\textcolor{Plum}{feature}}\ attr\ \{ \\ +\mbox{}\ \ \ \ \textbf{\textcolor{Plum}{ensureType}}\ length\ :$<$=:\ IntType \\ +\mbox{}\ \ \ \ \textbf{\textcolor{Plum}{ensureType}}\ attr\ :$<$=:\ StringType,\ IntType,\ FloatType \\ +\mbox{}\ \ \ \ \textbf{\textcolor{Plum}{ensureType}}\ validate\ :$<$=:\ BooleanType \\ +\mbox{}\}\ \ \\ +\mbox{} \\ +\mbox{}\textcolor{Green}{//\ checkbox\ widgets\ may\ only\ refer\ to\ boolean\ attributes} \\ +\mbox{}\textbf{\textcolor{Plum}{typeof}}\ CheckBoxWidget\ -$>$\ \textbf{\textcolor{Plum}{feature}}\ attr\ \{ \\ +\mbox{}\ \ \ \ \textbf{\textcolor{Plum}{ensureType}}\ attr\ :$<$=:\ BooleanType \\ +\mbox{}\ \ \ \ \textbf{\textcolor{Plum}{ensureType}}\ validate\ :$<$=:\ BooleanType \\ +\mbox{}\} +\end{tabular} diff --git a/EclipseDayFlorence-presentation/src-gen/org/typesys/xts/guidsl/typesys/GuiDlsTypesystemGenerated.java b/EclipseDayFlorence-presentation/src-gen/org/typesys/xts/guidsl/typesys/GuiDlsTypesystemGenerated.java new file mode 100644 index 0000000..971ac14 --- /dev/null +++ b/EclipseDayFlorence-presentation/src-gen/org/typesys/xts/guidsl/typesys/GuiDlsTypesystemGenerated.java @@ -0,0 +1,23 @@ +package org.typesys.xts.guidsl.typesys; + +import org.eclipse.emf.ecore.EObject; +import de.itemis.xtext.typesystem.exceptions.TypesystemConfigurationException; +import de.itemis.xtext.typesystem.trace.TypeCalculationTrace; +import de.itemis.xtext.typesystem.characteristics.TypeCharacteristic; + +public class GuiDlsTypesystemGenerated extends de.itemis.xtext.typesystem.DefaultTypesystem { + + protected org.typesys.xts.guidsl.guiDsl.GuiDslPackage p = org.typesys.xts.guidsl.guiDsl.GuiDslPackage.eINSTANCE; + + + protected void initialize() { + + try { + + } catch ( TypesystemConfigurationException ex ) { + ex.printStackTrace(); + } + } + + +} diff --git a/EclipseDayFlorence-presentation/xts.tex b/EclipseDayFlorence-presentation/xts.tex index ba81340..db409f7 100644 --- a/EclipseDayFlorence-presentation/xts.tex +++ b/EclipseDayFlorence-presentation/xts.tex @@ -8,52 +8,124 @@ \begin{frame} \frametitle{Xtext Typesystem (XTS)} \begin{itemize} - \item Typesystem DSL written in Xtext - \item Additional uses: interpreter, testing - \item Recursive type computation + \item Originally developed as a framework with a Java API to declaratively + specify type system rules; + \item DSL to generate the Java code that had to be written before; + \item If no suitable declarative abstraction is available, + Java code can still be added manually. + \item \texttt{ITypesystem} interface with methods for + \begin{itemize} + \item calculating the type of model elements + \item for comparing types for + compatibility and subtyping relationships + \end{itemize} \end{itemize} \end{frame} \begin{frame}[fragile] - \frametitle{The Plus Operator with XTS} + \frametitle{Setting up} \begin{footnotesize} - \input{listings/xts-plus.ts.tex} + \input{listings/xts-settingup.ts.tex} \end{footnotesize} - \note{ - \begin{itemize} - \item Commonly used language elements - \end{itemize} - \begin{itemize} - \item subtype relationships - \item grouping of types - \item type computation, \emph{ensure}\ldots clauses - \end{itemize}} + +the platform URI for the Ecore file (the metaclasses for +which we want to specify the type system rules) + \end{frame} -\note{ \begin{frame}[fragile] - \frametitle{The Plus Operator with XTS} - \begin{itemize} - \item Coercion of a number to a String - \end{itemize} + \frametitle{Specifying types} \begin{footnotesize} - \input{listings/xts-typecoerce.java.tex} + \input{listings/xts-types.ts.tex} \end{footnotesize} - \begin{itemize} - \item XTS will try custom coercion methods before throwing a type error - \item coercion methods use polymorphic dispatch - \end{itemize} - public EObject typeCoerce( EObject candidateElement, FloatType candidate, - StringType expected, TypeCalculationTrace trace ) { - if ( candidateElement instanceof NumberLiteral ) { - trace.add( candidateElement, "Number coerced to string."); - return create(lang.getStringType()); - } - return null; -} -\end{frame}} \ No newline at end of file +\onslide<2-> + + \begin{footnotesize} + \input{listings/xts-literals.ts.tex} + \end{footnotesize} + +\onslide<3-> + +\medskip + + Recursive computation + + \begin{footnotesize} + \input{listings/xts-attributeref.ts.tex} + \end{footnotesize} + + +\end{frame} + +\begin{frame}[fragile] + \frametitle{Specifying types} + + \begin{footnotesize} + \input{listings/xts-characteristics.ts.tex} + \end{footnotesize} + +\onslide<2-> + + \begin{footnotesize} + \input{listings/xts-types2.ts.tex} + \end{footnotesize} + +\end{frame} + +\begin{frame}[fragile] + \frametitle{Specifying types} + + \begin{footnotesize} + \input{listings/xts-types3.ts.tex} + \end{footnotesize} + +\end{frame} + +% \begin{frame}[fragile] +% \frametitle{The Plus Operator with XTS} +% +% +% \begin{footnotesize} +% \input{listings/xts-plus.ts.tex} +% \end{footnotesize} +% +% \note{ +% \begin{itemize} +% \item Commonly used language elements +% \end{itemize} +% \begin{itemize} +% \item subtype relationships +% \item grouping of types +% \item type computation, \emph{ensure}\ldots clauses +% \end{itemize}} +% \end{frame} +% +% \note{ +% \begin{frame}[fragile] +% \frametitle{The Plus Operator with XTS} +% \begin{itemize} +% \item Coercion of a number to a String +% \end{itemize} +% +% \begin{footnotesize} +% \input{listings/xts-typecoerce.java.tex} +% \end{footnotesize} +% +% \begin{itemize} +% \item XTS will try custom coercion methods before throwing a type error +% \item coercion methods use polymorphic dispatch +% \end{itemize} +% public EObject typeCoerce( EObject candidateElement, FloatType candidate, +% StringType expected, TypeCalculationTrace trace ) { +% if ( candidateElement instanceof NumberLiteral ) { +% trace.add( candidateElement, "Number coerced to string."); +% return create(lang.getStringType()); +% } +% return null; +% } +% \end{frame}} \ No newline at end of file diff --git a/tsarticle/6-xts.tex b/tsarticle/6-xts.tex index 9a5ad3c..f13e1d5 100644 --- a/tsarticle/6-xts.tex +++ b/tsarticle/6-xts.tex @@ -67,7 +67,7 @@ \subsection{The type of types} \begin{lstlisting}[language=xts] section "Types" typeof Type+ -> clone - subtype IntType base FloatTyoe + subtype IntType base FloatType \end{lstlisting} We also specify the subtyping relationship between \ic{FloatType} and \ic{IntType}. This diff --git a/tsarticle/lstlang0.sty b/tsarticle/lstlang0.sty index b7aff20..48e76ce 100644 --- a/tsarticle/lstlang0.sty +++ b/tsarticle/lstlang0.sty @@ -49,7 +49,7 @@ \lst@definelanguage{xts}% {morekeywords={typesystem,ecore,file,language,package,% section,typeof,subtype,base,clone,javacode,characteristic,% - abstract,ensureType,ensureCompatibility,char,common},% + abstract,ensureType,ensureCompatibility,char,common,feature,ancestor},% sensitive,% morecomment=[l]//,% morecomment=[s]{/*}{*/},%