コード例 #1
0
ファイル: lstring.cpp プロジェクト: Latexi95/CBCompiler
LString LString::operator +(const LString &o) const {
    if (this->isEmpty()) return o;
    if (o.isEmpty()) return *this;

    LStringData *newStr = LStringData::create(this->length() + o.length() + 1);
    std::copy(this->mData->begin(), this->mData->end(), newStr->begin());
    std::copy(o.mData->begin(), o.mData->end(), newStr->begin() + this->length());

    newStr->mSize = this->length() + o.length();
    return LString(newStr);
}
コード例 #2
0
ファイル: MSMSFileReader.hpp プロジェクト: CueMol/cuemol2
  LString readStr(int start, int end) {
    if (m_recbuf.isEmpty()) return LString();

    start --; end --;
    if (end >= m_recbuf.length())
      end = m_recbuf.length()-1;
    if (start<0)
      start = 0;
    if (start>end)
      start = end;

    return m_recbuf.substr(start, end-start+1);
  }
コード例 #3
0
ファイル: wordsplit.cpp プロジェクト: hladek/dagger
int main(int argc, char **argv) {

    Vocab3 vocab;
    Splitter s(vocab,3,true);
    s.load_vocab(argv[1]);
    s.go();
    NgramCounter unigrams(1);
    ifstream ifs1(argv[1]);
    LineTokenizer lt1(ifs1);
    while(lt1.next()){
        Tokenizer tok(lt1.token(),' ');
        while(tok.next()){
            int wid = vocab.Add(tok.token());
            unigrams.increase_count(&wid,1);
        }
    }

    ifstream ifs(argv[1]);
    LineTokenizer lt(ifs);
    NgramCounter ng(2);
    while(lt.next()){
        Tokenizer tok(lt.token(),' ');
        while(tok.next()){
            int wid = vocab.Add(tok.token());
            int clid = s.get_class(wid);
            if (clid < 0 || unigrams.get_count(&wid) > 100 ){
                clid = wid;
            }
            else {
                string cl = "-" + s.class_set.Get(clid).str();
                clid = vocab.Add(LString(cl));
            }

            int key[2] = {clid,wid};
            ng.increase_count(key,1);
            cout << vocab.Get(clid) << " "; 
        }
        cout << endl;
    }
    BtreeIterator it = ng.iterator();
    ofstream ofs("my.classes");
    while(it.next()){
         ofs << vocab.Get(it.key()[1]) << "\t" << vocab.Get(it.key()[0]) << "\t" << (int)it.double_value()[0] << endl;
    }
    ofstream ofs2("my.classmap");
    it = s.class_map.iterator();
    while (it.next()){

         ofs2 << vocab.Get(it.key()[0]) << "\t" << s.class_set.Get(it.key()[1]) << endl;
    }
}
コード例 #4
0
ファイル: exportPass.cpp プロジェクト: JehandadKhan/roccc-2.0
void ExportPass::ConstructModuleSymbols()
{
  CProcedureType* originalType = dynamic_cast<CProcedureType*>(originalProcedure->get_procedure_symbol()->get_type()) ;
  assert(originalType != NULL) ;

  // The original type takes and returns a struct.  We need to change this
  //  to a list of arguments.

  VoidType* newReturnType = create_void_type(theEnv, IInteger(0), 0) ;
  constructedType = create_c_procedure_type(theEnv,
					    newReturnType,
					    false, // has varargs
					    true, // arguments_known
					    0, // bit alignment
					    LString("ConstructedType")) ;

  StructType* returnType = 
    dynamic_cast<StructType*>(originalType->get_result_type()) ;
  assert(returnType != NULL) ;

  SymbolTable* structSymTab = returnType->get_group_symbol_table() ;
  assert(structSymTab != NULL) ;

  for (int i = 0 ; i < structSymTab->get_symbol_table_object_count() ; ++i)
  {
    VariableSymbol* nextVariable = 
      dynamic_cast<VariableSymbol*>(structSymTab->get_symbol_table_object(i));
    if (nextVariable != NULL)
    {
      // Check to see if this is an output or not
      QualifiedType* cloneType ;
      DataType* cloneBase = 
	dynamic_cast<DataType*>(nextVariable->get_type()->get_base_type()->deep_clone()) ;
      assert(cloneBase != NULL) ;
      cloneType = create_qualified_type(theEnv, cloneBase) ;
 
      if (nextVariable->lookup_annote_by_name("Output") != NULL)
      {
	cloneType->append_annote(create_brick_annote(theEnv, "Output")) ;
	// Why doesn't this stick around?
      }
      constructedType->append_argument(cloneType) ;
    }
  }

  constructedSymbol = create_procedure_symbol(theEnv,
					      constructedType,
					      originalProcedure->get_procedure_symbol()->get_name()) ;
  constructedSymbol->set_definition(NULL) ;

}
コード例 #5
0
void CleanupRedundantVotes::ProcessCall(CallStatement* c)
{
  assert(c != NULL) ;
  
  SymbolAddressExpression* symAddress = 
    dynamic_cast<SymbolAddressExpression*>(c->get_callee_address()) ;
  assert(symAddress != NULL) ;
  
  Symbol* sym = symAddress->get_addressed_symbol() ;
  assert(sym != NULL) ;

  if (sym->get_name() == LString("ROCCCTripleVote") || 
      sym->get_name() == LString("ROCCCDoubleVote") )
  {
    LoadVariableExpression* errorVariableExpression = 
      dynamic_cast<LoadVariableExpression*>(c->get_argument(0)) ;
    assert(errorVariableExpression != NULL) ;
    VariableSymbol* currentError = errorVariableExpression->get_source() ;
    assert(currentError != NULL) ;
    if (InList(currentError))
    {
      // Create a new variable
      VariableSymbol* errorDupe = 
	create_variable_symbol(theEnv,
			       currentError->get_type(),
			       TempName(LString("UnrolledRedundantError"))) ;
      errorDupe->append_annote(create_brick_annote(theEnv, "DebugRegister")) ;
      procDef->get_symbol_table()->append_symbol_table_object(errorDupe) ;
      usedVariables.push_back(errorDupe) ;
      errorVariableExpression->set_source(errorDupe) ;
    }
    else
    {
      usedVariables.push_back(currentError) ;
    }
  }

}
コード例 #6
0
LString TransformUnrolledArraysPass::GetReplacementName(LString baseName, 
							int offset)
{
   LString finalName = baseName ;
   finalName = finalName + "_" ;
   if (offset < 0)
   {
     offset = -offset ;
     finalName = finalName + "minus" ;
   }
   finalName = finalName + LString(offset) ;
   finalName = finalName + "_" ;
   return finalName ;
}
コード例 #7
0
ファイル: Viewport.cpp プロジェクト: mildrock/Carousel3D
clViewport::clViewport( const LString& WindowClassName,
                        LWindowHandle ViewportHandle,
                        const LString& Title,
                        int Width,
                        int Height,
                        bool Fullscreen,
                        bool RegWindowClass,
                        bool DisplayWindow,
                        bool TakeoverContext )
    : FWindowHandle( 0 ),
      FWindowClassName( WindowClassName ),
      FTitle( Title ),
      FWidth( Width ),
      FHeight( Height ),
      FTop( 0 ),
      FLeft( 0 ),
      FFullscreen( Fullscreen ),
      FRegisterWindowClass( RegWindowClass ),
      FDisplayWindow( DisplayWindow ),
      FTakeoverContext( TakeoverContext )
{
    FWindowClassName = LString( ENGINE_NAME ) + " " + LString( ENGINE_VERSION );

#ifdef OS_WINDOWS
    FExternalWindowHandle = ViewportHandle;

    if ( FTakeoverContext )
    {
        FWindowHandle = ViewportHandle;
    }

#endif

#if defined( OS_ANDROID ) && !defined( ANDROID9 )
    ResizeViewport( sEnvironment::FAndroidViewportSize.FWidth, sEnvironment::FAndroidViewportSize.FHeight );
#endif
}
コード例 #8
0
ファイル: lstring.cpp プロジェクト: Latexi95/CBCompiler
LString LString::number(unsigned int i, int b) {
    assert(b >= 2 && b <= 16);
    unsigned int base = b;
    if (i == 0) return LString(U"0");
    static const char32_t nums[] = {U'0', U'1', U'2', U'3', U'4', U'5', U'6', U'7', U'8', U'9', U'A', U'B', U'C', U'D', U'E', U'F'};
    LStringData *data = LStringData::create(6 + 64 / base);
    LChar *str = data->begin();
    int size = 0;
    unsigned int shifter = i;
    do { //Move to where representation ends
        ++str;
        shifter = shifter/base;
    } while(shifter);

    *str = 0;
    while (i) {
        *(--str) = nums[i % base];
        ++size;
        i /= base;
    }

    data->mSize = size;
    return LString(data);
}
コード例 #9
0
ファイル: lstring.cpp プロジェクト: Latexi95/CBCompiler
LString LString::fromUtf8(const std::string &s) {
    if (s.size() == 0) return LString();
    const uint8_t *begin = reinterpret_cast<const uint8_t*>(s.c_str());
    const uint8_t *end = begin + s.size();
    LString ret;
    ret.reserve(s.size());

    LChar *destBegin = ret.begin();
    LChar *destEnd = ret.end();
    bool conversionSucceeded = utf8ToUtf32(&begin, end, &destBegin, destEnd);
    assert(conversionSucceeded && "Failed conversion utf8 -> utf32");

    ret.resize(destBegin - ret.begin());
    return ret;
}
コード例 #10
0
ファイル: larguments.cpp プロジェクト: Heather/Pyramid-Head
//------------------------------------------------------------------------------
int LArguments::parseInternalOption(LString option) {
    int ret;
    if(option == "--version" || option == "-v") {
        printVersion();
        return L_EXIT;
        }
    if(option == "--help" || option == "-h") {
        printUsage();
        return L_EXIT;
        }
    ret = parseOption(option);
    if(ret < 0) {
        llog.log(LLog::error, LString("Unknown option ") + option);
        }
    return ret;
    }
