Esempio n. 1
0
/** reads the next token from the input file into the token buffer; returns whether a token was read */
static
SCIP_Bool getNextToken(
    BLKINPUT*             blkinput            /**< BLK reading data */
)
{
    SCIP_Bool hasdot;
    BLKEXPTYPE exptype;
    char* buf;
    int tokenlen;

    assert(blkinput != NULL);
    assert(blkinput->linepos < BLK_MAX_LINELEN);

    /* check the token stack */
    if( blkinput->npushedtokens > 0 )
    {
        swapPointers(&blkinput->token, &blkinput->pushedtokens[blkinput->npushedtokens-1]);
        blkinput->npushedtokens--;
        SCIPdebugMessage("(line %d) read token again: '%s'\n", blkinput->linenumber, blkinput->token);
        return TRUE;
    }

    /* skip delimiters */
    buf = blkinput->linebuf;
    while( isDelimChar(buf[blkinput->linepos]) )
    {
        if( buf[blkinput->linepos] == '\0' )
        {
            if( !getNextLine(blkinput) )
            {
                blkinput->section = BLK_END;
                SCIPdebugMessage("(line %d) end of file\n", blkinput->linenumber);
                return FALSE;
            }
            assert(blkinput->linepos == 0);
        }
        else
            blkinput->linepos++;
    }
    assert(blkinput->linepos < BLK_MAX_LINELEN);
    assert(!isDelimChar(buf[blkinput->linepos]));

    /* check if the token is a value */
    hasdot = FALSE;
    exptype = BLK_EXP_NONE;
    if( isValueChar(buf[blkinput->linepos], buf[blkinput->linepos+1], TRUE, &hasdot, &exptype) ) /*lint !e679*/
    {
        /* read value token */
        tokenlen = 0;
        do
        {
            assert(tokenlen < BLK_MAX_LINELEN);
            assert(!isDelimChar(buf[blkinput->linepos]));
            blkinput->token[tokenlen] = buf[blkinput->linepos];
            ++tokenlen;
            ++(blkinput->linepos);
            assert(blkinput->linepos < BLK_MAX_LINELEN);
        }
        while( isValueChar(buf[blkinput->linepos], buf[blkinput->linepos+1], FALSE, &hasdot, &exptype) ); /*lint !e679*/
    }
    else
    {
        /* read non-value token */
        tokenlen = 0;
        do
        {
            assert(tokenlen < BLK_MAX_LINELEN);
            blkinput->token[tokenlen] = buf[blkinput->linepos];
            tokenlen++;
            blkinput->linepos++;
            if( tokenlen == 1 && isTokenChar(blkinput->token[0]) )
                break;
        }
        while( !isDelimChar(buf[blkinput->linepos]) && !isTokenChar(buf[blkinput->linepos]) );

        /* if the token is an equation sense '<', '>', or '=', skip a following '='
         * if the token is an equality token '=' and the next character is a '<' or '>', replace the token by the inequality sense
         */
        if( tokenlen >= 1
                && (blkinput->token[tokenlen-1] == '<' || blkinput->token[tokenlen-1] == '>' || blkinput->token[tokenlen-1] == '=')
                && buf[blkinput->linepos] == '=' )
        {
            blkinput->linepos++;
        }
        else if( blkinput->token[tokenlen-1] == '=' && (buf[blkinput->linepos] == '<' || buf[blkinput->linepos] == '>') )
        {
            blkinput->token[tokenlen-1] = buf[blkinput->linepos];
            blkinput->linepos++;
        }
    }
    assert(tokenlen < BLK_MAX_LINELEN);
    blkinput->token[tokenlen] = '\0';

    SCIPdebugMessage("(line %d) read token: '%s'\n", blkinput->linenumber, blkinput->token);

    return TRUE;
}
Esempio n. 2
0
GpiObjHdl *FliImpl::create_gpi_obj_from_handle(void *hdl, std::string &name, std::string &fq_name, int accType, int accFullType)
{
    GpiObjHdl *new_obj = NULL;

    LOG_DEBUG("Attepmting to create GPI object from handle (Type=%d, FullType=%d).", accType, accFullType);
    if (!VS_TYPE_IS_VHDL(accFullType)) {
        LOG_DEBUG("Handle is not a VHDL type.");
        return NULL;
    }

    if (!isTypeValue(accType)) {
        /* Need a Pseudo-region to handle generate loops in a consistent manner across interfaces
         * and across the different methods of accessing data.
         */
        std::string rgn_name = mti_GetRegionName(static_cast<mtiRegionIdT>(hdl));
        if (name != rgn_name) {
            LOG_DEBUG("Found pseudo-region %s -> %p", fq_name.c_str(), hdl);
            new_obj = new FliObjHdl(this, hdl, GPI_GENARRAY, accType, accFullType);
        } else {
            LOG_DEBUG("Found region %s -> %p", fq_name.c_str(), hdl);
            new_obj = new FliObjHdl(this, hdl, GPI_MODULE, accType, accFullType);
        }
    } else {
        bool is_var;
        bool is_const;
        mtiTypeIdT valType;
        mtiTypeKindT typeKind;

        if (isTypeSignal(accType, accFullType)) {
            LOG_DEBUG("Found a signal %s -> %p", fq_name.c_str(), hdl);
            is_var   = false;
            is_const = false;
            valType  = mti_GetSignalType(static_cast<mtiSignalIdT>(hdl));
        } else {
            LOG_DEBUG("Found a variable %s -> %p", fq_name.c_str(), hdl);
            is_var   = true;
            is_const = isValueConst(accFullType);
            valType  = mti_GetVarType(static_cast<mtiVariableIdT>(hdl));
        }

        typeKind = mti_GetTypeKind(valType);

        switch (typeKind) {
            case MTI_TYPE_ENUM:
                if (isValueLogic(valType)) {
                    new_obj = new FliLogicObjHdl(this, hdl, GPI_REGISTER, is_const, accType, accFullType, is_var, valType, typeKind);
                } else if (isValueBoolean(valType) || isValueChar(valType)) {
                    new_obj = new FliIntObjHdl(this, hdl, GPI_INTEGER, is_const, accType, accFullType, is_var, valType, typeKind);
                } else {
                    new_obj = new FliEnumObjHdl(this, hdl, GPI_ENUM, is_const, accType, accFullType, is_var, valType, typeKind);
                }
                break;
            case MTI_TYPE_SCALAR:
            case MTI_TYPE_PHYSICAL:
                new_obj = new FliIntObjHdl(this, hdl, GPI_INTEGER, is_const, accType, accFullType, is_var, valType, typeKind);
                break;
            case MTI_TYPE_REAL:
                new_obj = new FliRealObjHdl(this, hdl, GPI_REAL, is_const, accType, accFullType, is_var, valType, typeKind);
                break;
            case MTI_TYPE_ARRAY: {
                    mtiTypeIdT   elemType     = mti_GetArrayElementType(valType);
                    mtiTypeKindT elemTypeKind = mti_GetTypeKind(elemType);

                    switch (elemTypeKind) {
                        case MTI_TYPE_ENUM:
                            if (isValueLogic(elemType)) {
                                new_obj = new FliLogicObjHdl(this, hdl, GPI_REGISTER, is_const, accType, accFullType, is_var, valType, typeKind); // std_logic_vector
                            } else if (isValueChar(elemType)) {
                                new_obj = new FliStringObjHdl(this, hdl, GPI_STRING, is_const, accType, accFullType, is_var, valType, typeKind);
                            } else {
                                new_obj = new FliValueObjHdl(this, hdl, GPI_ARRAY, false, accType, accFullType, is_var, valType, typeKind); // array of enums
                            }
                            break;
                        default:
                            new_obj = new FliValueObjHdl(this, hdl, GPI_ARRAY, false, accType, accFullType, is_var, valType, typeKind);// array of (array, Integer, Real, Record, etc.) 
                    }
                }
                break;
            case MTI_TYPE_RECORD:
                new_obj = new FliValueObjHdl(this, hdl, GPI_STRUCTURE, false, accType, accFullType, is_var, valType, typeKind);
                break;
            default:
                LOG_ERROR("Unable to handle object type for %s (%d)", name.c_str(), typeKind);
                return NULL;
        }
    }

    if (NULL == new_obj) {
        LOG_DEBUG("Didn't find anything named %s", fq_name.c_str());
        return NULL;
    }

    if (new_obj->initialise(name,fq_name) < 0) {
        LOG_ERROR("Failed to initialise the handle %s", name.c_str());
        delete new_obj;
        return NULL;
    }

    return new_obj;
}
Esempio n. 3
0
/** reads the next token from the input file into the token buffer; returns whether a token was read */
static
SCIP_Bool getNextToken(
   SCIP*                 scip,               /**< SCIP data structure */
   LPINPUT*              lpinput             /**< LP reading data */
   )
{
   SCIP_Bool hasdot;
   LPEXPTYPE exptype;
   char* buf;
   int tokenlen;

   assert(lpinput != NULL);
   assert(lpinput->linepos < LP_MAX_LINELEN);

   /* check the token stack */
   if( lpinput->npushedtokens > 0 )
   {
      swapPointers(&lpinput->token, &lpinput->pushedtokens[lpinput->npushedtokens-1]);
      lpinput->npushedtokens--;

      SCIPdebugMessage("(line %d) read token again: '%s'\n", lpinput->linenumber, lpinput->token);
      return TRUE;
   }

   /* skip delimiters */
   buf = lpinput->linebuf;
   while( isDelimChar(buf[lpinput->linepos]) )
   {
      if( buf[lpinput->linepos] == '\0' )
      {
         if( !getNextLine(scip, lpinput) )
         {
            lpinput->section = LP_END;
            SCIPdebugMessage("(line %d) end of file\n", lpinput->linenumber);
            return FALSE;
         }
         assert(lpinput->linepos == 0);
      }
      else
         lpinput->linepos++;
   }
   assert(lpinput->linepos < LP_MAX_LINELEN);
   assert(!isDelimChar(buf[lpinput->linepos]));

   /* check if the token is a value */
   hasdot = FALSE;
   exptype = LP_EXP_NONE;
   if( isValueChar(buf[lpinput->linepos], buf[lpinput->linepos+1], TRUE, &hasdot, &exptype) )
   {
      /* read value token */
      tokenlen = 0;
      do
      {
         assert(tokenlen < LP_MAX_LINELEN);
         assert(!isDelimChar(buf[lpinput->linepos]));
         lpinput->token[tokenlen] = buf[lpinput->linepos];
         tokenlen++;
         lpinput->linepos++;
      }
      while( isValueChar(buf[lpinput->linepos], buf[lpinput->linepos+1], FALSE, &hasdot, &exptype) );
   }
   else
   {
      /* read non-value token */
      tokenlen = 0;
      do
      {
         assert(tokenlen < LP_MAX_LINELEN);
         lpinput->token[tokenlen] = buf[lpinput->linepos];
         tokenlen++;
         lpinput->linepos++;
         if( tokenlen == 1 && isTokenChar(lpinput->token[0]) )
            break;
      }
      while( !isDelimChar(buf[lpinput->linepos]) && !isTokenChar(buf[lpinput->linepos]) );

      /* if the token is a power sign '^', skip a following '2'
       * if the token is an equation sense '<', '>', or '=', skip a following '='
       * if the token is an equality token '=' and the next character is a '<' or '>', replace the token by the inequality sense
       */
      if( tokenlen >= 1 && lpinput->token[tokenlen-1] == '^' && buf[lpinput->linepos] == '2' )
      {
         lpinput->linepos++;
      }
      if( tokenlen >= 1
         && (lpinput->token[tokenlen-1] == '<' || lpinput->token[tokenlen-1] == '>' || lpinput->token[tokenlen-1] == '=')
         && buf[lpinput->linepos] == '=' )
      {
         lpinput->linepos++;
      }
      else if( lpinput->token[tokenlen-1] == '=' && (buf[lpinput->linepos] == '<' || buf[lpinput->linepos] == '>') )
      {
         lpinput->token[tokenlen-1] = buf[lpinput->linepos];
         lpinput->linepos++;
      }
   }
   assert(tokenlen < LP_MAX_LINELEN);
   lpinput->token[tokenlen] = '\0';

   SCIPdebugMessage("(line %d) read token: '%s'\n", lpinput->linenumber, lpinput->token);

   return TRUE;
}