author | etisserant |
Mon, 18 Jun 2007 14:45:29 +0200 | |
changeset 19 | 0b499416ebd7 |
parent 18 | ee18a387e80a |
child 21 | e619d7bea692 |
permissions | -rw-r--r-- |
0 | 1 |
#!/usr/bin/env python |
2 |
# -*- coding: utf-8 -*- |
|
3 |
||
14
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
4 |
import string, os, sys |
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
5 |
|
0 | 6 |
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor |
7 |
#based on the plcopen standard. |
|
8 |
# |
|
9 |
#Copyright (C): Edouard TISSERANT and Laurent BESSARD |
|
10 |
# |
|
11 |
#See COPYING file for copyrights details. |
|
12 |
# |
|
13 |
#This library is free software; you can redistribute it and/or |
|
5 | 14 |
#modify it under the terms of the GNU General Public |
0 | 15 |
#License as published by the Free Software Foundation; either |
16 |
#version 2.1 of the License, or (at your option) any later version. |
|
17 |
# |
|
18 |
#This library is distributed in the hope that it will be useful, |
|
19 |
#but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
20 |
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
21 |
#Lesser General Public License for more details. |
|
22 |
# |
|
5 | 23 |
#You should have received a copy of the GNU General Public |
0 | 24 |
#License along with this library; if not, write to the Free Software |
25 |
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
26 |
||
27 |
||
9 | 28 |
LANGUAGES = ["IL","ST","FBD","LD","SFC"] |
29 |
||
0 | 30 |
#------------------------------------------------------------------------------- |
31 |
# Function Block Types definitions |
|
32 |
#------------------------------------------------------------------------------- |
|
33 |
||
34 |
""" |
|
35 |
Ordored list of common Function Blocks defined in the IEC 61131-3 |
|
36 |
Each block have this attributes: |
|
37 |
- "name" : The block name |
|
38 |
- "type" : The block type. It can be "function", "functionBlock" or "program" |
|
39 |
- "extensible" : Boolean that define if the block is extensible |
|
40 |
- "inputs" : List of the block inputs |
|
41 |
- "outputs" : List of the block outputs |
|
42 |
- "comment" : Comment that will be displayed in the block popup |
|
43 |
Inputs and outputs are a tuple of characteristics that are in order: |
|
44 |
- The name |
|
45 |
- The data type |
|
46 |
- The default modifier which can be "none", "negated", "rising" or "falling" |
|
47 |
""" |
|
48 |
||
14
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
49 |
BlockTypes = [{"name" : "Standard function blocks", "list": |
0 | 50 |
[{"name" : "SR", "type" : "functionBlock", "extensible" : False, |
51 |
"inputs" : [("S1","BOOL","none"),("R","BOOL","none")], |
|
52 |
"outputs" : [("Q1","BOOL","none")], |
|
53 |
"comment" : "SR bistable\nThe SR bistable is a latch where the Set dominates."}, |
|
54 |
{"name" : "RS", "type" : "functionBlock", "extensible" : False, |
|
55 |
"inputs" : [("S","BOOL","none"),("R1","BOOL","none")], |
|
56 |
"outputs" : [("Q1","BOOL","none")], |
|
57 |
"comment" : "RS bistable\nThe RS bistable is a latch where the Reset dominates."}, |
|
58 |
{"name" : "SEMA", "type" : "functionBlock", "extensible" : False, |
|
59 |
"inputs" : [("CLAIM","BOOL","none"),("RELEASE","BOOL","none")], |
|
60 |
"outputs" : [("BUSY","BOOL","none")], |
|
61 |
"comment" : "Semaphore\nThe semaphore provides a mechanism to allow software elements mutually exclusive access to certain ressources."}, |
|
62 |
{"name" : "R_TRIG", "type" : "functionBlock", "extensible" : False, |
|
63 |
"inputs" : [("CLK","BOOL","none")], |
|
64 |
"outputs" : [("Q","BOOL","none")], |
|
65 |
"comment" : "Rising edge detector\nThe output produces a single pulse when a rising edge is detected."}, |
|
66 |
{"name" : "F_TRIG", "type" : "functionBlock", "extensible" : False, |
|
67 |
"inputs" : [("CLK","BOOL","none")], |
|
68 |
"outputs" : [("Q","BOOL","none")], |
|
69 |
"comment" : "Falling edge detector\nThe output produces a single pulse when a falling edge is detected."}, |
|
70 |
{"name" : "CTU", "type" : "functionBlock", "extensible" : False, |
|
71 |
"inputs" : [("CU","BOOL","rising"),("R","BOOL","none"),("PV","INT","none")], |
|
72 |
"outputs" : [("Q","BOOL","none"),("CV","INT","none")], |
|
73 |
"comment" : "Up-counter\nThe up-counter can be used to signal when a count has reached a maximum value."}, |
|
74 |
{"name" : "CTD", "type" : "functionBlock", "extensible" : False, |
|
75 |
"inputs" : [("CD","BOOL","rising"),("LD","BOOL","none"),("PV","INT","none")], |
|
76 |
"outputs" : [("Q","BOOL","none"),("CV","INT","none")], |
|
77 |
"comment" : "Down-counter\nThe down-counter can be used to signal when a count has reached zero, on counting down from a preset value."}, |
|
78 |
{"name" : "CTUD", "type" : "functionBlock", "extensible" : False, |
|
79 |
"inputs" : [("CU","BOOL","rising"),("CD","BOOL","rising"),("R","BOOL","none"),("LD","BOOL","none"),("PV","INT","none")], |
|
80 |
"outputs" : [("QU","BOOL","none"),("QD","BOOL","none"),("CV","INT","none")], |
|
81 |
"comment" : "Up-down counter\nThe up-down counter has two inputs CU and CD. It can be used to both count up on one input ans down on the other."}, |
|
82 |
{"name" : "TP", "type" : "functionBlock", "extensible" : False, |
|
83 |
"inputs" : [("IN","BOOL","none"),("PT","TIME","none")], |
|
84 |
"outputs" : [("Q","BOOL","none"),("ET","TIME","none")], |
|
85 |
"comment" : "Pulse timer\nThe pulse timer can be used to generate output pulses of a given time duration."}, |
|
86 |
{"name" : "TOF", "type" : "functionBlock", "extensible" : False, |
|
87 |
"inputs" : [("IN","BOOL","none"),("PT","TIME","none")], |
|
88 |
"outputs" : [("Q","BOOL","none"),("ET","TIME","none")], |
|
89 |
"comment" : "On-delay timer\nThe on-delay timer can be used to delay setting an output true, for fixed period after an input becomes true."}, |
|
90 |
{"name" : "TON", "type" : "functionBlock", "extensible" : False, |
|
91 |
"inputs" : [("IN","BOOL","none"),("PT","TIME","none")], |
|
92 |
"outputs" : [("Q","BOOL","none"),("ET","TIME","none")], |
|
93 |
"comment" : "Off-delay timer\nThe off-delay timer can be used to delay setting an output false, for fixed period after input goes false."}, |
|
94 |
{"name" : "RTC", "type" : "functionBlock", "extensible" : False, |
|
95 |
"inputs" : [("EN","BOOL","none"),("PDT","DATE_AND_TIME","none")], |
|
96 |
"outputs" : [("Q","BOOL","none"),("CDT","DATE_AND_TIME","none")], |
|
97 |
"comment" : "Real time clock\nThe real time clock has many uses including time stamping, setting dates and times of day in batch reports, in alarm messages and so on."}, |
|
98 |
{"name" : "INTEGRAL", "type" : "functionBlock", "extensible" : False, |
|
99 |
"inputs" : [("RUN","BOOL","none"),("R1","BOOL","none"),("XIN","REAL","none"),("X0","REAL","none"),("CYCLE","TIME","none")], |
|
100 |
"outputs" : [("Q","BOOL","none"),("XOUT","REAL","none")], |
|
101 |
"comment" : "Integral\nThe integral function block integrates the value of input XIN over time."}, |
|
102 |
{"name" : "DERIVATIVE", "type" : "functionBlock", "extensible" : False, |
|
103 |
"inputs" : [("RUN","BOOL","none"),("XIN","REAL","none"),("CYCLE","TIME","none")], |
|
104 |
"outputs" : [("XOUT","REAL","none")], |
|
105 |
"comment" : "Derivative\nThe derivative function block produces an output XOUT proportional to the rate of change of the input XIN."}, |
|
106 |
{"name" : "PID", "type" : "functionBlock", "extensible" : False, |
|
107 |
"inputs" : [("AUTO","BOOL","none"),("PV","REAL","none"),("SP","REAL","none"),("X0","REAL","none"),("KP","REAL","none"),("TR","REAL","none"),("TD","REAL","none"),("CYCLE","TIME","none")], |
|
108 |
"outputs" : [("XOUT","REAL","none")], |
|
109 |
"comment" : "PID\nThe PID (proportional, Integral, Derivative) function block provides the classical three term controller for closed loop control."}, |
|
110 |
{"name" : "RAMP", "type" : "functionBlock", "extensible" : False, |
|
111 |
"inputs" : [("RUN","BOOL","none"),("X0","REAL","none"),("X1","REAL","none"),("TR","TIME","none"),("CYCLE","TIME","none"),("HOLDBACK","BOOL","none"),("ERROR","REAL","none"),("PV","REAL","none")], |
|
112 |
"outputs" : [("RAMP","BOOL","none"),("XOUT","REAL","none")], |
|
113 |
"comment" : "Ramp\nThe RAMP function block is modelled on example given in the standard but with the addition of a 'Holdback' feature."}, |
|
114 |
{"name" : "HYSTERESIS", "type" : "functionBlock", "extensible" : False, |
|
115 |
"inputs" : [("XIN1","REAL","none"),("XIN2","REAL","none"),("EPS","REAL","none")], |
|
116 |
"outputs" : [("Q","BOOL","none")], |
|
117 |
"comment" : "Hysteresis\nThe hysteresis function block provides a hysteresis boolean output driven by the difference of two floating point (REAL) inputs XIN1 and XIN2."}, |
|
118 |
{"name" : "RATIO_MONITOR", "type" : "functionBlock", "extensible" : False, |
|
119 |
"inputs" : [("PV1","REAL","none"),("PV2","REAL","none"),("RATIO","REAL","none"),("TIMON","TIME","none"),("TIMOFF","TIME","none"),("TOLERANCE","BOOL","none"),("RESET","BOOL","none"),("CYCLE","TIME","none")], |
|
120 |
"outputs" : [("ALARM","BOOL","none"),("TOTAL_ERR","BOOL","none")], |
|
121 |
"comment" : "Ratio monitor\nThe ratio_monitor function block checks that one process value PV1 is always a given ratio (defined by input RATIO) of a second process value PV2."}, |
|
122 |
]} |
|
123 |
] |
|
124 |
||
125 |
""" |
|
126 |
Function that returns the block definition associated to the block type given |
|
127 |
""" |
|
128 |
||
129 |
def GetBlockType(type): |
|
130 |
for category in BlockTypes: |
|
131 |
for blocktype in category["list"]: |
|
132 |
if blocktype["name"] == type: |
|
133 |
return blocktype |
|
134 |
return None |
|
135 |
||
136 |
||
137 |
#------------------------------------------------------------------------------- |
|
138 |
# Data Types definitions |
|
139 |
#------------------------------------------------------------------------------- |
|
140 |
||
141 |
""" |
|
142 |
Ordored list of common data types defined in the IEC 61131-3 |
|
143 |
Each type is associated to his direct parent type. It defines then a hierarchy |
|
144 |
between type that permits to make a comparison of two types |
|
145 |
""" |
|
18
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
146 |
TypeHierarchy_list = [ |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
147 |
("ANY" , None), |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
148 |
("ANY_DERIVED" , "ANY"), |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
149 |
("ANY_ELEMENTARY" , "ANY"), |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
150 |
("ANY_MAGNITUDE", "ANY_ELEMENTARY"), |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
151 |
("ANY_BIT" , "ANY_ELEMENTARY"), |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
152 |
("ANY_STRING" , "ANY_ELEMENTARY"), |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
153 |
("ANY_DATE" , "ANY_ELEMENTARY"), |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
154 |
("ANY_NUM" , "ANY_MAGNITUDE"), |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
155 |
("ANY_REAL" , "ANY_NUM"), |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
156 |
("ANY_INT" , "ANY_NUM"), |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
157 |
("REAL" , "ANY_REAL"), |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
158 |
("LREAL" , "ANY_REAL"), |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
159 |
("SINT" , "ANY_INT"), |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
160 |
("INT" , "ANY_INT"), |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
161 |
("DINT" , "ANY_INT"), |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
162 |
("LINT" , "ANY_INT"), |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
163 |
("USINT" , "ANY_INT"), |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
164 |
("UINT" , "ANY_INT"), |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
165 |
("UDINT" , "ANY_INT"), |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
166 |
("ULINT" , "ANY_INT"), |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
167 |
("TIME" , "ANY_MAGNITUDE"), |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
168 |
("BOOL" , "ANY_BIT"), |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
169 |
("BYTE" , "ANY_BIT"), |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
170 |
("WORD" , "ANY_BIT"), |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
171 |
("DWORD" , "ANY_BIT"), |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
172 |
("LWORD" , "ANY_BIT"), |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
173 |
("STRING" , "ANY_STRING"), |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
174 |
("WSTRING" , "ANY_STRING"), |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
175 |
("DATE" , "ANY_DATE"), |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
176 |
("TOD" , "ANY_DATE"), |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
177 |
("DT" , "ANY_DATE")] |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
178 |
|
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
179 |
TypeHierarchy = dict(TypeHierarchy_list) |
0 | 180 |
|
181 |
""" |
|
15 | 182 |
returns true if the given data type is the same that "reference" meta-type or one of its types. |
0 | 183 |
""" |
184 |
||
185 |
def IsOfType(test, reference): |
|
186 |
while test != None: |
|
187 |
if test == reference: |
|
188 |
return True |
|
189 |
test = TypeHierarchy[test] |
|
190 |
return False |
|
191 |
||
15 | 192 |
""" |
193 |
returns list of all types that correspont to the ANY* meta type |
|
194 |
""" |
|
14
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
195 |
def GetSubTypes(reference): |
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
196 |
return [ typename for typename in TypeHierarchy.iterkeys() if typename[:3] != "ANY" and IsOfType(typename, reference)] |
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
197 |
|
18
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
198 |
|
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
199 |
def IsATime(iectype): |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
200 |
return IsOfType(iectype, TIME) or IsOfType(iectype, ANY_DATE) |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
201 |
|
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
202 |
|
15 | 203 |
""" |
204 |
take a .csv file and translate it it a "csv_table" |
|
205 |
""" |
|
14
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
206 |
def csv_file_to_table(file): |
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
207 |
return [ map(string.strip,line.split(';')) for line in file.xreadlines()] |
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
208 |
|
15 | 209 |
""" |
210 |
seek into the csv table to a section ( section_name match 1st field ) |
|
211 |
return the matching row without first field |
|
212 |
""" |
|
14
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
213 |
def find_section(section_name, table): |
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
214 |
fields = [None] |
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
215 |
while(fields[0] != section_name): |
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
216 |
fields = table.pop(0) |
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
217 |
return fields[1:] |
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
218 |
|
15 | 219 |
""" |
220 |
extract the standard functions standard parameter names and types... |
|
221 |
return a { ParameterName: Type, ...} |
|
222 |
""" |
|
14
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
223 |
def get_standard_funtions_input_variables(table): |
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
224 |
variables = find_section("Standard_functions_variables_types", table) |
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
225 |
standard_funtions_input_variables = {} |
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
226 |
fields = [True,True] |
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
227 |
while(fields[1]): |
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
228 |
fields = table.pop(0) |
18
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
229 |
variable_from_csv = dict([(champ, val) for champ, val in zip(variables, fields[1:]) if champ!='']) |
14
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
230 |
standard_funtions_input_variables[variable_from_csv['name']] = variable_from_csv['type'] |
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
231 |
return standard_funtions_input_variables |
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
232 |
|
15 | 233 |
""" |
234 |
translate .csv file input declaration into PLCOpenEditor interessting values |
|
235 |
in : "(ANY_NUM, ANY_NUM)" and { ParameterName: Type, ...} |
|
236 |
return [("IN1","ANY_NUM","none"),("IN2","ANY_NUM","none")] |
|
237 |
""" |
|
14
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
238 |
def csv_input_translate(str_decl, variables, base): |
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
239 |
decl = str_decl.replace('(','').replace(')','').replace(' ','').split(',') |
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
240 |
param_types = [] |
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
241 |
param_names = [] |
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
242 |
modifiers = [] |
18
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
243 |
|
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
244 |
len_of_not_predifined_variable = 0 |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
245 |
for param_type in decl: |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
246 |
predifined_variable_param_type = variables.get(param_type,None) |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
247 |
if not predifined_variable_param_type : |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
248 |
len_of_not_predifined_variable += 1 |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
249 |
|
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
250 |
if len_of_not_predifined_variable>1 : suffix = str(base) |
14
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
251 |
else: suffix = '' |
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
252 |
|
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
253 |
for param_type in decl: |
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
254 |
predifined_variable_param_type = variables.get(param_type,None) |
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
255 |
if predifined_variable_param_type : |
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
256 |
param_types.append(predifined_variable_param_type) |
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
257 |
param_names.append(param_type) |
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
258 |
else: |
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
259 |
param_types.append(param_type) |
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
260 |
param_names.append("IN"+suffix) |
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
261 |
base+=1 |
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
262 |
suffix = str(base) |
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
263 |
|
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
264 |
modifiers = ["none"]*len(param_types) |
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
265 |
return zip(param_names,param_types,modifiers) |
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
266 |
|
15 | 267 |
""" |
268 |
Fillin the PLCOpenEditor standard function dictionnary |
|
269 |
translate input and output declaration to something more pythonesque |
|
270 |
and add interface description to comment |
|
271 |
""" |
|
14
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
272 |
def decl_function(dico_from_table, variables): |
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
273 |
Function_decl = { "type" : "function" } |
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
274 |
for field, val in dico_from_table: |
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
275 |
translate = { |
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
276 |
"baseinputnumber" : lambda x:int(x), |
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
277 |
"extensible" : lambda x: {"yes":True, "no":False}[x], |
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
278 |
"inputs" : lambda x:csv_input_translate(x,variables,Function_decl.get("baseinputnumber",1)), |
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
279 |
"outputs":lambda x:[("OUT",x,"none")]} |
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
280 |
Function_decl[field] = translate.get(field,lambda x:x)(val) |
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
281 |
return Function_decl |
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
282 |
|
18
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
283 |
|
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
284 |
def ANY_TO_ANY_FORMAT_GEN(fdecl): |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
285 |
|
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
286 |
ANY_T0_ANY_LIST=[ |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
287 |
(("ANY_NUM","ANY_BIT"),("ANY_NUM","ANY_BIT"), "(%(return_type)s)%(IN_value)s"), |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
288 |
(("ANY_NUM","ANY_BIT"),("ANY_DATE","TIME"), "(%(return_type)s)real_to_time(%(IN_value)s)"), |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
289 |
(("ANY_DATE","TIME"), ("ANY_NUM","ANY_BIT"), "(%(return_type)s)time_to_real(%(IN_value)s)"), |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
290 |
(("ANY_DATE","TIME"), ("ANY_STRING",), "(%(return_type)s)time_to_string(%(IN_value)s)"), |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
291 |
(("ANY_STRING",), ("ANY_DATE","TIME"), "(%(return_type)s)string_to_time(%(IN_value)s)"), |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
292 |
(("ANY_BIT",), ("ANY_STRING",), "(%(return_type)s)int_to_string(%(IN_value)s, 16)"), |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
293 |
(("ANY_NUM",), ("ANY_STRING",), "(%(return_type)s)int_to_string(%(IN_value)s, 10)"), |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
294 |
(("ANY_STRING",), ("ANY_BIT",), "(%(return_type)s)string_to_int(%(IN_value)s, 16)"), |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
295 |
(("ANY_STRING",), ("ANY_NUM",), "(%(return_type)s)string_to_int(%(IN_value)s, 10)")] |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
296 |
|
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
297 |
for (InTypes, OutTypes, Format) in ANY_T0_ANY_LIST: |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
298 |
inps = reduce(lambda a,b: a or b, map(lambda testtype : IsOfType(fdecl["outputs"][0][1],testtype), InTypes)) |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
299 |
#print "IN ",inps , fdecl["outputs"][0][1], InTypes |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
300 |
outs = reduce(lambda a,b: a or b, map(lambda testtype : IsOfType(fdecl["inputs"][0][1],testtype), OutTypes)) |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
301 |
#print "OUT ",outs , fdecl["inputs"][0][1], OutTypes |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
302 |
if (inps and outs ): |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
303 |
return Format |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
304 |
|
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
305 |
#print "IN:", fdecl["outputs"][0][1], " OUT:", fdecl["inputs"][0][1] |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
306 |
|
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
307 |
return "#error %s_TO_%s not implemented!"%(fdecl["inputs"][0][1],fdecl["outputs"][0][1]) |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
308 |
|
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
309 |
|
15 | 310 |
""" |
311 |
Returns this kind of declaration for all standard functions |
|
312 |
||
313 |
[{"name" : "Numerical", 'list': [ { |
|
314 |
'baseinputnumber': 1, |
|
315 |
'comment': 'Addition', |
|
316 |
'extensible': True, |
|
317 |
'inputs': [ ('IN1', 'ANY_NUM', 'none'), |
|
318 |
('IN2', 'ANY_NUM', 'none')], |
|
319 |
'name': 'ADD', |
|
320 |
'outputs': [('OUT', 'ANY_NUM', 'none')], |
|
321 |
'type': 'function'}, ...... ] },.....] |
|
322 |
""" |
|
14
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
323 |
def get_standard_funtions(table): |
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
324 |
|
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
325 |
variables = get_standard_funtions_input_variables(table) |
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
326 |
|
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
327 |
fonctions = find_section("Standard_functions_type",table) |
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
328 |
|
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
329 |
Standard_Functions_Decl = [] |
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
330 |
Current_section = None |
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
331 |
for fields in table: |
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
332 |
if fields[1]: |
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
333 |
# If function section name given |
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
334 |
if fields[0] : |
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
335 |
if Current_section: |
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
336 |
Standard_Functions_Decl.append(Current_section) |
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
337 |
Current_section = { "name" : fields[0], "list" : [] } |
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
338 |
Function_decl_list = [] |
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
339 |
|
18
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
340 |
dico_from_table = [ (champ,val) for champ,val in zip(fonctions, fields[1:]) if champ ] |
14
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
341 |
Function_decl = decl_function(dico_from_table,variables) |
18
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
342 |
if Function_decl["name"].startswith('*') : |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
343 |
input_types = [ GetSubTypes(inpdecl[1]) for inpdecl in Function_decl["inputs"] ] |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
344 |
input_ovrloading_types = input_types[map(len,input_types).index(max(map(len,input_types)))] |
14
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
345 |
else: |
18
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
346 |
input_ovrloading_types = [None] |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
347 |
|
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
348 |
if Function_decl["name"].endswith('*') : |
14
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
349 |
output_types = GetSubTypes(Function_decl["outputs"][0][1]) |
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
350 |
else: |
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
351 |
output_types = [None] |
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
352 |
|
18
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
353 |
funcdeclname_orig = Function_decl["name"] |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
354 |
funcdeclname = Function_decl["name"].strip('*_') |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
355 |
fdc = Function_decl["inputs"][:] |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
356 |
for intype in input_ovrloading_types: |
14
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
357 |
if intype != None: |
18
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
358 |
Function_decl["inputs"] = [] |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
359 |
for decl_tpl in fdc: |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
360 |
if IsOfType(intype, decl_tpl[1]): |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
361 |
Function_decl["inputs"] += [(decl_tpl[0], intype, decl_tpl[2])] |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
362 |
else: |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
363 |
Function_decl["inputs"] += [(decl_tpl)] |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
364 |
|
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
365 |
if funcdeclname_orig.startswith('*'): |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
366 |
funcdeclin = intype + '_' + funcdeclname |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
367 |
else: |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
368 |
funcdeclin = funcdeclname |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
369 |
else: |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
370 |
funcdeclin = funcdeclname |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
371 |
|
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
372 |
|
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
373 |
if Function_decl["return_type_rule"] == "copy_input": |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
374 |
output_types = [intype] |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
375 |
elif Function_decl["return_type_rule"] == "defined": |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
376 |
pass |
14
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
377 |
|
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
378 |
for outype in output_types: |
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
379 |
if outype != None: |
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
380 |
decl_tpl = Function_decl["outputs"][0] |
18
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
381 |
Function_decl["outputs"] = [ (decl_tpl[0] , outype, decl_tpl[2])] |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
382 |
if funcdeclname_orig.endswith('*'): |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
383 |
funcdeclout = funcdeclin + '_' + outype |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
384 |
else: |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
385 |
funcdeclout = funcdeclin |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
386 |
else: |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
387 |
funcdeclout = funcdeclin |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
388 |
Function_decl["name"] = funcdeclout |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
389 |
|
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
390 |
|
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
391 |
try: |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
392 |
fdecl = Function_decl |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
393 |
res = eval(Function_decl["python_eval_c_code_format"]) |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
394 |
except Exception,e: |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
395 |
res = None |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
396 |
|
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
397 |
if res != None : |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
398 |
# create the copy of decl dict to be appended to section |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
399 |
Function_decl_copy = Function_decl.copy() |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
400 |
# Have to generate type description in comment with freshly redefined types |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
401 |
Function_decl_copy["comment"] += ( |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
402 |
"\n (" + |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
403 |
str([ " " + fctdecl[1]+":"+fctdecl[0] for fctdecl in Function_decl["inputs"]]).strip("[]").replace("'",'') + |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
404 |
" ) => (" + |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
405 |
str([ " " + fctdecl[1]+":"+fctdecl[0] for fctdecl in Function_decl["outputs"]]).strip("[]").replace("'",'') + |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
406 |
" )") |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
407 |
Current_section["list"].append(Function_decl_copy) |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
408 |
#pp.pprint(Function_decl_copy) |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
409 |
|
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
410 |
Standard_Functions_Decl.append(Current_section) |
14
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
411 |
|
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
412 |
return Standard_Functions_Decl |
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
413 |
|
0 | 414 |
#------------------------------------------------------------------------------- |
9 | 415 |
# Test identifier |
416 |
#------------------------------------------------------------------------------- |
|
417 |
||
418 |
||
419 |
||
420 |
# Test if identifier is valid |
|
421 |
def TestIdentifier(identifier): |
|
422 |
if identifier[0].isdigit(): |
|
423 |
return False |
|
424 |
words = identifier.split('_') |
|
425 |
for i, word in enumerate(words): |
|
426 |
if len(word) == 0 and i != 0: |
|
427 |
return False |
|
428 |
if len(word) != 0 and not word.isalnum(): |
|
429 |
return False |
|
430 |
return True |
|
431 |
||
432 |
#------------------------------------------------------------------------------- |
|
0 | 433 |
# Languages Keywords |
434 |
#------------------------------------------------------------------------------- |
|
435 |
||
436 |
||
437 |
||
438 |
# Keywords for Pou Declaration |
|
439 |
POU_KEYWORDS = ["FUNCTION", "END_FUNCTION", "FUNCTION_BLOCK", "END_FUNCTION_BLOCK", |
|
440 |
"PROGRAM", "END_PROGRAM", "EN", "ENO", "F_EDGE", "R_EDGE"] |
|
441 |
for category in BlockTypes: |
|
442 |
for block in category["list"]: |
|
443 |
if block["name"] not in POU_KEYWORDS: |
|
444 |
POU_KEYWORDS.append(block["name"]) |
|
445 |
||
446 |
||
447 |
# Keywords for Type Declaration |
|
448 |
TYPE_KEYWORDS = ["TYPE", "END_TYPE", "STRUCT", "END_STRUCT", "ARRAY", "OF", "T", |
|
449 |
"D", "TIME_OF_DAY", "DATE_AND_TIME"] |
|
450 |
TYPE_KEYWORDS.extend([keyword for keyword in TypeHierarchy.keys() if keyword not in TYPE_KEYWORDS]) |
|
451 |
||
452 |
||
453 |
# Keywords for Variable Declaration |
|
454 |
VAR_KEYWORDS = ["VAR", "VAR_INPUT", "VAR_OUTPUT", "VAR_IN_OUT", "VAR_TEMP", |
|
455 |
"VAR_EXTERNAL", "END_VAR", "AT", "CONSTANT", "RETAIN", "NON_RETAIN"] |
|
456 |
||
457 |
||
458 |
# Keywords for Configuration Declaration |
|
459 |
CONFIG_KEYWORDS = ["CONFIGURATION", "END_CONFIGURATION", "RESOURCE", "ON", "END_RESOURCE", |
|
460 |
"PROGRAM", "WITH", "READ_ONLY", "READ_WRITE", "TASK", "VAR_ACCESS", "VAR_CONFIG", |
|
461 |
"VAR_GLOBAL", "END_VAR"] |
|
462 |
||
463 |
||
464 |
# Keywords for Structured Function Chart |
|
465 |
SFC_KEYWORDS = ["ACTION", "END_ACTION", "INITIAL_STEP", "STEP", "END_STEP", "TRANSITION", |
|
466 |
"FROM", "TO", "END_TRANSITION"] |
|
467 |
||
468 |
||
469 |
# Keywords for Instruction List |
|
470 |
IL_KEYWORDS = ["LD", "LDN", "ST", "STN", "S", "R", "AND", "ANDN", "OR", "ORN", |
|
471 |
"XOR", "XORN", "NOT", "ADD", "SUB", "MUL", "DIV", "MOD", "GT", "GE", "EQ", "NE", |
|
472 |
"LE", "LT", "JMP", "JMPC", "JMPNC", "CAL", "CALC", "CALNC", "RET", "RETC", "RETNC"] |
|
473 |
||
474 |
||
475 |
# Keywords for Instruction List and Structured Text |
|
476 |
ST_KEYWORDS = ["IF", "THEN", "ELSIF", "ELSE", "END_IF", "CASE", "OF", "END_CASE", |
|
477 |
"FOR", "TO", "BY", "DO", "END_FOR", "WHILE", "DO", "END_WHILE", "REPEAT", "UNTIL", |
|
478 |
"END_REPEAT", "EXIT", "RETURN", "NOT", "MOD", "AND", "XOR", "OR"] |
|
479 |
||
480 |
||
481 |
# All the keywords of IEC |
|
482 |
IEC_KEYWORDS = ["E", "TRUE", "FALSE"] |
|
483 |
IEC_KEYWORDS.extend([keyword for keyword in POU_KEYWORDS if keyword not in IEC_KEYWORDS]) |
|
484 |
IEC_KEYWORDS.extend([keyword for keyword in TYPE_KEYWORDS if keyword not in IEC_KEYWORDS]) |
|
485 |
IEC_KEYWORDS.extend([keyword for keyword in VAR_KEYWORDS if keyword not in IEC_KEYWORDS]) |
|
486 |
IEC_KEYWORDS.extend([keyword for keyword in CONFIG_KEYWORDS if keyword not in IEC_KEYWORDS]) |
|
487 |
IEC_KEYWORDS.extend([keyword for keyword in SFC_KEYWORDS if keyword not in IEC_KEYWORDS]) |
|
488 |
IEC_KEYWORDS.extend([keyword for keyword in IL_KEYWORDS if keyword not in IEC_KEYWORDS]) |
|
489 |
IEC_KEYWORDS.extend([keyword for keyword in ST_KEYWORDS if keyword not in IEC_KEYWORDS]) |
|
490 |
||
15 | 491 |
if __name__ == '__main__': |
18
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
492 |
|
15 | 493 |
import pprint |
494 |
pp = pprint.PrettyPrinter(indent=4) |
|
18
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
495 |
|
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
496 |
def ANY_to_compiler_test_type_GEN(typename, paramname): |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
497 |
return {"ANY" : "", |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
498 |
"ANY_BIT" : "if(search_expression_type->is_binary_type(%(paramname)s_param_value))", |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
499 |
"ANY_NUM" : "if(search_expression_type->is_num_type(%(paramname)s_param_value))", |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
500 |
"ANY_REAL" : "if(search_expression_type->is_real_type(%(paramname)s_param_value))", |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
501 |
"ANY_INT" : "if(search_expression_type->is_integer_type(%(paramname)s_param_value))" |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
502 |
}.get(typename, |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
503 |
"if (typeid(*last_type_symbol) == typeid(%(typename)s_type_name_c))")%{ |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
504 |
"paramname" : paramname, "typename": typename.lower()} |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
505 |
|
19
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
506 |
def recurse_and_indent(fdecls, indent, do_type_search_only = False): |
18
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
507 |
if type(fdecls) != type(tuple()): |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
508 |
res = "" |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
509 |
for Paramname, ParamTypes in fdecls.iteritems(): |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
510 |
res += (""" |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
511 |
{ |
19
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
512 |
identifier_c param_name("%(input_name)s"); |
18
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
513 |
/* Get the value from a foo(<param_name> = <param_value>) style call */ |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
514 |
symbol_c *%(input_name)s_param_value = function_call_param_iterator.search(¶m_name); |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
515 |
|
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
516 |
/* Get the value from a foo(<param_value>) style call */ |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
517 |
if (%(input_name)s_param_value == NULL) |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
518 |
%(input_name)s_param_value = function_call_param_iterator.next(); |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
519 |
symbol_c *%(input_name)s_type_symbol = search_expression_type->get_type(%(input_name)s_param_value); |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
520 |
last_type_symbol = last_type_symbol && search_expression_type->is_same_type(%(input_name)s_type_symbol, last_type_symbol) ? search_expression_type->common_type(%(input_name)s_type_symbol, last_type_symbol) : %(input_name)s_type_symbol ; |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
521 |
"""%{"input_name":Paramname}) |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
522 |
|
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
523 |
for ParamType,NextParamDecl in ParamTypes.iteritems(): |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
524 |
|
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
525 |
res += (""" |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
526 |
%(type_test)s |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
527 |
{ |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
528 |
%(if_good_type_code)s |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
529 |
} |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
530 |
"""%{ |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
531 |
"type_test":ANY_to_compiler_test_type_GEN(ParamType,Paramname), |
19
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
532 |
"if_good_type_code":recurse_and_indent(NextParamDecl,indent,do_type_search_only).replace('\n','\n ')}) |
18
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
533 |
|
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
534 |
res += """ |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
535 |
ERROR; |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
536 |
} |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
537 |
""" |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
538 |
|
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
539 |
return res.replace('\n','\n'+indent) |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
540 |
else: |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
541 |
res = "\n" |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
542 |
fdecl=fdecls[0] |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
543 |
|
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
544 |
result_type_rule = fdecl["return_type_rule"] |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
545 |
res += { |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
546 |
"copy_input" : "symbol_c * return_type_symbol = last_type_symbol;\n", |
19
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
547 |
"defined" : "symbol_c * return_type_symbol = &search_constant_type_c::%s_type_name;\n"%fdecl["outputs"][0][1].lower(), |
18
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
548 |
}.get(result_type_rule, "symbol_c * return_type_symbol = %s;\n"%result_type_rule) |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
549 |
|
19
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
550 |
if not do_type_search_only: |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
551 |
try: |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
552 |
code_gen = eval(fdecl["python_eval_c_code_format"]) |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
553 |
except Exception: |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
554 |
code_gen = "#error in eval of " + fdecl["name"] |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
555 |
|
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
556 |
code_gen_dic_decl = {} |
18
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
557 |
for paramname,paramtype,unused in fdecl["inputs"]: |
19
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
558 |
code_gen_dic_decl[paramname+"_value"] = '");\n%s_param_value->accept(*this);\ns4o.print("'%(paramname) |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
559 |
code_gen_dic_decl[paramname+"_type"] = '");\n%s_type_symbol->accept(*this);\ns4o.print("'%(paramname) |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
560 |
code_gen_dic_decl["return_type"] = '");\nreturn_type_symbol->accept(*this);\ns4o.print("' |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
561 |
code_gen_dic_decl["param_count"] = '");\ns4o.print_integer(nb_param);\ns4o.print("' |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
562 |
|
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
563 |
if type(code_gen) == type(tuple()): |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
564 |
res += 's4o.print("%s");\n'%(code_gen[0]%code_gen_dic_decl) |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
565 |
static_param_accept_list = [] |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
566 |
for paramname,paramtype,unused in fdecl["inputs"]: |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
567 |
static_param_accept_list.append("%s_param_value->accept(*this);\n"%(paramname)) |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
568 |
res += ('s4o.print("%s");\n'%(code_gen[1])).join(static_param_accept_list) |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
569 |
code = 's4o.print("%s");\nparam_value->accept(*this);\n'%(code_gen[1]) |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
570 |
end_code = 's4o.print("%s");\nreturn NULL;\n'%(code_gen[2]) |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
571 |
else: |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
572 |
code = '' |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
573 |
end_code = ('s4o.print("' + code_gen%code_gen_dic_decl + '");\nreturn NULL;\n').replace('s4o.print("");\n','') |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
574 |
|
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
575 |
if fdecl["extensible"]: |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
576 |
res += (""" |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
577 |
int base_num = %d; |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
578 |
symbol_c *param_value = NULL; |
18
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
579 |
do{ |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
580 |
char my_name[10]; |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
581 |
sprintf(my_name, "IN%%d", base_num++); |
19
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
582 |
identifier_c param_name(my_name); |
18
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
583 |
|
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
584 |
/* Get the value from a foo(<param_name> = <param_value>) style call */ |
19
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
585 |
param_value = function_call_param_iterator.search(¶m_name); |
18
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
586 |
|
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
587 |
/* Get the value from a foo(<param_value>) style call */ |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
588 |
if (param_value == NULL) |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
589 |
param_value = function_call_param_iterator.next(); |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
590 |
if (param_value != NULL){ |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
591 |
symbol_c *current_type_symbol = search_expression_type->get_type(param_value); |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
592 |
last_type_symbol = last_type_symbol && search_expression_type->is_same_type(current_type_symbol, last_type_symbol) ? search_expression_type->common_type(current_type_symbol, last_type_symbol) : current_type_symbol ; |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
593 |
|
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
594 |
/*Function specific CODE */ |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
595 |
%s |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
596 |
} |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
597 |
|
19
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
598 |
}while(param_value != NULL); |
18
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
599 |
%s |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
600 |
"""%(fdecl["baseinputnumber"]+2, code.replace('\n','\n '), end_code)) |
19
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
601 |
else: |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
602 |
#res += code + end_code |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
603 |
res += end_code |
18
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
604 |
else: |
19
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
605 |
res += "return return_type_symbol;\n" |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
606 |
|
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
607 |
|
18
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
608 |
return res.replace('\n','\n'+indent) |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
609 |
|
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
610 |
################################################################### |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
611 |
### ### |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
612 |
### MAIN ### |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
613 |
### ### |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
614 |
################################################################### |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
615 |
|
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
616 |
# Get definitions |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
617 |
std_decl = get_standard_funtions(csv_file_to_table(open("iec_std.csv")))#, True) |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
618 |
|
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
619 |
# Reorganize into a dict of dict, according |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
620 |
# fname : paramname : paramtype : paraname : paramtype... |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
621 |
# Keep ptrack of original order in a separated list |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
622 |
std_fdecls = {} |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
623 |
official_order = [] |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
624 |
for section in std_decl: |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
625 |
for fdecl in section["list"]: |
19
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
626 |
if len(official_order)==0 or official_order[-1] != fdecl["name"]: |
18
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
627 |
official_order.append(fdecl["name"]) |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
628 |
# store all func by name in a dict |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
629 |
std_fdecls_fdecl_name = std_fdecls.get(fdecl["name"], {}) |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
630 |
current = std_fdecls_fdecl_name |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
631 |
for i in fdecl["inputs"]: |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
632 |
current[i[0]] = current.get(i[0], {}) |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
633 |
current = current[i[0]] |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
634 |
last = current |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
635 |
current[i[1]] = current.get(i[1], {}) |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
636 |
current = current[i[1]] |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
637 |
last[i[1]]=(fdecl,) |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
638 |
std_fdecls[fdecl["name"]] = std_fdecls_fdecl_name |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
639 |
|
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
640 |
# Generate the long enumeration of std function types |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
641 |
function_type_decl = """ |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
642 |
/**** |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
643 |
* IEC 61131-3 standard function lib |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
644 |
* generated code, do not edit by hand |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
645 |
*/ |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
646 |
typedef enum { |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
647 |
""" |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
648 |
for fname, fdecls in [ (fname,std_fdecls[fname]) for fname in official_order ]: |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
649 |
function_type_decl += " function_"+fname.lower()+",\n" |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
650 |
|
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
651 |
function_type_decl += """ function_none |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
652 |
} function_type_t; |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
653 |
""" |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
654 |
|
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
655 |
# Generate the funct thaat return enumerated according function name |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
656 |
get_function_type_decl = """ |
19
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
657 |
/**** |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
658 |
* IEC 61131-3 standard function lib |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
659 |
* generated code, do not edit by hand |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
660 |
*/ |
18
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
661 |
function_type_t get_function_type(identifier_c *function_name) { |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
662 |
""" |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
663 |
for fname, fdecls in [ (fname,std_fdecls[fname]) for fname in official_order ]: |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
664 |
get_function_type_decl += """ |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
665 |
if (!strcasecmp(function_name->value, "%s")) |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
666 |
return function_%s; |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
667 |
"""%(fname,fname.lower()) |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
668 |
|
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
669 |
get_function_type_decl += """ |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
670 |
else return function_none; |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
671 |
} |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
672 |
|
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
673 |
""" |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
674 |
|
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
675 |
# Generate the part of generate_cc_st_c::visit(function_invocation) |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
676 |
# that is responsible to generate C code for std lib calls. |
19
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
677 |
st_code_gen = """ |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
678 |
/**** |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
679 |
* IEC 61131-3 standard function lib |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
680 |
* generated code, do not edit by hand |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
681 |
*/ |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
682 |
switch(current_function_type){ |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
683 |
""" |
18
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
684 |
|
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
685 |
for fname, fdecls in [ (fname,std_fdecls[fname]) for fname in official_order ]: |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
686 |
st_code_gen += """ |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
687 |
/**** |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
688 |
*%s |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
689 |
*/ |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
690 |
case function_%s : |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
691 |
{ |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
692 |
symbol_c *last_type_symbol = NULL; |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
693 |
""" %(fname, fname.lower()) |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
694 |
indent = " " |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
695 |
|
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
696 |
st_code_gen += recurse_and_indent(fdecls, indent).replace('\n','\n ') |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
697 |
|
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
698 |
st_code_gen += """ |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
699 |
}/*function_%s*/ |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
700 |
break; |
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
701 |
""" %(fname.lower()) |
19
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
702 |
st_code_gen += """ |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
703 |
case function_none : |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
704 |
ERROR; |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
705 |
} |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
706 |
return NULL; |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
707 |
""" |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
708 |
|
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
709 |
|
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
710 |
# Generate the part of search_expression_type_c::visit(function_invocation) |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
711 |
# that is responsible of returning type symbol for function invocation. |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
712 |
search_type_code = """ |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
713 |
/**** |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
714 |
* IEC 61131-3 standard function lib |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
715 |
* generated code, do not edit by hand |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
716 |
*/ |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
717 |
switch(current_function_type){ |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
718 |
""" |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
719 |
|
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
720 |
for fname, fdecls in [ (fname,std_fdecls[fname]) for fname in official_order ]: |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
721 |
search_type_code += """ |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
722 |
/**** |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
723 |
*%s |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
724 |
*/ |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
725 |
case function_%s : |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
726 |
{ |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
727 |
symbol_c *last_type_symbol = NULL; |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
728 |
""" %(fname, fname.lower()) |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
729 |
indent = " " |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
730 |
|
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
731 |
search_type_code += recurse_and_indent(fdecls, indent, True).replace('\n','\n ') |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
732 |
|
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
733 |
search_type_code += """ |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
734 |
}/*function_%s*/ |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
735 |
break; |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
736 |
""" %(fname.lower()) |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
737 |
search_type_code += """ |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
738 |
case function_none : |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
739 |
ERROR; |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
740 |
} |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
741 |
return NULL; |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
742 |
""" |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
743 |
|
18
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
744 |
|
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
745 |
# Now, print that out, or write to files from sys.argv |
19
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
746 |
for name, ext in [ |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
747 |
('function_type_decl','h'), |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
748 |
('get_function_type_decl','c'), |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
749 |
('st_code_gen','c'), |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
750 |
('search_type_code','c')]: |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
751 |
fd = open(os.path.join(sys.argv[1],name+'.'+ext),'w') |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
752 |
fd.write(eval(name)) |
0b499416ebd7
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
18
diff
changeset
|
753 |
fd.close() |
15 | 754 |
else: |
755 |
# Put standard functions declaration in Bloktypes |
|
756 |
BlockTypes.extend(get_standard_funtions(csv_file_to_table(open(os.path.join(sys.path[0], "plcopen/iec_std.csv"))))) |
|
757 |