void Map::checkFunction(CFunction& function) const throw(InvalidProcessException) { if (function.getInputParameters().size() == 1) { if (function.getReturnDataType()->getFunctionReturnDataTypeString() == "void") { THROW_EXCEPTION(InvalidProcessException, string("Leaf \"") + getId()->getString() + "\" of type \"" + type() + "\": function arguments with one input " "parameter must return data (i.e. have return " "data type other than \"void\")"); } if (function.getReturnDataType()->isArray()) { THROW_EXCEPTION(InvalidProcessException, string("Leaf \"") + getId()->getString() + "\" of type \"" + type() + "\": return type of function arguments " "with one input parameter must not be an array"); } } else if (function.getInputParameters().size() == 2) { if (function.getReturnDataType()->getFunctionReturnDataTypeString() != "void") { THROW_EXCEPTION(InvalidProcessException, string("Leaf \"") + getId()->getString() + "\" of type \"" + type() + "\": function arguments with two input " "parameters must not return data (i.e. have return " "data type \"void\")"); } } else { THROW_EXCEPTION(InvalidProcessException, string("Leaf \"") + getId()->getString() + "\" of type \"" + type() + "\" must have a function argument with " "one or two input parameters"); } CDataType first_input_data_type = *function.getInputParameters().front()->getDataType(); if (first_input_data_type.isArray() && !first_input_data_type.isConst()) { THROW_EXCEPTION(InvalidProcessException, string("Leaf \"") + getId()->getString() + "\" of type \"" + type() + "\": first input parameter is a " "reference or array but not declared const"); } }
void GraphmlParser::findFunctionArraySizes(CFunction& function, ticpp::Element* xml) throw(InvalidArgumentException, ParseException, IOException, RuntimeException) { if (!xml) { THROW_EXCEPTION(InvalidArgumentException, "\"xml\" must not be NULL"); } list<Element*> elements = getElementsByName(xml, "port"); // If return data type or last input parameter is an array, find the array // size by analyzing the out port XML elements CDataType* output_data_type = NULL; if (function.getReturnDataType()->isArray()) { output_data_type = function.getReturnDataType(); logger_.logMessage(Logger::DEBUG, "Searching array size for return " "data type..."); } else if (function.getNumInputParameters() > 1) { output_data_type = function.getInputParameters().back()->getDataType(); // Reset to NULL if the parameter is not what we are looking for if (output_data_type->isArray()) { logger_.logMessage(Logger::DEBUG, "Searching array size for second " "input parameter data type..."); } else { output_data_type = NULL; } } if (output_data_type) { list<Element*>::iterator it; for (it = elements.begin(); it != elements.end(); ++it) { logger_.logMessage(Logger::DEBUG, string("Analyzing line " + tools::toString((*it)->Row()) + "...")); string port_name = getName(*it); if (isOutPort(port_name)) { size_t array_size = findArraySize(*it); if (array_size > 0) { logger_.logMessage(Logger::DEBUG, string("Found array size ") + tools::toString(array_size)); output_data_type->setArraySize(array_size); } break; } } } // Find array sizes for the input parameters which are arrays by analyzing // the in port XML elements list<CVariable*> parameters = function.getInputParameters(); list<CVariable*>::iterator param_it = parameters.begin(); list<CVariable*>::iterator param_stop_point; list<Element*>::iterator xml_it = elements.begin(); if (function.getNumInputParameters() > 1) { param_stop_point = --parameters.end(); } else { param_stop_point = parameters.end(); } while (param_it != param_stop_point && xml_it != elements.end()) { if (param_it == parameters.begin()) { logger_.logMessage(Logger::DEBUG, "Searching array size for " "input parameter data type..."); } logger_.logMessage(Logger::DEBUG, string("Analyzing line " + tools::toString((*xml_it)->Row()) + "...")); if (!isInPort(getName(*xml_it))) { logger_.logMessage(Logger::DEBUG, "Not an in port, moving to next"); ++xml_it; continue; } if ((*param_it)->getDataType()->isArray()) { size_t array_size = findArraySize(*xml_it); if (array_size > 0) { logger_.logMessage(Logger::DEBUG, string("Found array size ") + tools::toString(array_size)); (*param_it)->getDataType()->setArraySize(array_size); } else { logger_.logMessage(Logger::DEBUG, "No array size key"); } } ++param_it; ++xml_it; } }