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
Ocarina
Commits
b3b06000
Commit
b3b06000
authored
Jul 07, 2015
by
yoogx
Browse files
* First design of Python function to retrieve property values
For issue #44
parent
af7d3add
Changes
7
Hide whitespace changes
Inline
Side-by-side
resources/runtime/python/ocarina/ocarina.py
View file @
b3b06000
...
...
@@ -356,3 +356,10 @@ def getRoot ():
'''
return
runOcarinaFunction
(
libocarina_python
.
getRoot
)
################################################################################
def
getPropertyValue
(
nodeId
,
nameId
):
'''Get the value of the property
'''
return
runOcarinaFunction
(
libocarina_python
.
getPropertyValue
,
nodeId
,
nameId
)
resources/runtime/python/test/visitor.py
0 → 100755
View file @
b3b06000
#! /usr/bin/python
import
ocarina
;
import
sys
;
def
visitor
(
component
,
level
):
print
' '
*
level
,
'Visiting '
,
ocarina
.
getInstanceName
(
component
)[
0
]
features
=
ocarina
.
AIN
.
Features
(
component
)[
0
];
if
features
is
not
None
:
print
' '
*
level
,
' -> features:'
,
features
for
feature
in
features
:
print
' '
*
level
,
' -> '
,
feature
,
","
,
ocarina
.
getInstanceName
(
feature
)[
0
]
properties
=
ocarina
.
AIN
.
Properties
(
component
)[
0
];
if
properties
is
not
None
:
print
' '
*
level
,
' -> properties:'
for
property
in
properties
:
print
' '
*
level
,
' '
,
ocarina
.
getPropertyValue
(
component
,
property
)[
0
]
subcomponents
=
ocarina
.
AIN
.
Subcomponents
(
component
)[
0
];
if
subcomponents
is
not
None
:
print
' '
*
level
,
' -> subcomponents:'
,
subcomponents
for
subcomponent
in
subcomponents
:
print
' '
*
level
,
' -> '
,
subcomponent
,
","
,
ocarina
.
getInstanceName
(
subcomponent
)[
0
]
visitor
(
str
(
ocarina
.
AIN
.
Corresponding_Instance
(
subcomponent
)[
0
]),
level
+
3
)
print
' '
*
level
,
'end of visit of '
,
component
def
main
():
'''Test function'''
err
=
ocarina
.
load
(
"rma.aadl"
);
# load a file
err
=
ocarina
.
analyze
();
# analyze models
err
=
ocarina
.
instantiate
(
"rma.erc32"
);
# instantiate system
print
'----------------------------------------------------'
print
'Visit AADL Instance tree'
print
'----------------------------------------------------'
root
=
ocarina
.
getRoot
()[
0
]
visitor
(
root
,
0
)
if
__name__
==
"__main__"
:
main
()
sys
.
exit
(
0
);
# exit
src/backends/ocarina-backends-properties-utils.adb
View file @
b3b06000
...
...
@@ -33,6 +33,10 @@ with Ocarina.Backends.Messages;
with
Ocarina
.
Instances
.
Queries
;
with
Ocarina
.
ME_AADL
.
AADL_Instances
.
Nodes
;
with
Ocarina
.
Namet
;
with
Utils
;
with
Ocarina
.
ME_AADL
.
AADL_Tree
.
Nodes
;
with
Ocarina
.
ME_AADL
.
AADL_Tree
.
NUtils
;
with
Ocarina
.
AADL_Values
;
package
body
Ocarina
.
Backends
.
Properties
.
Utils
is
...
...
@@ -40,11 +44,175 @@ package body Ocarina.Backends.Properties.Utils is
use
Ocarina
.
Instances
.
Queries
;
use
Ocarina
.
ME_AADL
.
AADL_Instances
.
Nodes
;
use
Ocarina
.
Namet
;
use
Standard
.
Utils
;
package
ATN
renames
Ocarina
.
ME_AADL
.
AADL_Tree
.
Nodes
;
package
ATNU
renames
Ocarina
.
ME_AADL
.
AADL_Tree
.
NUtils
;
use
type
ATN
.
Node_Kind
;
function
SA
(
S
:
String
)
return
String_Access
is
(
new
String
'(
S
));
-----------------------------------------
-- Print_Value_Of_Property_Association --
-----------------------------------------
function
Print_Value_Of_Property_Association
(
AADL_Property_Value
:
Node_Id
)
return
String
;
function
Print_Value_Of_Property_Association
(
AADL_Property_Value
:
Node_Id
)
return
String
is
begin
if
Present
(
AADL_Property_Value
)
and
then
ATN
.
Kind
(
AADL_Property_Value
)
=
ATN
.
K_Signed_AADLNumber
then
return
Ocarina
.
AADL_Values
.
Image
(
ATN
.
Value
(
ATN
.
Number_Value
(
AADL_Property_Value
)))
&
" "
&
(
if
Present
(
ATN
.
Unit_Identifier
(
AADL_Property_Value
))
then
Get_Name_String
(
ATN
.
Display_Name
(
ATN
.
Unit_Identifier
(
AADL_Property_Value
)))
else
""
);
elsif
Present
(
AADL_Property_Value
)
and
then
ATN
.
Kind
(
AADL_Property_Value
)
=
ATN
.
K_Literal
then
-- This property value denotes a literal
return
Ocarina
.
AADL_Values
.
Image
(
ATN
.
Value
(
AADL_Property_Value
),
Quoted
=>
False
);
elsif
Present
(
AADL_Property_Value
)
and
then
ATN
.
Kind
(
AADL_Property_Value
)
=
ATN
.
K_Reference_Term
then
-- This property value denotes a reference term
return
Get_Name_String
(
ATN
.
Display_Name
(
ATN
.
First_Node
-- XXX must iterate
(
ATN
.
List_Items
(
ATN
.
Reference_Term
(
AADL_Property_Value
)))));
elsif
Present
(
AADL_Property_Value
)
and
then
ATN
.
Kind
(
AADL_Property_Value
)
=
ATN
.
K_Enumeration_Term
then
-- This property value denotes an enumeration term
return
Get_Name_String
(
ATN
.
Display_Name
(
ATN
.
Identifier
(
AADL_Property_Value
)));
elsif
Present
(
AADL_Property_Value
)
and
then
ATN
.
Kind
(
AADL_Property_Value
)
=
ATN
.
K_Number_Range_Term
then
-- This property value denotes a number range term
return
Ocarina
.
AADL_Values
.
Image
(
ATN
.
Value
(
ATN
.
Number_Value
(
ATN
.
Lower_Bound
(
AADL_Property_Value
))))
&
(
if
Present
(
ATN
.
Unit_Identifier
(
ATN
.
Lower_Bound
(
AADL_Property_Value
)))
then
" "
&
Get_Name_String
(
ATN
.
Display_Name
(
ATN
.
Unit_Identifier
(
ATN
.
Lower_Bound
(
AADL_Property_Value
))))
else
""
)
&
" .. "
&
Ocarina
.
AADL_Values
.
Image
(
ATN
.
Value
(
ATN
.
Number_Value
(
ATN
.
Upper_Bound
(
AADL_Property_Value
))))
&
(
if
Present
(
ATN
.
Unit_Identifier
(
ATN
.
Upper_Bound
(
AADL_Property_Value
)))
then
" "
&
Get_Name_String
(
ATN
.
Display_Name
(
ATN
.
Unit_Identifier
(
ATN
.
Upper_Bound
(
AADL_Property_Value
))))
else
""
);
end
if
;
raise
Program_Error
;
end
Print_Value_Of_Property_Association
;
----------------------------
-- Check_And_Get_Property --
----------------------------
function
Check_And_Get_Property
(
E
:
Node_Id
;
Property
:
Node_Id
)
return
String_List
is
Prop_Name
:
constant
Name_Id
:=
Standard
.
Utils
.
To_Lower
(
Display_Name
(
Identifier
(
Property
)));
A
:
constant
String_Access
:=
new
String
'(
Get_Name_String
(
Prop_Name
));
AADL_Property_Value
:
Node_Id
;
begin
if
Is_Defined_String_Property
(
E
,
Prop_Name
)
then
return
A
&
SA
(
Get_Name_String
(
Get_String_Property
(
E
,
Prop_Name
)));
elsif
(
Is_Defined_Integer_Property
(
E
,
Prop_Name
)
or
else
Is_Defined_Float_Property
(
E
,
Prop_Name
))
then
AADL_Property_Value
:=
Get_Value_Of_Property_Association
(
E
,
Prop_Name
);
return
A
&
SA
(
Print_Value_Of_Property_Association
(
AADL_Property_Value
));
elsif
Is_Defined_Boolean_Property
(
E
,
Prop_Name
)
then
return
A
&
SA
(
Boolean
'
Image
(
Get_Boolean_Property
(
E
,
Prop_Name
)));
elsif
Is_Defined_Reference_Property
(
E
,
Prop_Name
)
then
return
A
&
SA
(
Get_Reference_Property
(
E
,
Prop_Name
)'
Img
);
elsif
Is_Defined_Classifier_Property
(
E
,
Prop_Name
)
then
return
A
&
SA
(
Get_Classifier_Property
(
E
,
Prop_Name
)'
Img
);
elsif
Is_Defined_Range_Property
(
E
,
Prop_Name
)
then
AADL_Property_Value
:=
Get_Range_Property
(
E
,
Prop_Name
);
return
A
&
SA
(
Print_Value_Of_Property_Association
(
AADL_Property_Value
));
elsif
Is_Defined_List_Property
(
E
,
Prop_Name
)
then
declare
It
:
Node_Id
:=
ATN
.
First_Node
(
Get_List_Property
(
E
,
Prop_Name
));
B
:
String_List
(
1
..
ATNU
.
Length
(
Get_List_Property
(
E
,
Prop_Name
)));
J
:
Integer
:=
B
'
First
;
begin
while
Present
(
It
)
loop
B
(
J
)
:=
new
String
'(
Print_Value_Of_Property_Association
(
It
));
J
:=
J
+
1
;
It
:=
ATN
.
Next_Node
(
It
);
end
loop
;
return
A
&
B
;
end
;
elsif
Is_Defined_Enumeration_Property
(
E
,
Prop_Name
)
then
return
A
&
SA
(
Get_Name_String
(
Get_Enumeration_Property
(
E
,
Prop_Name
)));
end
if
;
return
A
&
SA
(
" KO"
);
end
Check_And_Get_Property
;
function
Check_And_Get_Property
(
E
:
Node_Id
;
Property_Name
:
Name_Id
;
...
...
src/backends/ocarina-backends-properties-utils.ads
View file @
b3b06000
...
...
@@ -29,8 +29,34 @@
-- --
------------------------------------------------------------------------------
with
GNAT
.
OS_Lib
;
use
GNAT
.
OS_Lib
;
package
Ocarina
.
Backends
.
Properties
.
Utils
is
-- This package proposes various generic accessor to ease the
-- retrieval of property values.
-- This high-level accessor return a GNAT.OS_Lib.String_List made
-- of the name of the property in lower case, followed by a list
-- of strings representing the property value. E.g.
--
-- ("source_stack_size", "13952 Bytes")
-- ("Deadline", "500 Ms")
-- ("Compute_Execution_Time", "0 Ms .. 3 Ms")
-- ("Dispatch_Offset", "100 Ms")
-- ("Period", "500 Ms")
-- ("Dispatch_Protocol", "Periodic")
function
Check_And_Get_Property
(
E
:
Node_Id
;
Property
:
Node_Id
)
return
String_List
;
-- The following accessors takes as parameters the following entities
-- * E: entity from the instance tree for which we look for a property
-- * Property_Name: name of the property we are looking for, in
-- lower case
function
Check_And_Get_Property
(
E
:
Node_Id
;
Property_Name
:
Name_Id
;
...
...
@@ -68,7 +94,4 @@ package Ocarina.Backends.Properties.Utils is
Default_Value
:
Int
:=
Int
'
First
)
return
Int
;
-- Check Property_Name is set on node E, if so returns its value
-- otherwise return the default value.
end
Ocarina
.
Backends
.
Properties
.
Utils
;
src/python/ocarina-python_cmd.adb
View file @
b3b06000
...
...
@@ -444,10 +444,27 @@ package body Ocarina.Python_Cmd is
pragma
Unreferenced
(
Command
);
List_Node
:
Node_Id
;
begin
ATNP
.
return_List
(
Data
,
Get_Property_Constants
(
Get_Node_Id_From_String
(
Nth_Arg
(
Data
,
1
,
""
))));
ATNP
.
return_List
(
Data
,
Get_Property_Constants
(
Get_Node_Id_From_String
(
Nth_Arg
(
Data
,
1
,
""
))));
end
On_Get_PropertyConstants
;
---------------------------
-- On_Get_Property_Value --
---------------------------
procedure
On_Get_Property_Value
(
Data
:
in
out
Callback_Data
'
Class
;
Command
:
String
);
procedure
On_Get_Property_Value
(
Data
:
in
out
Callback_Data
'
Class
;
Command
:
String
)
is
pragma
Unreferenced
(
Command
);
begin
Get_Property_Value
(
Data
,
Nth_Arg
(
Data
,
1
,
""
),
Nth_Arg
(
Data
,
2
,
""
));
end
On_Get_Property_Value
;
----------------------
-- On_Get_Instances --
----------------------
...
...
@@ -651,6 +668,11 @@ package body Ocarina.Python_Cmd is
(
Repo
,
"getPropertyDefinitions"
,
1
,
1
,
Handler
=>
On_Get_Property_Definitions
'
Unrestricted_Access
);
-- getPropertyValue() function
Register_Command
(
Repo
,
"getPropertyValue"
,
2
,
2
,
Handler
=>
On_Get_Property_Value
'
Unrestricted_Access
);
-- getPropertyConstants() function
Register_Command
(
Repo
,
"getPropertyConstants"
,
1
,
1
,
...
...
src/python/ocarina-utils.adb
View file @
b3b06000
...
...
@@ -49,6 +49,7 @@ with Ocarina.Instances; use Ocarina.Instances;
with
Ocarina
.
Parser
;
use
Ocarina
.
Parser
;
with
Ocarina
.
Options
;
use
Ocarina
.
Options
;
with
Ocarina
.
Files
;
use
Ocarina
.
Files
;
with
Ocarina
.
Backends
.
Properties
.
Utils
;
package
body
Ocarina
.
Utils
is
...
...
@@ -260,6 +261,25 @@ package body Ocarina.Utils is
return
AADL_Root
;
end
Get_AADL_Root
;
------------------------
-- Get_Property_Value --
------------------------
procedure
Get_Property_Value
(
Data
:
in
out
Callback_Data
'
Class
;
PropId
:
String
;
PropName
:
String
)
is
Result
:
constant
String_List
:=
Ocarina
.
Backends
.
Properties
.
Utils
.
Check_And_Get_Property
(
Get_Node_Id_From_String
(
PropId
),
Get_Node_Id_From_String
(
PropName
));
begin
Set_Return_Value_As_List
(
Data
);
for
Elt
of
Result
loop
Set_Return_Value
(
Data
,
Elt
.
all
);
end
loop
;
end
Get_Property_Value
;
-----------------
-- Get_Node_Id --
-----------------
...
...
src/python/ocarina-utils.ads
View file @
b3b06000
...
...
@@ -61,5 +61,7 @@ package Ocarina.Utils is
function
Get_Int_From_String
(
Name
:
String
)
return
Int
;
function
Get_Value_Id_From_String
(
Name
:
String
)
return
Value_Id
;
procedure
Get_Node_Id
(
Data
:
in
out
Callback_Data
'
Class
;
N
:
String
);
procedure
Get_Property_Value
(
Data
:
in
out
Callback_Data
'
Class
;
PropId
:
String
;
PropName
:
String
);
end
Ocarina
.
Utils
;
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