2011-02-11 18:16:40 +01:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2011 Stephen Williams (steve@icarus.com)
|
|
|
|
|
*
|
|
|
|
|
* This source code is free software; you can redistribute it
|
|
|
|
|
* and/or modify it in source code form under the terms of the GNU
|
|
|
|
|
* General Public License as published by the Free Software
|
|
|
|
|
* Foundation; either version 2 of the License, or (at your option)
|
|
|
|
|
* any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
|
|
|
|
*/
|
|
|
|
|
|
2011-02-04 17:51:51 +01:00
|
|
|
#include "vhdlint.h"
|
|
|
|
|
#include <cstring>
|
|
|
|
|
#include <cstdlib>
|
|
|
|
|
#include <sstream>
|
|
|
|
|
|
2011-09-23 04:57:59 +02:00
|
|
|
using namespace std;
|
|
|
|
|
|
2011-02-04 17:51:51 +01:00
|
|
|
bool vhdlint::is_negative() const
|
|
|
|
|
{
|
|
|
|
|
return value_ < 0L;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool vhdlint::is_positive() const
|
|
|
|
|
{
|
|
|
|
|
return value_ > 0L;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool vhdlint::is_zero() const
|
|
|
|
|
{
|
|
|
|
|
return value_ == 0L;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vhdlint::vhdlint(const char* text)
|
|
|
|
|
{
|
|
|
|
|
unsigned text_length = strlen(text);
|
|
|
|
|
if(text_length == 0)
|
|
|
|
|
{
|
|
|
|
|
value_ = 0L;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2011-03-03 05:23:02 +01:00
|
|
|
|
2011-02-04 17:51:51 +01:00
|
|
|
char* new_text = new char[text_length + 1];
|
2011-03-03 05:23:02 +01:00
|
|
|
|
2011-02-04 17:51:51 +01:00
|
|
|
const char* ptr;
|
|
|
|
|
char* new_ptr;
|
2011-02-14 02:14:33 +01:00
|
|
|
for(ptr = text, new_ptr = new_text; *ptr != 0; ++ptr)
|
2011-02-04 17:51:51 +01:00
|
|
|
{
|
|
|
|
|
if(*ptr == '_')
|
|
|
|
|
continue;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
*new_ptr = *ptr;
|
|
|
|
|
++new_ptr;
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-02-14 02:14:33 +01:00
|
|
|
*new_ptr = 0;
|
2011-04-15 23:44:05 +02:00
|
|
|
|
2011-02-04 17:51:51 +01:00
|
|
|
istringstream str(new_text);
|
|
|
|
|
delete[] new_text;
|
2011-03-03 05:23:02 +01:00
|
|
|
|
2011-02-04 17:51:51 +01:00
|
|
|
//TODO: check if numbers greater than MAX_INT are handled correctly
|
|
|
|
|
str >> value_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vhdlint::vhdlint(const int64_t& val)
|
|
|
|
|
{
|
|
|
|
|
value_ = val;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vhdlint::vhdlint(const vhdlint& val)
|
|
|
|
|
{
|
|
|
|
|
value_ = val.as_long();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int64_t vhdlint::as_long() const
|
|
|
|
|
{
|
|
|
|
|
return value_;
|
2011-02-11 18:16:40 +01:00
|
|
|
}
|