예제 #1
0
const string& Symbol::cIdent() const
{
  if (existPair("external") || existPair("primitive")) { 
    return m_id;
  } else {
    return m_c_id;
  }
}
예제 #2
0
void Symbol::addPair(const string& key, const string& value)
{
  if (existPair(key)) {
    warning("Pair key '" + key + "' re-defined. new: '" + value + "' old: '" + lookupPair(key) + "'");
  }
  m_pairs.add(key, value);
}
예제 #3
0
const string& Symbol::lookupPair(const string& key) const
{
  if (!existPair(key)) {
    error("Value for pair '" + key + "' missing.");
  }
  return m_pairs.lookup(key);
}
예제 #4
0
파일: Func.C 프로젝트: dberc/tpzsimul.gems
Func::Func(string id, const Location& location, 
           Type* type_ptr, const Vector<Type*>& param_type_vec,
           const Vector<string>& param_string_vec, string body,
           const Map<string, string>& pairs, StateMachine* machine_ptr)
  : Symbol(id, location, pairs)
{ 
  m_type_ptr = type_ptr; 
  m_param_type_vec = param_type_vec;
  m_param_string_vec = param_string_vec;
  m_body = body;
  m_isInternalMachineFunc = false;

  if (machine_ptr == NULL) {
    m_c_ident = id;
  } else if (existPair("external") || existPair("primitive")) { 
    m_c_ident = id;
  } else {
    m_machineStr = machine_ptr->toString();
    m_c_ident = m_machineStr + "_" + id;  // Append with machine name
    m_isInternalMachineFunc = true;
  }
}
예제 #5
0
파일: Func.C 프로젝트: dberc/tpzsimul.gems
// This write a function of object Chip
void Func::writeCFiles(string path) const
{
  if (isExternal()) {
    // Do nothing
  } else {
    ostringstream out;

    // Header
    out << "/** Auto generated C++ code started by "<<__FILE__<<":"<<__LINE__<< " */" << endl;
    out << endl;
    out << "#include \"Types.h\"" << endl;
    out << "#include \"Chip.h\"" << endl;
    if (m_isInternalMachineFunc) {
      out << "#include \"" << m_machineStr << "_Controller.h\"" << endl;
    }
    out << endl;

    // Generate function header
    string code;
    Type* void_type_ptr = g_sym_table.getType("void");
    string return_type = m_type_ptr->cIdent(); 
    code += return_type;
    if (existPair("return_by_ref") && m_type_ptr != void_type_ptr) {
      code += "&";
    }
    if (!m_isInternalMachineFunc) {   
      code += " Chip::" + cIdent() + "(";
    } else {
      code += " " + m_machineStr + "_Controller::" + cIdent() + "(";
    }
    int size = m_param_type_vec.size();
    for(int i=0; i<size; i++) {
      // Generate code
      if (i != 0) {
        code += ", ";
      }
      code += m_param_string_vec[i];
    }
    code += ")";
    
    // Function body
    code += "\n{\n";
    code += m_body;
    code += "}\n";
    out << code << endl;
    
    // Write it out
    conditionally_write_file(path + cIdent() + ".C", out);
  }
}
예제 #6
0
Symbol::Symbol(string id, const Location& location, const Map<string, string>& pairs, const StateMachine* machine_ptr)
{
  m_id = id; 
  m_location = location; 
  m_pairs = pairs;
  if (!existPair("short")) {
    addPair("short", m_id);
  }
  m_used = false; 
  m_machine_ptr = machine_ptr;
  
  if (m_machine_ptr != NULL) {
    m_c_id = machine_ptr->toString() + "_" + id;  // Append with machine name
  } else {
    m_c_id = id;
  }
}
예제 #7
0
파일: Func.C 프로젝트: dberc/tpzsimul.gems
void Func::funcPrototype(string& code) const
{
  if (isExternal()) {
    // Do nothing
  } else {
    string return_type = m_type_ptr->cIdent(); 
    Type* void_type_ptr = g_sym_table.getType("void");
    if (existPair("return_by_ref") && (m_type_ptr != void_type_ptr)) {
      return_type += "&";
    }
    code += return_type + " " + cIdent() + "(";
    int size = m_param_string_vec.size();
    for(int i=0; i<size; i++) {
      // Generate code
      if (i != 0) {
        code += ", ";
      }
      code += m_param_string_vec[i];
    }
    code += ");\n";
  }
}