1 /******************************************************************************
2 * Copyright (c) 2000-2016 Ericsson Telecom AB
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
12 ******************************************************************************/
13 #include "SigParam.hh"
16 #include "CompilerError.hh"
20 // =================================
21 // ===== SignatureParam
22 // =================================
24 SignatureParam::SignatureParam(param_direction_t p_d
, Type
*p_t
,
26 : param_direction(p_d
), param_type(p_t
), param_id(p_i
)
28 if (!p_t
|| !p_i
) FATAL_ERROR("SignatureParam::SignatureParam()");
29 param_type
->set_ownertype(Type::OT_SIG_PAR
, this);
32 SignatureParam::~SignatureParam()
38 SignatureParam
*SignatureParam::clone() const
40 FATAL_ERROR("SignatureParam::clone");
43 void SignatureParam::set_fullname(const string
& p_fullname
)
45 Node::set_fullname(p_fullname
);
46 param_type
->set_fullname(p_fullname
);
49 void SignatureParam::set_my_scope(Scope
*p_scope
)
51 param_type
->set_my_scope(p_scope
);
54 void SignatureParam::dump(unsigned level
) const
56 switch(param_direction
) {
57 case PARAM_IN
: DEBUG(level
,"in"); break;
58 case PARAM_OUT
: DEBUG(level
,"out"); break;
59 case PARAM_INOUT
: DEBUG(level
,"inout");break;
60 default: FATAL_ERROR("SignatureParam::dump()"); break;
62 param_type
->dump(level
+1);
63 param_id
->dump(level
+2);
66 // =================================
67 // ===== SignatureParamList
68 // =================================
70 SignatureParamList::~SignatureParamList()
72 for (size_t i
= 0; i
< params_v
.size(); i
++) delete params_v
[i
];
79 SignatureParamList
*SignatureParamList::clone() const
81 FATAL_ERROR("SignatureParam::clone");
84 void SignatureParamList::set_fullname(const string
& p_fullname
)
86 Node::set_fullname(p_fullname
);
87 for (size_t i
= 0; i
< params_v
.size(); i
++) {
88 SignatureParam
*param
= params_v
[i
];
89 param
->set_fullname(p_fullname
+ "." + param
->get_id().get_dispname());
93 void SignatureParamList::set_my_scope(Scope
*p_scope
)
95 for (size_t i
= 0; i
< params_v
.size(); i
++)
96 params_v
[i
]->set_my_scope(p_scope
);
99 void SignatureParamList::add_param(SignatureParam
*p_param
)
101 if (!p_param
|| checked
) FATAL_ERROR("SignatureParamList::add_param()");
102 params_v
.add(p_param
);
105 size_t SignatureParamList::get_nof_in_params() const
107 if (!checked
) FATAL_ERROR("SignatureParamList::get_nof_in_params()");
108 return in_params_v
.size();
111 SignatureParam
*SignatureParamList::get_in_param_byIndex(size_t n
) const
113 if (!checked
) FATAL_ERROR("SignatureParamList::get_in_param_byIndex()");
114 return in_params_v
[n
];
117 size_t SignatureParamList::get_nof_out_params() const
119 if (!checked
) FATAL_ERROR("SignatureParamList::get_nof_out_params()");
120 return out_params_v
.size();
123 SignatureParam
*SignatureParamList::get_out_param_byIndex(size_t n
) const
125 if (!checked
) FATAL_ERROR("SignatureParamList::get_out_param_byIndex()");
126 return out_params_v
[n
];
129 bool SignatureParamList::has_param_withName(const Identifier
& p_name
) const
131 if (!checked
) FATAL_ERROR("SignatureParamList::has_param_withName()");
132 return params_m
.has_key(p_name
.get_name());
135 const SignatureParam
*SignatureParamList::get_param_byName
136 (const Identifier
& p_name
) const
138 if (!checked
) FATAL_ERROR("SignatureParamList::get_param_byName()");
139 return params_m
[p_name
.get_name()];
142 void SignatureParamList::chk(Type
*p_signature
)
146 for (size_t i
= 0; i
< params_v
.size(); i
++) {
147 SignatureParam
*param
= params_v
[i
];
148 const Identifier
& id
= param
->get_id();
149 const string
& name
= id
.get_name();
150 const char *dispname_str
= id
.get_dispname().c_str();
151 if (params_m
.has_key(name
)) {
152 param
->error("Duplicate parameter identifier: `%s'", dispname_str
);
153 params_m
[name
]->note("Parameter `%s' is already defined here",
155 } else params_m
.add(name
, param
);
156 Error_Context
cntxt(param
, "In parameter `%s'", dispname_str
);
157 bool is_nonblock
= p_signature
->is_nonblocking_signature();
158 switch (param
->get_direction()) {
159 case SignatureParam::PARAM_IN
:
160 in_params_v
.add(param
);
162 case SignatureParam::PARAM_OUT
:
163 if (is_nonblock
) param
->error("A non-blocking signature cannot have "
165 out_params_v
.add(param
);
167 case SignatureParam::PARAM_INOUT
:
168 if (is_nonblock
) param
->error("A non-blocking signature cannot have "
169 "`inout' parameter");
170 in_params_v
.add(param
);
171 out_params_v
.add(param
);
174 FATAL_ERROR("SignatureParamList::chk()");
176 Type
*param_type
= param
->get_type();
177 param_type
->set_genname(p_signature
->get_genname_own(), name
);
178 param_type
->set_parent_type(p_signature
);
180 param_type
->chk_embedded(false, "the type of a signature parameter");
184 void SignatureParamList::dump(unsigned level
) const
186 for (size_t i
= 0; i
< params_v
.size(); i
++) params_v
[i
]->dump(level
);
189 // =================================
190 // ===== SignatureExceptions
191 // =================================
193 SignatureExceptions::~SignatureExceptions()
195 for (size_t i
= 0; i
< exc_v
.size(); i
++) delete exc_v
[i
];
200 SignatureExceptions
*SignatureExceptions::clone() const
202 FATAL_ERROR("SignatureExceptions::clone");
205 void SignatureExceptions::add_type(Type
*p_type
)
207 if (!p_type
) FATAL_ERROR("SignatureExceptions::add_type()");
211 bool SignatureExceptions::has_type(Type
*p_type
)
213 if (!p_type
) FATAL_ERROR("SignatureExceptions::has_type()");
214 if (p_type
->get_type_refd_last()->get_typetype() == Type::T_ERROR
)
216 else return exc_m
.has_key(p_type
->get_typename());
219 size_t SignatureExceptions::get_nof_compatible_types(Type
*p_type
)
221 if (!p_type
) FATAL_ERROR("SignatureExceptions::get_nof_compatible_types()");
222 if (p_type
->get_type_refd_last()->get_typetype() == Type::T_ERROR
) {
223 // Return a positive answer for erroneous types.
227 for (size_t i
= 0; i
< exc_v
.size(); i
++)
228 // Don't allow type compatibility. The types must match exactly.
229 if (exc_v
[i
]->is_compatible(p_type
, NULL
))
235 void SignatureExceptions::chk(Type
*p_signature
)
237 Error_Context
cntxt(this, "In exception list");
238 for (size_t i
= 0; i
< exc_v
.size(); i
++) {
239 Type
*type
= exc_v
[i
];
240 type
->set_genname(p_signature
->get_genname_own(), Int2string(i
+ 1));
241 type
->set_parent_type(p_signature
);
243 if (type
->get_typetype() == Type::T_ERROR
) continue;
244 type
->chk_embedded(false, "on the exception list of a signature");
245 const string
& type_name
= type
->get_typename();
246 if (exc_m
.has_key(type_name
)) {
247 type
->error("Duplicate type in exception list");
248 exc_m
[type_name
]->note("Type `%s' is already given here",
250 } else exc_m
.add(type_name
, type
);
254 void SignatureExceptions::set_fullname(const string
& p_fullname
)
256 Node::set_fullname(p_fullname
);
257 for (size_t i
= 0; i
< exc_v
.size(); i
++)
258 exc_v
[i
]->set_fullname(p_fullname
+ ".<type" + Int2string(i
+ 1) + ">");
261 void SignatureExceptions::set_my_scope(Scope
*p_scope
)
263 for (size_t i
= 0; i
< exc_v
.size(); i
++)
264 exc_v
[i
]->set_my_scope(p_scope
);
267 void SignatureExceptions::dump(unsigned level
) const
269 for (size_t i
=0; i
< exc_v
.size(); i
++) exc_v
[i
]->dump(level
);
272 } /* namespace Common */
This page took 0.045481 seconds and 5 git commands to generate.