Commit b530e974 authored by Marius Bozga's avatar Marius Bozga
Browse files

support ranges on reals with default step fixed at 1

parent 86f32361
......@@ -128,7 +128,7 @@ extern const char* if_$1_name[];
`#define' print_func($1)(x,f) fprintf(f,"%s",if_$1_name[x])
`#define' print_func_xml($1)(x,b) b << "<$1 value=\"" << if_$1_name[x] << "\" />"
`#define' reset_func($1)(x) (x)=(type_name($1))0
`#define' iterate_func($1)(x) for(x=(type_name($1))0;x<=constant_name(last_item($@));x=(type_name($1))(x + 1))')
`#define' iterate_func($1)(x) for(x=constant_name($2);x<=constant_name(last_item($@));x=(type_name($1))(x+1))')
# enum_quote(e1,... en) #
......@@ -150,7 +150,7 @@ const char* if_$1_name[] = {
# Range Type #
# ----------------------------------------------------------------#
# range_type_decl(T,T1,l,u)
# range_type_decl(T,T1,l,u,s)
define(`range_type_decl', `
typedef type_name($2) type_name($1);
......@@ -160,7 +160,7 @@ typedef type_name($2) type_name($1);
`#define' print_func($1)(x,f) print_func($2)(x,f)
`#define' print_func_xml($1)(x,b) print_func_xml($2)(x,b)
`#define' reset_func($1)(x) (x)=$3
`#define' iterate_func($1)(x) for(x=$3;x<=$4;x++)')
`#define' iterate_func($1)(x) for(x=$3;x<=$4;x=(type_name($1))(x+$5))')
# range_type_impl(T,T1,l,u)
......
......@@ -150,7 +150,7 @@ void IfSystemEntity::Dump(FILE* file) const {
void IfSystemEntity::PreCompile() {
IfEntity::PreCompile();
int ok = 1, index = 0;
int ok = GetFlag(CORRECT), index = 0;
ok &= m_pResources->Compile();
......@@ -407,7 +407,7 @@ void IfProcessEntity::Link(IfSignalroute* route) {
void IfProcessEntity::PreCompile() {
IfEntity::PreCompile();
int ok = 1, index = 0;
int ok = GetFlag(CORRECT), index = 0;
ok &= m_pInstances->Compile();
ok &= m_pInstances->GetBase()->IsInteger();
......@@ -529,7 +529,7 @@ void IfObserverEntity::Dump(FILE* file) const {
void IfObserverEntity::PreCompile() {
IfEntity::PreCompile();
int ok = 1, index = 0;
int ok = GetFlag(CORRECT), index = 0;
m_pEntry->SetParent( NULL );
......
......@@ -208,7 +208,7 @@ void yywarning(const char* msg) {
char* name;
char** name_list;
int integer;
float probability;
float real;
}
%type <constant> constant constant_decl constant_body constant_value range_bound
......@@ -273,8 +273,7 @@ void yywarning(const char* msg) {
%type <name_list> option_set
%type <integer> integer priority_opt obs_kind
%type <probability> probability_opt
%type <real> real probability_opt
%type <name> priority_rule_id
%type <priority_rule> priority_decl
......@@ -419,7 +418,7 @@ type_value :
ENUM_K enum_decl_list ENDENUM_K
{ $$ = new IfEnumType($2, NULL); }
| RANGE_K range_bound DDOT_K range_bound
{ $$ = new IfRangeType($2, $4, NULL); }
{ $$ = new IfRangeType($2, $4, new IfIntegerConstant(1), NULL); }
| RECORD_K field_decl_set ENDRECORD_K
{ $$ = new IfRecordType($2, NULL); }
| ARRAY_K '[' constant_body ']' OF_K type
......@@ -459,6 +458,7 @@ type_list :
range_bound :
constant_body { $$ = $1; }
| '-' integer { $$ = new IfIntegerConstant(-$2, NULL); }
| '-' real { $$ = new IfRealConstant(-$2, NULL); }
;
/*
......@@ -1350,6 +1350,10 @@ integer :
_INTEGER_ { $$ = atoi(yytext); }
;
real :
_REAL_ { $$ = atof(yytext); }
;
option_set :
option_set option { int i = 0; while ($1[i]) i++; $1[i] = $2; $$ = $1; }
| /* empty */ { $$ = (char**) calloc(16, sizeof(char*)); }
......
......@@ -117,16 +117,19 @@ void IfEnumType::Code(FILE* file) const {
IfRangeType::IfRangeType(IfConstant* Lower,
IfConstant* Upper,
IfConstant* Step,
char* Name,
unsigned Flags)
: IfType(Name, Flags) {
m_pLower = Lower;
m_pUpper = Upper;
m_pStep = Step;
}
IfRangeType::~IfRangeType() {
if (!m_pLower->GetName()) delete m_pLower;
if (!m_pUpper->GetName()) delete m_pUpper;
if (!m_pStep->GetName()) delete m_pStep;
}
void IfRangeType::Dump(FILE* file) const {
......@@ -146,11 +149,19 @@ void IfRangeType::PreCompile() {
ok &= m_pLower->Compile();
if (!m_pUpper->GetName())
ok &= m_pUpper->Compile();
if (!m_pStep->GetName())
ok &= m_pStep->Compile();
ok &= m_pLower->GetType() == m_pUpper->GetType();
ok &= m_pLower->GetBase()->IsInteger() ||
m_pLower->GetBase()->IsEnum();
m_pLower->GetBase()->IsEnum() ||
m_pLower->GetBase()->IsReal();
ok &= m_pStep->GetBase()->IsInteger() ||
m_pStep->GetBase()->IsReal();
ok &= !m_pStep->GetBase()->IsReal() || m_pLower->GetBase()->IsReal();
SetFlag(CORRECT, ok);
}
......@@ -161,22 +172,11 @@ void IfRangeType::Code(FILE* file) const {
m_pLower->CodeNameOrValue(file);
fprintf(file, ",");
m_pUpper->CodeNameOrValue(file);
fprintf(file, ",");
m_pStep->CodeNameOrValue(file);
fprintf(file, ")");
}
int IfRangeType::GetSize() const {
int l = 0, u = 0;
if (m_pLower->GetBase()->IsInteger())
l = ((IfIntegerConstant*) m_pLower->GetBase())->GetValue();
if (m_pLower->GetBase()->IsEnum())
l = ((IfEnumConstant*) m_pLower->GetBase())->GetValue();
if (m_pUpper->GetBase()->IsInteger())
u = ((IfIntegerConstant*) m_pUpper->GetBase())->GetValue();
if (m_pUpper->GetBase()->IsEnum())
u = ((IfEnumConstant*) m_pUpper->GetBase())->GetValue();
return u-l;
}
/*
*
* record type
......
......@@ -158,6 +158,7 @@ class IfRangeType : public IfType {
public:
IfRangeType(IfConstant* Lower,
IfConstant* Upper,
IfConstant* Step,
char* Name,
unsigned Flags = 0);
virtual ~IfRangeType();
......@@ -165,11 +166,13 @@ class IfRangeType : public IfType {
public:
inline IfConstant* GetLower() const { return m_pLower; }
inline IfConstant* GetUpper() const { return m_pUpper; }
int GetSize() const;
inline IfConstant* GetStep() const { return m_pStep; }
inline void SetLower(const IfConstant* Lower)
{ m_pLower = (IfConstant*) Lower; }
inline void SetUpper(const IfConstant* Upper)
{ m_pUpper = (IfConstant*) Upper; }
inline void SetStep(const IfConstant* Step)
{ m_pStep = (IfConstant*) Step; }
public:
virtual int IsRange() const { return 1; }
......@@ -185,6 +188,7 @@ class IfRangeType : public IfType {
protected:
IfConstant* m_pLower;
IfConstant* m_pUpper;
IfConstant* m_pStep;
};
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment