summaryrefslogtreecommitdiffstats
path: root/awlparameters.py
blob: ee160f5af318a10ad610c2fe2a31e7e4d2adb151 (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
# -*- coding: utf-8 -*-
#
# AWL simulator - call parameters
# Copyright 2013 Michael Buesch <m@bues.ch>
#
# Licensed under the terms of the GNU General Public License version 2.
#

from awlblocks import *
from util import *


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

	DIR_UNKNOWN	= -1	# magic value: Unknown direction
	DIR_IN		= 0x1	# in-bitmask
	DIR_OUT		= 0x2	# out-bitmask

	def __init__(self, lvalueName, rvalueOp):
		self.lvalueName = lvalueName
		self.rvalueOp = rvalueOp
		self.direction = self.DIR_UNKNOWN

	def __setDirection(self, interface):
		self.direction = 0
		field = interface.getFieldByName(self.lvalueName)
		if field.fieldType == BlockInterface.Field.FTYPE_IN or\
		   field.fieldType == BlockInterface.Field.FTYPE_INOUT:
			self.direction |= self.DIR_IN
		if field.fieldType == BlockInterface.Field.FTYPE_OUT or\
		   field.fieldType == BlockInterface.Field.FTYPE_INOUT:
			self.direction |= self.DIR_OUT

	def isInbound(self, interface):
		if self.direction == self.DIR_UNKNOWN:
			self.__setDirection(interface)
		return self.direction & self.DIR_IN

	def isOutbound(self, interface):
		if self.direction == self.DIR_UNKNOWN:
			self.__setDirection(interface)
		return self.direction & self.DIR_OUT

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