1 ///////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2000-2015 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
7 ///////////////////////////////////////////////////////////////////////////////
11 #include "CompilerError.hh"
15 // =================================
16 // ===== SignatureParam
17 // =================================
19 SignatureParam::SignatureParam(param_direction_t p_d
, Type
*p_t
,
21 : param_direction(p_d
), param_type(p_t
), param_id(p_i
)
23 if (!p_t
|| !p_i
) FATAL_ERROR("SignatureParam::SignatureParam()");
24 param_type
->set_ownertype(Type::OT_SIG_PAR
, this);
27 SignatureParam::~SignatureParam()
33 SignatureParam
*SignatureParam::clone() const
35 FATAL_ERROR("SignatureParam::clone");
38 void SignatureParam::set_fullname(const string
& p_fullname
)
40 Node::set_fullname(p_fullname
);
41 param_type
->set_fullname(p_fullname
);
44 void SignatureParam::set_my_scope(Scope
*p_scope
)
46 param_type
->set_my_scope(p_scope
);
49 void SignatureParam::dump(unsigned level
) const
51 switch(param_direction
) {
52 case PARAM_IN
: DEBUG(level
,"in"); break;
53 case PARAM_OUT
: DEBUG(level
,"out"); break;
54 case PARAM_INOUT
: DEBUG(level
,"inout");break;
55 default: FATAL_ERROR("SignatureParam::dump()"); break;
57 param_type
->dump(level
+1);
58 param_id
->dump(level
+2);
61 // =================================
62 // ===== SignatureParamList
63 // =================================
65 SignatureParamList::~SignatureParamList()
67 for (size_t i
= 0; i
< params_v
.size(); i
++) delete params_v
[i
];
74 SignatureParamList
*SignatureParamList::clone() const
76 FATAL_ERROR("SignatureParam::clone");
79 void SignatureParamList::set_fullname(const string
& p_fullname
)
81 Node::set_fullname(p_fullname
);
82 for (size_t i
= 0; i
< params_v
.size(); i
++) {
83 SignatureParam
*param
= params_v
[i
];
84 param
->set_fullname(p_fullname
+ "." + param
->get_id().get_dispname());
88 void SignatureParamList::set_my_scope(Scope
*p_scope
)
90 for (size_t i
= 0; i
< params_v
.size(); i
++)
91 params_v
[i
]->set_my_scope(p_scope
);
94 void SignatureParamList::add_param(SignatureParam
*p_param
)
96 if (!p_param
|| checked
) FATAL_ERROR("SignatureParamList::add_param()");
97 params_v
.add(p_param
);
100 size_t SignatureParamList::get_nof_in_params() const
102 if (!checked
) FATAL_ERROR("SignatureParamList::get_nof_in_params()");
103 return in_params_v
.size();
106 SignatureParam
*SignatureParamList::get_in_param_byIndex(size_t n
) const
108 if (!checked
) FATAL_ERROR("SignatureParamList::get_in_param_byIndex()");
109 return in_params_v
[n
];
112 size_t SignatureParamList::get_nof_out_params() const
114 if (!checked
) FATAL_ERROR("SignatureParamList::get_nof_out_params()");
115 return out_params_v
.size();
118 SignatureParam
*SignatureParamList::get_out_param_byIndex(size_t n
) const
120 if (!checked
) FATAL_ERROR("SignatureParamList::get_out_param_byIndex()");
121 return out_params_v
[n
];
124 bool SignatureParamList::has_param_withName(const Identifier
& p_name
) const
126 if (!checked
) FATAL_ERROR("SignatureParamList::has_param_withName()");
127 return params_m
.has_key(p_name
.get_name());
130 const SignatureParam
*SignatureParamList::get_param_byName
131 (const Identifier
& p_name
) const
133 if (!checked
) FATAL_ERROR("SignatureParamList::get_param_byName()");
134 return params_m
[p_name
.get_name()];
137 void SignatureParamList::chk(Type
*p_signature
)
141 for (size_t i
= 0; i
< params_v
.size(); i
++) {
142 SignatureParam
*param
= params_v
[i
];
143 const Identifier
& id
= param
->get_id();
144 const string
& name
= id
.get_name();
145 const char *dispname_str
= id
.get_dispname().c_str();
146 if (params_m
.has_key(name
)) {
147 param
->error("Duplicate parameter identifier: `%s'", dispname_str
);
148 params_m
[name
]->note("Parameter `%s' is already defined here",
150 } else params_m
.add(name
, param
);
151 Error_Context
cntxt(param
, "In parameter `%s'", dispname_str
);
152 bool is_nonblock
= p_signature
->is_nonblocking_signature();
153 switch (param
->get_direction()) {
154 case SignatureParam::PARAM_IN
:
155 in_params_v
.add(param
);
157 case SignatureParam::PARAM_OUT
:
158 if (is_nonblock
) param
->error("A non-blocking signature cannot have "
160 out_params_v
.add(param
);
162 case SignatureParam::PARAM_INOUT
:
163 if (is_nonblock
) param
->error("A non-blocking signature cannot have "
164 "`inout' parameter");
165 in_params_v
.add(param
);
166 out_params_v
.add(param
);
169 FATAL_ERROR("SignatureParamList::chk()");
171 Type
*param_type
= param
->get_type();
172 param_type
->set_genname(p_signature
->get_genname_own(), name
);
173 param_type
->set_parent_type(p_signature
);
175 param_type
->chk_embedded(false, "the type of a signature parameter");
179 void SignatureParamList::dump(unsigned level
) const
181 for (size_t i
= 0; i
< params_v
.size(); i
++) params_v
[i
]->dump(level
);
184 // =================================
185 // ===== SignatureExceptions
186 // =================================
188 SignatureExceptions::~SignatureExceptions()
190 for (size_t i
= 0; i
< exc_v
.size(); i
++) delete exc_v
[i
];
195 SignatureExceptions
*SignatureExceptions::clone() const
197 FATAL_ERROR("SignatureExceptions::clone");
200 void SignatureExceptions::add_type(Type
*p_type
)
202 if (!p_type
) FATAL_ERROR("SignatureExceptions::add_type()");
206 bool SignatureExceptions::has_type(Type
*p_type
)
208 if (!p_type
) FATAL_ERROR("SignatureExceptions::has_type()");
209 if (p_type
->get_type_refd_last()->get_typetype() == Type::T_ERROR
)
211 else return exc_m
.has_key(p_type
->get_typename());
214 size_t SignatureExceptions::get_nof_compatible_types(Type
*p_type
)
216 if (!p_type
) FATAL_ERROR("SignatureExceptions::get_nof_compatible_types()");
217 if (p_type
->get_type_refd_last()->get_typetype() == Type::T_ERROR
) {
218 // Return a positive answer for erroneous types.
222 for (size_t i
= 0; i
< exc_v
.size(); i
++)
223 // Don't allow type compatibility. The types must match exactly.
224 if (exc_v
[i
]->is_compatible(p_type
, NULL
))
230 void SignatureExceptions::chk(Type
*p_signature
)
232 Error_Context
cntxt(this, "In exception list");
233 for (size_t i
= 0; i
< exc_v
.size(); i
++) {
234 Type
*type
= exc_v
[i
];
235 type
->set_genname(p_signature
->get_genname_own(), Int2string(i
+ 1));
236 type
->set_parent_type(p_signature
);
238 if (type
->get_typetype() == Type::T_ERROR
) continue;
239 type
->chk_embedded(false, "on the exception list of a signature");
240 const string
& type_name
= type
->get_typename();
241 if (exc_m
.has_key(type_name
)) {
242 type
->error("Duplicate type in exception list");
243 exc_m
[type_name
]->note("Type `%s' is already given here",
245 } else exc_m
.add(type_name
, type
);
249 void SignatureExceptions::set_fullname(const string
& p_fullname
)
251 Node::set_fullname(p_fullname
);
252 for (size_t i
= 0; i
< exc_v
.size(); i
++)
253 exc_v
[i
]->set_fullname(p_fullname
+ ".<type" + Int2string(i
+ 1) + ">");
256 void SignatureExceptions::set_my_scope(Scope
*p_scope
)
258 for (size_t i
= 0; i
< exc_v
.size(); i
++)
259 exc_v
[i
]->set_my_scope(p_scope
);
262 void SignatureExceptions::dump(unsigned level
) const
264 for (size_t i
=0; i
< exc_v
.size(); i
++) exc_v
[i
]->dump(level
);
267 } /* namespace Common */
This page took 0.044893 seconds and 6 git commands to generate.