コード例 #11
0
// This is a vastly simpler way to setup annotations that doesn't worry
//  or assume that all feedbacks come from a single store variable statement
void SolveFeedbackVariablesPass3::SetupAnnotations()
{
  assert(theEnv != NULL) ;
  // Go through the list of all feedback instances we have discovered.
  list<PossibleFeedbackPair>::iterator feedbackIter = actualFeedbacks.begin();
  while (feedbackIter != actualFeedbacks.end())
  {
    // For every feedback, we need to create a two variables
    //  The first one is a replacement for the original use.
    //  The second one is the variable used for feedback.

    LString replacementName = (*feedbackIter).varSym->get_name() ;
    replacementName = replacementName + "_replacementTmp" ;

    VariableSymbol* replacementVariable = 
      create_variable_symbol(theEnv,
			     (*feedbackIter).varSym->get_type(),
			     TempName(replacementName)) ;
    procDef->get_symbol_table()->append_symbol_table_object(replacementVariable);

    VariableSymbol* feedbackVariable =
	create_variable_symbol(theEnv,
			       (*feedbackIter).varSym->get_type(),
			       TempName(LString("feedbackTmp"))) ;
    procDef->get_symbol_table()->append_symbol_table_object(feedbackVariable) ;
    
    // Replace the use with this new feedback variable
    (*feedbackIter).use->set_source(replacementVariable) ;

    // I am looking for the variable that originally defined me and 
    //  the variable that will replace me.
    Statement* definition = (*feedbackIter).definition ;
    VariableSymbol* definitionVariable = 
      GetDefinedVariable(definition, (*feedbackIter).definitionLocation) ;
    assert(definitionVariable != NULL) ;

    // Finally, annotate the feedback variable
    SetupAnnotations(feedbackVariable,		     
		     definitionVariable,
		     replacementVariable) ;
    
    replacementVariable->append_annote(create_brick_annote(theEnv,
							   "NonInputScalar"));

    ++feedbackIter ;
  }  
}
コード例 #12
0
ファイル: ldir.cpp プロジェクト: Heather/Pyramid-Head
//------------------------------------------------------------------------------
LString LDir::findSubdir(LString dirname) {
    struct stat sb;
    int pos = 0;
    int ret;
    ret = lstat((path + "/" + dirname), &sb);
    if(ret == 0 && (sb.st_mode & S_IFDIR)) {
        return path;
        }
    pos = path.find('/', pos);
    while(pos != string::npos) {
        ret = lstat((path.substr(0, pos) + "/" + dirname), &sb);
        if(ret == 0 && (sb.st_mode & S_IFDIR)) {
            return path.substr(0, pos);
            }
        pos = path.find('/', ++pos);
        }
    return LString("");
    }
