Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
kazoo
Commits
27061584
Commit
27061584
authored
Mar 18, 2018
by
Maxime Perrotin
Browse files
Add generation of context parameters
parent
27a46e3e
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/taste-backend-skeletons.adb
View file @
27061584
...
...
@@ -65,12 +65,18 @@ package body TASTE.Backend.Skeletons is
-- Generate the content of the Makefile per function
function
Function_Makefile
(
Path
:
String
;
Content
:
Translate_Set
)
return
String
is
Content
:
Translate_Set
)
return
String
is
Tmplt_Makefile
:
constant
String
:=
Path
&
"makefile.tmplt"
;
begin
return
Parse
(
Tmplt_Makefile
,
Content
);
end
Function_Makefile
;
function
CP_To_ASN1
(
Content
:
Translate_Set
)
return
String
is
Tmplt_CP
:
constant
String
:=
Prefix
&
"context_parameters.tmplt"
;
begin
return
Parse
(
Tmplt_CP
,
Content
);
end
CP_To_ASN1
;
-- Generate string for a global Makefile (processing all functions)
-- The template contains a set of languages, and a list of
-- combined function name/language
...
...
@@ -83,7 +89,7 @@ package body TASTE.Backend.Skeletons is
Language_Tag
:
Vector_Tag
;
Is_Type_Tag
:
Vector_Tag
;
Content_Set
:
Translate_Set
;
Tmplt
:
constant
String
:=
Prefix
&
"makefile.tmplt"
;
Tmplt
:
constant
String
:=
Prefix
&
"makefile.tmplt"
;
begin
if
not
Exists
(
Tmplt
)
then
raise
Skeleton_Error
with
"Missing makefile.tmplt"
;
...
...
@@ -137,6 +143,12 @@ package body TASTE.Backend.Skeletons is
Files
=>
Get_ASN1_File_List
);
Make_Text
:
constant
String
:=
(
if
Proceed
then
Function_Makefile
(
Path
,
Make_Tmpl
)
else
""
);
-- Associations for (optional) context parameters:
CP_Tmpl
:
constant
Translate_Set
:=
CP_Template
(
F
=>
Each
);
CP_Text
:
constant
String
:=
CP_To_ASN1
(
CP_Tmpl
);
CP_File
:
constant
String
:=
"Context-"
&
To_String
(
Each
.
Name
)
&
".asn"
;
Func_Tmpl
:
constant
Func_As_Template
:=
Template
.
Funcs
.
Element
(
To_String
(
Each
.
Name
));
...
...
@@ -214,6 +226,15 @@ package body TASTE.Backend.Skeletons is
Name
=>
Output_Base
&
Make_File
);
Put_Line
(
Output_File
,
Make_Text
);
Close
(
Output_File
);
-- Generate context parameters if any
if
not
Each
.
Context_Params
.
Is_Empty
then
Put_Info
(
"Generating "
&
CP_File
);
Create
(
File
=>
Output_File
,
Mode
=>
Out_File
,
Name
=>
Output_Base
&
CP_File
);
Put_Line
(
Output_File
,
CP_Text
);
Close
(
Output_File
);
end
if
;
else
Put_Info
(
"Ignoring function "
&
To_String
(
Each
.
Name
));
end
if
;
...
...
@@ -236,6 +257,41 @@ package body TASTE.Backend.Skeletons is
Close
(
Output_File
);
end
Generate
;
-- Context Parameters
function
CP_Template
(
F
:
Taste_Terminal_Function
)
return
Translate_Set
is
use
Ada
.
Strings
.
Unbounded
;
package
Sort_Set
is
new
Ordered_Sets
(
Unbounded_String
);
use
Sort_Set
;
Sorts_Set
:
Set
;
Unique_Sorts
:
Vector_Tag
;
Corr_Module
:
Vector_Tag
;
Names
:
Vector_Tag
;
Sorts
:
Vector_Tag
;
ASN1_Modules
:
Vector_Tag
;
Values
:
Vector_Tag
;
begin
for
Each
of
F
.
Context_Params
loop
if
not
Sorts_Set
.
Contains
(
Each
.
Sort
)
then
-- Build up a set of unique types, needed for the IMPORTS section
-- in the ASN.1 module
Sorts_Set
.
Insert
(
Each
.
Sort
);
Unique_Sorts
:=
Unique_Sorts
&
Each
.
Sort
;
Corr_Module
:=
Corr_Module
&
Each
.
ASN1_Module
;
end
if
;
Names
:=
Names
&
Each
.
Name
;
Sorts
:=
Sorts
&
Each
.
Sort
;
ASN1_Modules
:=
ASN1_Modules
&
Each
.
ASN1_Module
;
Values
:=
Values
&
Each
.
Default_Value
;
end
loop
;
return
Result
:
constant
Translate_Set
:=
+
Assoc
(
"Name"
,
F
.
Name
)
&
Assoc
(
"Sort_Set"
,
Unique_Sorts
)
&
Assoc
(
"Module_Set"
,
Corr_Module
)
&
Assoc
(
"CP_Name"
,
Names
)
&
Assoc
(
"CP_Sort"
,
Sorts
)
&
Assoc
(
"CP_ASN1_Module"
,
ASN1_Modules
)
&
Assoc
(
"CP_Value"
,
Values
);
end
CP_Template
;
-- Makefiles need the function name and the list of ASN.1 files/modules
function
Function_Makefile_Template
(
F
:
Taste_Terminal_Function
;
Modules
:
Tag
;
...
...
@@ -243,7 +299,7 @@ package body TASTE.Backend.Skeletons is
is
(
Translate_Set
'(
+
Assoc
(
"Name"
,
F
.
Name
)
&
Assoc
(
"ASN1_Files"
,
Files
)
&
Assoc
(
"ASN1_Modules"
,
Modules
))
&
Assoc
(
"Is_Type"
,
F
.
Is_Type
)
&
Assoc
(
"Is_Type"
,
F
.
Is_Type
)
&
Assoc
(
"Instance_Of"
,
F
.
Instance_Of
.
Value_Or
(
US
(
""
))));
...
...
src/taste-backend-skeletons.ads
View file @
27061584
...
...
@@ -41,6 +41,7 @@ private
return
Interface_As_Template
;
function
Func_Template
(
F
:
Taste_Terminal_Function
)
return
Func_As_Template
;
function
CP_Template
(
F
:
Taste_Terminal_Function
)
return
Translate_Set
;
function
Function_Makefile_Template
(
F
:
Taste_Terminal_Function
;
Modules
:
Tag
;
Files
:
Tag
)
return
Translate_Set
;
...
...
src/taste-parser_version.ads
View file @
27061584
package
TASTE
.
Parser_Version
is
Parser_Release
:
constant
String
:=
"
b10344b
; Commit Date: S
at
Mar 1
7
1
7:31:49
2018 "
;
"
5e581c6
; Commit Date: S
un
Mar 1
8
1
0:57:03
2018 "
;
Ocarina_Version
:
constant
String
:=
"Ocarina 2017.x (Working Copy from r2a52334)"
;
end
TASTE
.
Parser_Version
;
\ No newline at end of file
templates/skeletons/context_parameters.tmplt
0 → 100644
View file @
27061584
@@-- Generate an ASN.1 module for context parameters
@@-- The following tags are available in this template:
@@--
@@-- @_Name_@ : Function name
@@-- @_Sort_Set_@ : Set of types used for this Context Parameter file
@@-- @_Module_Set_@ : ... corresponding module (needed for ASN.1 "IMPORTS")
@@-- @_CP_Name_@ : Table of context parameter names
@@-- @_CP_Sort_@ : ... corresponding ASN.1 type
@@-- @_CP_ASN1_Module_@ : ... in ASN.1 module
@@-- @_CP_Value_@ : ... with default value
Context-@_REPLACE((_)/-):LOWER:Name_@ DEFINITIONS ::=
BEGIN
IMPORTS
@@INLINE( )(\n )(;\n)@@
@@TABLE@@
@_Sort_Set_@ FROM @_Module_Set_@
@@END_TABLE@@
@@END_INLINE@@
-- Group all context parameters of this function in a record
Context-@_REPLACE((_)/-):LOWER:Name_@ ::= SEQUENCE {
@@INLINE( )(,\n )(\n)@@
@@TABLE@@
@_REPLACE((_)/-):LOWER:CP_Name_@ @_CP_Sort_@
@@END_TABLE@@
@@END_INLINE@@
}
-- Declare a constant with the values set by the user in the interface view
@_REPLACE((_)/-):LOWER:Name_@-ctxt Context-@_REPLACE((_)/-):LOWER:Name_@ ::= {
@@INLINE( )(,\n )(\n)@@
@@TABLE@@
@_REPLACE((_)/-):LOWER:CP_Name_@ @_CP_Value_@
@@END_TABLE@@
@@END_INLINE@@
}
END
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment