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