コード例 #13
0
/*--------------------------------------------------------------------
 * preprocess_c
 *
 * This is a very naive C preprocessor that removes / * and * / comments,
 * # directives, escape codes beginning with '\', and strings are ignored.
 *
 * It is assumed that s2c doesn't generate complicated C codes.
 *
 */
static char *
preprocess_c(char *line, int &state, char *&current_src_file,
	     int &current_src_line, bool &found_line_num)
{
  found_line_num = false;
  char *buffer = new char[strlen(line) + 1];
  char *buffer_ptr = buffer;

  for (char *p = line; *p; p++) {
    if (state == COMMENT_STATE) {
      if (p[0] == '*' && p[1] == '/') {
	state = NORMAL_STATE;
	p++;
      }
    } else {
      if (p[0] == '/' && p[1] == '*') {
	state = COMMENT_STATE;

	/* check if this is a line number comment */
	int line_num;
	char src_file[200];
	if (sscanf(p, "/* line: %d \"%s\" */",
		   &line_num, src_file) == 2) {
	
	  /* this line contains the line number and file info */
	  int l = strlen(src_file);
	  if (src_file[l-1] == '\"') src_file[l-1] = 0;
	  current_src_file = (char *) LString(src_file).c_str();
	  current_src_line = line_num;
	  found_line_num = true;
	}
	p++;

      } else {

	*buffer_ptr++ = *p;
      }
    }
  }

  *buffer_ptr = 0;
  return (buffer);
}
コード例 #14
0
void ConstQualedVarPropagationPass::do_procedure_definition(ProcedureDefinition* proc_def)
{
  OutputInformation("Constant qualified variable propagation pass begins");

  suif_map<VariableSymbol*, ValueBlock*> temp_const_defs;
    if (proc_def){
        DefinitionBlock *proc_def_block = proc_def->get_definition_block();
        for(Iter<VariableDefinition*> iter = proc_def_block->get_variable_definition_iterator();
            iter.is_valid(); iter.next()){
            VariableDefinition *var_def = iter.current();
            VariableSymbol *var_sym = var_def->get_variable_symbol();
            QualifiedType *qualed_var_type = var_sym->get_type();
            if(is_a<IntegerType>(qualed_var_type->get_base_type())){
               bool found = 0;
               for(Iter<LString> iter2 = qualed_var_type->get_qualification_iterator();
                   iter2.is_valid(); iter2.next())
                   if(iter2.current() == LString("const"))
                      found = 1;
               if(found){
                  temp_const_defs.enter_value(var_sym, var_def->get_initialization());
               }
            }
        }
        for(Iter<StoreVariableStatement> iter = object_iterator<StoreVariableStatement>(proc_def->get_body());
            iter.is_valid(); iter.next()){
            StoreVariableStatement *store_var_stmt = &iter.current();
            Expression *store_var_value = store_var_stmt->get_value();
            if(!is_a<IntConstant>(store_var_value))
               continue;
            VariableSymbol *store_var_destination = store_var_stmt->get_destination();
            if(!is_a<IntegerType>(store_var_destination->get_type()->get_base_type()))  
               continue;
            suif_map<VariableSymbol*,ValueBlock*>::iterator iter2 =
                        temp_const_defs.find(to<LoadVariableExpression>(store_var_value)->get_source());
            if(iter2 != temp_const_defs.end())
               const_qualified_scalars.enter_value(store_var_destination, (*iter2).second);
        }
        cqvp_load_variable_expression_walker walker(get_suif_env());
        proc_def->walk(walker);
    }
  OutputInformation("Constant qualified variable propagation pass ends");
}
コード例 #15
0
ファイル: lstring.cpp プロジェクト: Latexi95/CBCompiler
LString LString::trimmed() const {
    LString::ConstIterator start = end();
    for (LString::ConstIterator i = begin(); i != end(); i++) {
        if (!isWhitespace(*i)) {
            start = i;
            break;
        }
    }
    if (start == end()) return *this;

    LString::ConstIterator e = end();
    for (LString::ConstIterator i = end() - 1; i != begin(); --i) {
        if (!isWhitespace(*i)) {
            e = i + 1;
            break;
        }
    }

    return LString(start, e);
}
コード例 #16
0
ファイル: larguments.cpp プロジェクト: Heather/Pyramid-Head
//------------------------------------------------------------------------------
int LArguments::parse(int argc, char* argv[]) {
    LString opt;
    int find;
    int ret;
    for(int num = 1; num < argc; num++) {
        opt = LString(argv[num]);

        if(opt.find("--") == 0) {
            if((find = opt.find("=")) != (int)string::npos) {
                if((ret = parseInternalOptionWithParamater(opt.substr(0, find), opt.substr(find + 1))) != L_OK) {
                    return ret;
                    }
                }
            else {
                if((ret = parseInternalOption(opt)) != L_OK) {
                    return ret;
                    }
                }
            }
        else if(opt.find("-") == 0) {
            if((find = opt.find("=")) != (int)string::npos) {
                if((ret = parseInternalOptionWithParamater(opt.substr(0, find), opt.substr(find + 1))) != L_OK) {
                    return ret;
                    }
                }
            else {
                if((ret = parseInternalOption(opt)) != L_OK) {
                    return ret;
                    }
                }
            }
        else {
            if((ret = parseInternalArgument(opt)) != L_OK) {
                return ret;
                }
            }

        }
    return L_OK;
    }
