aboutsummaryrefslogtreecommitdiffstats
path: root/awlsim/core/parameters.py
blob: 508945ca39bb508611d8c0ea0bd1728209ec7a31 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# -*- coding: utf-8 -*-
#
# AWL simulator - call parameters
#
# Copyright 2013-2016 Michael Buesch <m@bues.ch>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#

from __future__ import division, absolute_import, print_function, unicode_literals
from awlsim.common.compat import *

#from awlsim.core.dynattrs cimport * #@cy

from awlsim.core.datastructure import *
from awlsim.core.datablocks import *
from awlsim.core.blocks import *
from awlsim.core.util import *
from awlsim.core.dynattrs import * #@nocy


class AwlParamAssign(DynAttrs):
	"Parameter assignment for CALL"

	dynAttrs = {
		# isInbound attribute is True, if this is an
		# IN or IN_OUT parameter assignment.
		"isInbound"	: lambda self, name: self.__isInbound(),

		# isOutbound attribute is True, if this is an
		# OUT or IN_OUT parameter assignment.
		"isOutbound"	: lambda self, name: self.__isOutbound(),

		# lValueDataType attribute is the AwlDataType of the
		# parameter's l-value.
		"lValueDataType"	: lambda self, name: self.__lValueDataType(),

		# lValueStructField attribute is the AwlStructField corresponding
		# to this parameter's l-value.
		"lValueStructField"	: lambda self, name: self.__lValueStructField(),

		# interfaceFieldIndex attribute is the index number for the
		# parameter assignment l-value in the block interface refs.
		"interfaceFieldIndex"	: lambda self, name: self.__interfaceFieldIndex(),

		# scratchSpaceOp attribute holds the possible AwlOperator for
		# scratch space allocation.
		"scratchSpaceOp"	: None,
	}

	def __init__(self, lvalueName, rvalueOp):
		# A parameter assignment consists of an lvalue and an rvalue:
		#  LVALUE := RVALUE
		# 'lvalueName' is the name string of the lvalue.
		# 'rvalueOp' is the AwlOperator that represents the rvalue.
		self.lvalueName = lvalueName
		self.rvalueOp = rvalueOp
		# 'interface' is the BlockInterface of the called block.
		# This element is assigned later in the translation phase.
		self.interface = None

	def __eq__(self, other):
		return (self is other) or (\
			isinstance(other, AwlParamAssign) and\
			self.lvalueName == other.lvalueName and\
			self.rvalueOp == other.rvalueOp and\
			super(AwlParamAssign, self).__eq__(other)\
		)

	def __ne__(self, other):
		return not self.__eq__(other)

	def __isInbound(self):
		field = self.interface.getFieldByName(self.lvalueName)
		return field.fieldType == BlockInterfaceField.FTYPE_IN or\
		       field.fieldType == BlockInterfaceField.FTYPE_INOUT

	def __isOutbound(self):
		field = self.interface.getFieldByName(self.lvalueName)
		return field.fieldType == BlockInterfaceField.FTYPE_OUT or\
		       field.fieldType == BlockInterfaceField.FTYPE_INOUT

	def __lValueStructField(self):
		# Find the l-value struct field
		return self.interface.struct.getField(self.lvalueName)

	def __lValueDataType(self):
		# Get the l-value data type
		return self.interface.getFieldByName(self.lvalueName).dataType

	def __interfaceFieldIndex(self):
		# Find the index number for the l-value
		return self.interface.getFieldByName(self.lvalueName).fieldIndex

	def __repr__(self):
		return "%s := %s" % (self.lvalueName, str(self.rvalueOp))
bues.ch cgit interface