Exemplo n.º 1
0
// display the application usage including parameter sintax
void CommandLineManager::displayApplicationUsage() {

	cout << endl;
	cout << " " << m_strApplicationName.c_str() << " (version: " << m_strVersion.c_str() 
		<< ", author: " << m_strAuthor.c_str() << ")" << endl;
	cout << endl;
	cout << " usage: " << m_strApplicationName.c_str() << " [parameters]" << endl;
	cout << " parameters:" << endl;
	string strType;
	
	bool bOptionalParameters = false;
	// compute max lenght of string types
	unsigned int iMaxLength = 0;
	for(MParameter::iterator it = m_mParameter.begin() ; it != m_mParameter.end() ; ++it) {
		if (it->second->bOptional) {
			bOptionalParameters = true;
		}	
		getStrType(it->second,strType);
		if (strType.length() > iMaxLength) {
			iMaxLength = (int)strType.length();
		}
	}
	
	for(unsigned int iPosition = 0 ; iPosition < m_mParameter.size() ; ++iPosition) {
		for(MParameter::iterator it = m_mParameter.begin() ; it != m_mParameter.end() ; ++it) {
			if (it->second->iOrder == (int)iPosition) {
				getStrType(it->second,strType);
				printf("  %-12s %-*s %-s",it->second->strName.c_str(),max(iMaxLength,24u),strType.c_str(),
					it->second->strDescription.c_str());
				if (it->second->strDefaultValue.compare("") == 0) {
					cout << endl;
				} else {
					cout << " (default: " << it->second->strDefaultValue.c_str() << " )" << endl;
				}
				break;
			}
		}
	}
	if (bOptionalParameters) {
		cout << endl << " (*optional)" << endl;
	}
	cout << endl;
}
Exemplo n.º 2
0
void dumpGlobalVars(astree* root){
  for(size_t i = 0;i<root->children.size();i++){
    astree* curr = root->children[i];
    int sym = curr->symbol;
    if(sym == TOK_VARDECL){
      fprintf(file_oil, "%s __%s;\n",
      getStrType(curr->children[0]).c_str(),
      curr->children[0]->children[0]->lexinfo->c_str() );
    }
  }
}
Exemplo n.º 3
0
void dumpStruct(astree* root){
  for(size_t i=0;i<root->children.size();i++){
    int sym = root->children[i]->symbol;
    if(sym == TOK_STRUCT){
      const string* strval = root->children[i]->children[0]->lexinfo;
      symbol* structSym = lookupSym(strval);
      if(structSym!=NULL){
        fprintf(file_oil,"struct s_%s {\n",structSym->type_id.c_str());
        for(size_t j=1;j<root->children[i]->children.size();j++){
          astree* temp = root->children[i]->children[j];
          const string* field = temp->children[0]->lexinfo;
          if(temp->children.size()>1)
            field = temp->children[1]->lexinfo;
          string type = getStrType(temp);
          fprintf(file_oil, "\t%s f_%s_%s;\n",
                            type.c_str(),strval->c_str(),
                                            field->c_str());
        }
        fprintf(file_oil,"}\n");
      }
    }
  }
}
Exemplo n.º 4
0
void dumpFunction(astree* root){
  for(size_t i = 0;i<root->children.size();i++){
    astree* curr = root->children[i];
    int sym = curr->symbol;
    if(sym == TOK_FUNCTION){
      fprintf(file_oil, "%s __%s (",
      getStrType(curr->children[0]).c_str(),
      curr->children[0]->children[0]->lexinfo->c_str());
      if(curr->children[1]->children.size()==0){
        fprintf(file_oil,")\n");
      }else{
        symbol* func = lookupSym(curr->children[0]->
                                children[0]->lexinfo);
        vector<symbol*> temp = *(func->parameters);
        for(size_t j = 0; j<temp.size();j++){
          symbol* tempSym = temp[j];
          string output = getStrType(curr->children[1]->children[j]);
          int blocknum = static_cast<int>(tempSym->block_nr);
          output+="_"+to_string(blocknum)+"_";
          output+=*(curr->children[1]->children[j]->
                                children[0]->lexinfo);
          if(j==temp.size()-1){
            fprintf(file_oil, "\n\t%s)\n",output.c_str());
          }else{
            fprintf(file_oil, "\n\t%s,",output.c_str());
          }
        }
      }
      fprintf(file_oil, "{\n");
      for(size_t k = 0;k<curr->children[2]->children.size();k++){
        int blockSym = curr->children[2]->children[k]->symbol;
        switch(blockSym){
          case TOK_VARDECL: case '=':
            printVardecl(curr->children[2]->children[k], curr, 1);
            break;
          case TOK_RETURN:{
            string result = "";
            if(curr->children[2]->children[k]->children.size() > 1){
              result = recursBinop(curr->children[2]->children[k]
                                          ->children[1], curr, 1);
            }else{
              result = recursBinop(curr->children[2]->children[k]
                                        ->children[0], curr, 1);
            }
            fprintf(file_oil, "\treturn %s\n", result.c_str());
            break;
          }
          case TOK_WHILE:
          {
            dumpWhile(curr->children[2]->children[k], 1);
            break;
          }
          case TOK_IF:
            dumpIf(curr, 1);
            break;
          case TOK_IFELSE:
            dumpIfElse(curr, 1);
            break;
          case TOK_CALL:
            dumpCall(curr);
          default:
            break;
        }
      }
    }
  }
  fprintf(file_oil, "}\n");
}