コード例 #17
0
ファイル: ldir.cpp プロジェクト: Heather/Pyramid-Head
//------------------------------------------------------------------------------
int LDir::next() {
    struct dirent* dirp;
    struct stat sb;
    do {
        if((dirp = readdir(dp)) == NULL) {
            filename.clear();
            return L_ERROR;
            }
        filename = LString(dirp->d_name);
        }
    while(filename == "." || filename == "..");
    lstat((path + "/" + filename), &sb);
    if((sb.st_mode & S_IFDIR)) {
        type = LDir::Dir;
        }
    else if((sb.st_mode & S_IFREG)) {
        type = LDir::File;
        }
    else {
        type = LDir::Unknown;
        }
    return L_OK;
    }
コード例 #18
0
bool ConstantArrayPropagationPass::ValidSymbol(VariableSymbol* var)
{
  assert(var != NULL) ;
  // The variable should be an array type and have the const qualifier.
  if (dynamic_cast<ArrayType*>(var->get_type()->get_base_type()) == NULL)
  {
    return false ;
  }
  QualifiedType* qualType = var->get_type() ;
  while (dynamic_cast<ArrayType*>(qualType->get_base_type()) != NULL)
  {
    ArrayType* array = dynamic_cast<ArrayType*>(qualType->get_base_type()) ;
    qualType = array->get_element_type() ;
  }
  assert(qualType != NULL) ;
  for (int i = 0 ; i < qualType->get_qualification_count(); ++i)
  {
    if (qualType->get_qualification(i) == LString("const"))
    {
      return true ;
    }
  }
  return false ;
}
コード例 #19
0
ファイル: lserialport.cpp プロジェクト: Heather/Pyramid-Head
//------------------------------------------------------------------------------
int LSerialPort::OpenPort() {
    struct termios options;
    /// open the device to be non-blocking (read will return immediatly)
    hCom = open(devCom, O_RDWR | O_NOCTTY | O_NONBLOCK);
    if(hCom < 0) {
        perror(devCom);
        return(-1);
        }
#ifdef DEBUG
    llog.log(LLog::info, 
                LString(devCom) + " port opened!");
#endif /* DEBUG */
    ///set parameters of port
    tcgetattr(hCom, &options);
    ///disable soft flow control
    options.c_iflag = 0;
    options.c_oflag = 0;
    options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
    options.c_cflag |= (CLOCAL | CREAD);
    ///8n1
    options.c_cflag &= ~PARENB;
    options.c_cflag &= ~CSTOPB;
    options.c_cflag &= ~CSIZE; // Mask the character size bits
    options.c_cflag |= CS8;    // Select 8 data bits
    ///enable hard flow control
    options.c_cflag &= ~CRTSCTS;
    options.c_cc[VMIN]  = 10;
    options.c_cc[VTIME] = 10;

    cfsetispeed(&options, baud_rates[baudRate]);
    cfsetospeed(&options, baud_rates[baudRate]);

    tcsetattr(hCom, TCSANOW, &options);
    fcntl(hCom, F_SETFL, FNDELAY);
    return hCom;
    }
