Beispiel #1
0
Type *Namespace::FindTypeByName(const std::string& name) const
{
  auto delim = name.find(' ');
  if (delim != std::string::npos)
    return FindTypeByName(name.substr(delim + 1));

  delim = name.find("::");
  if (delim != std::string::npos)
  {
    std::string head = name.substr(0, delim);
    std::string tail = name.substr(delim + 2);

    auto headIter = m_Children.find(head);
    if (headIter != m_Children.end())
    {
      auto &ch = headIter->second;
      return ch->FindTypeByName(tail);
    }
  }

  auto iter = m_Types.find(name);
  if (iter != m_Types.end())
    return iter->second.get();

  return m_Parent ? m_Parent->FindTypeByName(name) : nullptr;
}
Beispiel #2
0
//12.<传递参数>—> id [ ,  id ]| ε
void passparameter(char funname[]){
	vector<int> tmptypes;//实参类型序列
	char varname[MAXIDLEN];
	strcpy(varname, token);

	if (lookahead==id){
		match(id);
		if (!isexist(varname)){
			strcpy(token, varname);
			error(46);
		}

		int tmptype = FindTypeByName(varname);

		tmptypes.push_back(tmptype);

		while (lookahead == comma){
			match(comma);

			strcpy(varname, token);
			
			match(id);

			if (!isexist(varname)){
				strcpy(token, varname);
				error(46);
			}

			tmptype = FindTypeByName(varname);
			tmptypes.push_back(tmptype);
		}
		int callfuncId = FindIdByName(funname);
		if (tmptypes.size() != funtabs[callfuncId].para.size()){
			error(51);
		}
		else{
			for (int i = 0; i < tmptypes.size(); i++){
				if (tmptypes[i] != funtabs[callfuncId].para[i]){
					error(52);
				}
			}
		}
	}
}