MethodCallExprAST.py (6780:2d3fc2e6f368) MethodCallExprAST.py (6882:898047a3672c)
1# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
2# Copyright (c) 2009 The Hewlett-Packard Development Company
3# All rights reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions are
7# met: redistributions of source code must retain the above copyright
8# notice, this list of conditions and the following disclaimer;

--- 54 unchanged lines hidden (view full) ---

63 # Right number of parameters
64 self.error("Wrong number of parameters for function name: '%s', " + \
65 "expected: , actual: ", proc_name,
66 len(obj_type.methods[methodId].param_types),
67 len(self.expr_ast_vec))
68
69 for actual_type, expected_type in \
70 zip(paramTypes, obj_type.methods[methodId].param_types):
1# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
2# Copyright (c) 2009 The Hewlett-Packard Development Company
3# All rights reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions are
7# met: redistributions of source code must retain the above copyright
8# notice, this list of conditions and the following disclaimer;

--- 54 unchanged lines hidden (view full) ---

63 # Right number of parameters
64 self.error("Wrong number of parameters for function name: '%s', " + \
65 "expected: , actual: ", proc_name,
66 len(obj_type.methods[methodId].param_types),
67 len(self.expr_ast_vec))
68
69 for actual_type, expected_type in \
70 zip(paramTypes, obj_type.methods[methodId].param_types):
71 if actual_type != expected_type:
71 if actual_type != expected_type and \
72 str(actual_type["interface"]) != str(expected_type):
72 self.error("Type mismatch: expected: %s actual: %s",
73 expected_type, actual_type)
74
75 # Return the return type of the method
76 return obj_type.methods[methodId].return_type
77
78 def findResources(self, resources):
79 pass

--- 12 unchanged lines hidden (view full) ---

92 def generate_prefix(self, paramTypes):
93 code = code_formatter()
94
95 # member method call
96 obj_type = self.obj_expr_ast.generate(code)
97 methodId = obj_type.methodId(self.proc_name, paramTypes)
98
99 prefix = ""
73 self.error("Type mismatch: expected: %s actual: %s",
74 expected_type, actual_type)
75
76 # Return the return type of the method
77 return obj_type.methods[methodId].return_type
78
79 def findResources(self, resources):
80 pass

--- 12 unchanged lines hidden (view full) ---

93 def generate_prefix(self, paramTypes):
94 code = code_formatter()
95
96 # member method call
97 obj_type = self.obj_expr_ast.generate(code)
98 methodId = obj_type.methodId(self.proc_name, paramTypes)
99
100 prefix = ""
101 implements_interface = False
100 if methodId not in obj_type.methods:
102 if methodId not in obj_type.methods:
101 self.error("Invalid method call: Type '%s' does not have a method '%s'",
102 obj_type, methodId)
103 #
104 # The initial method check has failed, but before generating an
105 # error we must check whether any of the paramTypes implement
106 # an interface. If so, we must check if the method ids using
107 # the inherited types exist.
108 #
109 # This code is a temporary fix and only checks for the methodId
110 # where all paramTypes are converted to their inherited type. The
111 # right way to do this is to replace slicc's simple string
112 # comparison for determining the correct overloaded method, with a
113 # more robust param by param check.
114 #
115 implemented_paramTypes = []
116 for paramType in paramTypes:
117 implemented_paramType = paramType
118 if paramType.isInterface:
119 implements_interface = True
120 implemented_paramType.abstract_ident = paramType["interface"]
121 else:
122 implemented_paramType.abstract_ident = paramType.c_ident
123
124 implemented_paramTypes.append(implemented_paramType)
125
126 if implements_interface:
127 implementedMethodId = obj_type.methodIdAbstract(self.proc_name,
128 implemented_paramTypes)
129 else:
130 implementedMethodId = ""
131
132 if implementedMethodId not in obj_type.methods:
133 self.error("Invalid method call: " \
134 "Type '%s' does not have a method '%s' nor '%s'",
135 obj_type, methodId, implementedMethodId)
136 else:
137 #
138 # Replace the methodId with the implementedMethodId found in
139 # the method list.
140 #
141 methodId = implementedMethodId
142
103 return_type = obj_type.methods[methodId].return_type
104 if return_type.isInterface:
105 prefix = "static_cast<%s &>" % return_type.c_ident
106 prefix = "%s((%s)." % (prefix, code)
107
108 return obj_type, methodId, prefix
109
110

--- 20 unchanged lines hidden ---
143 return_type = obj_type.methods[methodId].return_type
144 if return_type.isInterface:
145 prefix = "static_cast<%s &>" % return_type.c_ident
146 prefix = "%s((%s)." % (prefix, code)
147
148 return obj_type, methodId, prefix
149
150

--- 20 unchanged lines hidden ---