コード例 #20
0
bool CombineSummationPass::IsSummation(Expression* e, VariableSymbol* v)
{
  assert(e != NULL) ;
  assert(v != NULL) ;

  BinaryExpression* binExp = dynamic_cast<BinaryExpression*>(e) ;
  if (binExp == NULL)
  {
    return false ;
  }

  if (binExp->get_opcode() != LString("add"))
  {
    return false ;
  }

  Expression* leftSide = binExp->get_source1() ;
  Expression* rightSide = binExp->get_source2() ;

  LoadVariableExpression* leftLoadVar = 
    dynamic_cast<LoadVariableExpression*>(leftSide) ;
  LoadVariableExpression* rightLoadVar = 
    dynamic_cast<LoadVariableExpression*>(rightSide) ;

  if (leftLoadVar != NULL && leftLoadVar->get_source() == v)
  {
    return true ;
  }
  
  if (rightLoadVar != NULL && rightLoadVar->get_source() == v)
  {
    return true ;
  }

  return IsSummation(leftSide, v) || IsSummation(rightSide, v) ;
}
コード例 #21
0
void ScalarReplacementPass2::CollectArrayReferences()
{
  assert(procDef != NULL) ;
  list<ArrayReferenceExpression*>* allRefs = 
    collect_objects<ArrayReferenceExpression>(procDef->get_body()) ;
  list<ArrayReferenceExpression*>::iterator refIter = allRefs->begin() ;
  while (refIter != allRefs->end())
  {
    // If this is not the topmost array reference, skip it.
    if (dynamic_cast<ArrayReferenceExpression*>((*refIter)->get_parent()) !=
	NULL)
    {
      ++refIter ;
      continue ;
    }
    
    // Also, skip lookup tables
    if (IsLookupTable(GetArrayVariable(*refIter)))
    {
      ++refIter ;
      continue ;
    }

    bool found = false ;
    std::pair<Expression*, VariableSymbol*> toAdd ;
    list<std::pair<Expression*, VariableSymbol*> >::iterator identIter = 
      Identified.begin() ;
    while (identIter != Identified.end())
    {
      if (EquivalentExpressions((*identIter).first, *refIter))
      {
	found = true ;
	toAdd = (*identIter) ;
	break ;
      }
      ++identIter ;
    }

    if (!found)
    {
      VariableSymbol* replacement =
	create_variable_symbol(theEnv, 
			       GetQualifiedTypeOfElement(*refIter),
			       TempName(LString("suifTmp"))) ;	
      replacement->append_annote(create_brick_annote(theEnv, 
						  "ScalarReplacedVariable")) ;
      procDef->get_symbol_table()->append_symbol_table_object(replacement) ;

      toAdd.first = (*refIter) ;
      toAdd.second = replacement ;
      Identified.push_back(toAdd) ;
    }
    if (dynamic_cast<LoadExpression*>((*refIter)->get_parent()) != NULL)
    {
      found = false ;
      identIter = IdentifiedLoads.begin() ;
      while (identIter != IdentifiedLoads.end())
      {
	if (EquivalentExpressions((*identIter).first, *refIter))
	  {
	    found = true ;
	    break ;
	  }
	++identIter ;
      }
      if (!found)
      {
	IdentifiedLoads.push_back(toAdd) ;
      }      
    }
    else if (dynamic_cast<StoreStatement*>((*refIter)->get_parent()) != NULL)
    {
      found = false ;
      identIter = IdentifiedStores.begin() ;
      while (identIter != IdentifiedStores.end())
      {
	if (EquivalentExpressions((*identIter).first, *refIter))
	{
	  found = true ;
	  break ;
	}
	++identIter ;
      }
      if (!found)
      {
	IdentifiedStores.push_back(toAdd) ;
      }
    }
    else 
    {
      assert(0 && "Improperly formatted array reference!") ;
    }  
    ++refIter ;
  }
  delete allRefs ;
}
コード例 #22
0
// All of the array references expressions in the passed in the struct are
//  equivalent, so we can determine types of the original and use that
//  to create a new expression with which to replace everything.
bool TransformUnrolledArraysPass::ReplaceNDReference(EquivalentReferences* a)
{
  assert(a != NULL) ;
  assert(a->original != NULL) ;

  // Check to see if the reference at this stage is a constant or not
  IntConstant* constantIndex = 
    dynamic_cast<IntConstant*>(a->original->get_index()) ;
  
  if (constantIndex == NULL)
  {
    // There was no replacement made
    return false ;
  }

  Expression* baseAddress = a->original->get_base_array_address() ;
  assert(baseAddress != NULL) ;
  assert(constantIndex != NULL) ;

  // Create a replacement expression for this value.  This will either
  //  be another array reference expression or a single variable.
  Expression* replacementExp = NULL ;
  //  QualifiedType* elementType = GetQualifiedTypeOfElement(a->original) ;
  VariableSymbol* originalSymbol = GetArrayVariable(a->original) ;
  assert(originalSymbol != NULL) ;
  LString replacementName = 
    GetReplacementName(originalSymbol->get_name(), 
		       constantIndex->get_value().c_int()) ;
  int dimensionality = GetDimensionality(a->original) ;
  
  QualifiedType* elementType = originalSymbol->get_type() ;
  while (dynamic_cast<ArrayType*>(elementType->get_base_type()) != NULL)
  {
    elementType = dynamic_cast<ArrayType*>(elementType->get_base_type())->get_element_type() ;
  }
  
  // There is a special case for one dimensional arrays as opposed to all
  //  other dimensional arrays.  It only should happen if we are truly
  //  replacing an array with a one dimensional array.
  if (dimensionality == 1 && 
      dynamic_cast<ArrayReferenceExpression*>(a->original->get_parent())==NULL)
  {

    VariableSymbol* replacementVar = 
      create_variable_symbol(theEnv,
			     GetQualifiedTypeOfElement(a->original),
			     TempName(replacementName)) ;
    procDef->get_symbol_table()->append_symbol_table_object(replacementVar) ;
    
    replacementExp = 
      create_load_variable_expression(theEnv,
				      elementType->get_base_type(),
				      replacementVar) ;
  }
  else
  {
    // Create a new array with one less dimension.  This requires a new
    //  array type.
    ArrayType* varType = 
      dynamic_cast<ArrayType*>(originalSymbol->get_type()->get_base_type()) ;
    assert(varType != NULL) ;
   
    ArrayType* replacementArrayType =
      create_array_type(theEnv,
	varType->get_element_type()->get_base_type()->get_bit_size(),
	0, // bit alignment
	OneLessDimension(originalSymbol->get_type(), dimensionality),
	dynamic_cast<Expression*>(varType->get_lower_bound()->deep_clone()),
	dynamic_cast<Expression*>(varType->get_upper_bound()->deep_clone()),
	TempName(varType->get_name())) ;

    procDef->get_symbol_table()->append_symbol_table_object(replacementArrayType) ;

    VariableSymbol* replacementArraySymbol = 
      create_variable_symbol(theEnv,
			     create_qualified_type(theEnv,
						   replacementArrayType,
						   TempName(LString("qualType"))),
			     TempName(replacementName)) ;

    procDef->get_symbol_table()->append_symbol_table_object(replacementArraySymbol) ;

    // Create a new symbol address expression for this variable symbol
    SymbolAddressExpression* replacementAddrExp =
      create_symbol_address_expression(theEnv,
				       replacementArrayType,
				       replacementArraySymbol) ;

    // Now, replace the symbol address expression in the base
    //  array address with this symbol.
    ReplaceSymbol(a->original, replacementAddrExp) ;
    
    // And replace this reference with the base array address.
    replacementExp = a->original->get_base_array_address() ;
    a->original->set_base_array_address(NULL) ;
    replacementExp->set_parent(NULL) ;
  }

  // Replace all of the equivalent expressions with the newly generated
  //  replacement expression.
  assert(replacementExp != NULL) ;
  a->original->get_parent()->replace(a->original, replacementExp) ;
   
  //  ReplaceChildExpression(a->original->get_parent(),
  //			 a->original,
  //			 replacementExp) ;

  list<ArrayReferenceExpression*>::iterator equivIter = 
    a->allEquivalent.begin() ;
  while (equivIter != a->allEquivalent.end()) 
  {
    (*equivIter)->get_parent()->replace((*equivIter),
					dynamic_cast<Expression*>(replacementExp->deep_clone())) ;
    //    ReplaceChildExpression((*equivIter)->get_parent(),
    //			   (*equivIter),
    //			   dynamic_cast<Expression*>(replacementExp->deep_clone())) ;
    ++equivIter ;
  }

  return true ;
}
コード例 #23
0
ファイル: Library.cpp プロジェクト: berezhkovskaya/Carousel3D
LString clLibrary::FindLibrary( const LString& LibName )
{
	// TODO
	if ( clFileSystem::FileExistsPhys( LibName ) ) { return LibName; }

	if ( clFileSystem::FileExistsPhys( AdditionalDLLPath + LibName ) ) { return AdditionalDLLPath + LibName; }

	if ( clFileSystem::FileExistsPhys( "..\\..\\" + AdditionalDLLPath + LibName ) ) { return LString( "..\\..\\" ) + AdditionalDLLPath + LibName; }

	return "";
}
コード例 #24
0
 output_node(int s_line, char* s_file, int o_line) {
   src_line = s_line;
   src_file = LString(s_file).c_str();
   out_line = o_line;
   mapped = false;
 }
コード例 #25
0
ファイル: NameLabelRenderer.hpp プロジェクト: CueMol/cuemol2
  virtual void styleChanged(qsys::StyleEvent &);

  virtual void objectChanged(qsys::ObjectEvent &ev);

  //////
  // Serialization / deserialization impl for non-prop data

  virtual void writeTo2(qlib::LDom2Node *pNode) const;
  virtual void readFrom2(qlib::LDom2Node *pNode);

  //////////////////////////////////////////////////////

  MolCoordPtr getClientMol() const;

  bool addLabelByID(int aid, const LString &label = LString());
  bool addLabel(MolAtomPtr patom, const LString &label = LString());

  bool removeLabelByID(int aid);

  void setMaxLabel(int nmax) { m_nMax = nmax; }
  int getMaxLabel() const { return m_nMax; }


  void setFontSize(double val);
  double getFontSize() const { return m_dFontSize; }
  
  void setFontName(const LString &val);
  LString getFontName() const { return m_strFontName; }
  
  void setFontStyle(const LString &val);
コード例 #26
0
 /// Convert object (rend, obj, cam) to bytearray
 qlib::LScrSp<qlib::LByteArray> toByteArray(const qlib::LScrSp<qlib::LScrObjBase> &pSObj)
 {
   return toByteArray(pSObj, LString());
 }
コード例 #27
0
void CombineSummationPass::do_procedure_definition(ProcedureDefinition* p)
{
  procDef = p ;
  assert(procDef != NULL) ;

  OutputInformation("Combine summation pass begins") ;

  StatementList* innermost = InnermostList(procDef) ;
  assert(innermost != NULL) ;

  bool change = false ;
  do
  {
    // Find the first summation
    StoreVariableStatement* firstStatement = NULL ;
    StoreVariableStatement* secondStatement = NULL ;
    change = false ;
    int i ;
    int firstStatementPosition = -1 ;
    i = 0 ;
    while (i < innermost->get_statement_count())
    {
      StoreVariableStatement* currentStoreVariable =
	dynamic_cast<StoreVariableStatement*>(innermost->get_statement(i)) ;
      if (currentStoreVariable != NULL && IsSummation(currentStoreVariable))
      {
	firstStatement = currentStoreVariable ;
	firstStatementPosition = i ;
	break ;
      }
	++i ;
    }
    
    if (firstStatement != NULL)
    {
      VariableSymbol* firstDest = firstStatement->get_destination() ;
      for (int j = i+1 ; j < innermost->get_statement_count() ; ++j)
      {
	StoreVariableStatement* nextStoreVar = 
	  dynamic_cast<StoreVariableStatement*>(innermost->get_statement(j));
	if (nextStoreVar != NULL && IsSummation(nextStoreVar, firstDest))
	{
	  secondStatement = nextStoreVar ;
	  break ;
	}
	if (IsDefinition(innermost->get_statement(j), firstDest) ||
	    HasUses(innermost->get_statement(j), firstDest))
	{
	  break ;
	}						
      }
    }
    if (secondStatement != NULL)
    {
      // Go through each of the variables used in the first statement and
      //  make sure there are no definitions to any of them.
      //  I only have to worry about variables and not array accesses because
      //  we don't allow them to read and write to array values.
      int originalPosition = DeterminePosition(innermost, firstStatement) ;
      assert(originalPosition >= 0) ;
      list<VariableSymbol*> usedVars = 
	AllUsedVariablesBut(firstStatement, firstStatement->get_destination());
      bool goodPath = true ;
      for (int j = originalPosition ; 
	   j < innermost->get_statement_count() && 
	     innermost->get_statement(j) != secondStatement ; 
	   ++j)
      {
	list<VariableSymbol*>::iterator usedIter = usedVars.begin() ;
	while (usedIter != usedVars.end())
	{
	  if (IsOutputVariable((*usedIter), innermost->get_statement(j)))
	  {
	    goodPath = false ;
	    break ;
	  }
	  ++usedIter ;
	}
	if (!goodPath) 
	{
	  break ;
	}
      }
      if (!goodPath)
      {
	continue ;
      }
      // Actually do the combining here
      change = true ;
      Expression* remains = RemoveValue(firstStatement) ;
      Expression* secondRemains = RemoveValue(secondStatement) ;
      // Create two binary expressions
      BinaryExpression* remainsSum = 
	create_binary_expression(theEnv,
				 remains->get_result_type(),
				 LString("add"),
				 remains,
				 secondRemains) ;
      LoadVariableExpression* loadDest = 
	create_load_variable_expression(theEnv,
	    secondStatement->get_destination()->get_type()->get_base_type(),
					secondStatement->get_destination()) ;
      BinaryExpression* finalSum =
	create_binary_expression(theEnv,
				 remainsSum->get_result_type(),
				 LString("add"),
				 remainsSum,
				 loadDest) ;

      secondStatement->set_value(finalSum) ;
      // Delete?
      innermost->remove_statement(firstStatementPosition) ;
    }
     
  } while (change == true) ;  

  OutputInformation("Combine summation pass ends") ;
}
コード例 #28
0
ファイル: cb_system.cpp プロジェクト: Latexi95/CBCompiler
void CBF_makeError(CBString errorMsg) {
	error(LString(errorMsg));
	sys::closeProgram();
}
コード例 #29
0
ファイル: cb_system.cpp プロジェクト: Latexi95/CBCompiler
int CBF_int(CBString s) {
	return LString(s).toInt();
}
コード例 #30
0
ファイル: ldir.cpp プロジェクト: Heather/Pyramid-Head
//------------------------------------------------------------------------------
void LDir::setPathCwd() {
    char _path[MAXPATHLEN];
    if(getcwd(_path, MAXPATHLEN) != NULL) {
        path = LString(_path);
        }
    }