Skip to content

Commit a060749

Browse files
committed
Add special pre-defined to_string functions
1 parent ae17851 commit a060749

File tree

1 file changed

+138
-5
lines changed

1 file changed

+138
-5
lines changed

vhdl_lang/src/analysis/standard.rs

Lines changed: 138 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,18 @@ impl<'a> StandardRegion<'a> {
5555
self.lookup_type("BOOLEAN")
5656
}
5757

58+
fn natural(&self) -> TypeEnt {
59+
self.lookup_type("NATURAL")
60+
}
61+
62+
fn real(&self) -> TypeEnt {
63+
self.lookup_type("REAL")
64+
}
65+
66+
fn time(&self) -> TypeEnt {
67+
self.lookup_type("TIME")
68+
}
69+
5870
fn file_open_kind(&self) -> TypeEnt {
5971
self.lookup_type("FILE_OPEN_KIND")
6072
}
@@ -374,11 +386,6 @@ impl<'a> StandardRegion<'a> {
374386
// function TO_STRING (VALUE: FILE_OPEN_KIND) return STRING;
375387
// function TO_STRING (VALUE: FILE_OPEN_STATUS) return STRING;
376388

377-
// @TODO Predefined overloaded TO_STRING operations
378-
// function TO_STRING (VALUE: REAL; DIGITS: NATURAL) return STRING;
379-
// function TO_STRING (VALUE: REAL; FORMAT: STRING) return STRING;
380-
// function TO_STRING (VALUE: TIME; UNIT: TIME) return STRING
381-
382389
for name in [
383390
"BOOLEAN",
384391
"BIT",
@@ -407,6 +414,132 @@ impl<'a> StandardRegion<'a> {
407414
res.extend(implicits);
408415
}
409416

417+
// Predefined overloaded TO_STRING operations
418+
// function TO_STRING (VALUE: REAL; DIGITS: NATURAL) return STRING;
419+
{
420+
let real = self.real();
421+
let natural = self.natural();
422+
let string = self.string();
423+
424+
let mut params = FormalRegion::new_params();
425+
params.add(Arc::new(NamedEntity::new(
426+
self.symbol("VALUE"),
427+
NamedEntityKind::Object(Object {
428+
class: ObjectClass::Constant,
429+
mode: Some(Mode::In),
430+
subtype: Subtype::new(real.to_owned()),
431+
has_default: false,
432+
}),
433+
real.decl_pos(),
434+
)));
435+
436+
params.add(Arc::new(NamedEntity::new(
437+
self.symbol("DIGITS"),
438+
NamedEntityKind::Object(Object {
439+
class: ObjectClass::Constant,
440+
mode: Some(Mode::In),
441+
subtype: Subtype::new(natural),
442+
has_default: false,
443+
}),
444+
real.decl_pos(),
445+
)));
446+
447+
let ent = Arc::new(NamedEntity::implicit(
448+
real.clone().into(),
449+
self.symbol("TO_STRING"),
450+
NamedEntityKind::Subprogram(Signature::new(params, Some(string))),
451+
real.decl_pos(),
452+
));
453+
454+
if let Some(implicit) = real.kind().implicits() {
455+
// This is safe because the standard package is analyzed in a single thread
456+
unsafe { implicit.push(&ent) };
457+
}
458+
res.push(ent);
459+
}
460+
461+
// function TO_STRING (VALUE: REAL; FORMAT: STRING) return STRING;
462+
{
463+
let real = self.real();
464+
let string = self.string();
465+
466+
let mut params = FormalRegion::new_params();
467+
params.add(Arc::new(NamedEntity::new(
468+
self.symbol("VALUE"),
469+
NamedEntityKind::Object(Object {
470+
class: ObjectClass::Constant,
471+
mode: Some(Mode::In),
472+
subtype: Subtype::new(real.to_owned()),
473+
has_default: false,
474+
}),
475+
real.decl_pos(),
476+
)));
477+
478+
params.add(Arc::new(NamedEntity::new(
479+
self.symbol("FORMAT"),
480+
NamedEntityKind::Object(Object {
481+
class: ObjectClass::Constant,
482+
mode: Some(Mode::In),
483+
subtype: Subtype::new(string.to_owned()),
484+
has_default: false,
485+
}),
486+
real.decl_pos(),
487+
)));
488+
489+
let ent = Arc::new(NamedEntity::implicit(
490+
real.clone().into(),
491+
self.symbol("TO_STRING"),
492+
NamedEntityKind::Subprogram(Signature::new(params, Some(string))),
493+
real.decl_pos(),
494+
));
495+
496+
if let Some(implicit) = real.kind().implicits() {
497+
// This is safe because the standard package is analyzed in a single thread
498+
unsafe { implicit.push(&ent) };
499+
}
500+
res.push(ent);
501+
}
502+
503+
// function TO_STRING (VALUE: TIME; UNIT: TIME) return STRING
504+
{
505+
let time = self.time();
506+
let string = self.string();
507+
let mut params = FormalRegion::new_params();
508+
params.add(Arc::new(NamedEntity::new(
509+
self.symbol("VALUE"),
510+
NamedEntityKind::Object(Object {
511+
class: ObjectClass::Constant,
512+
mode: Some(Mode::In),
513+
subtype: Subtype::new(time.to_owned()),
514+
has_default: false,
515+
}),
516+
time.decl_pos(),
517+
)));
518+
519+
params.add(Arc::new(NamedEntity::new(
520+
self.symbol("UNIT"),
521+
NamedEntityKind::Object(Object {
522+
class: ObjectClass::Constant,
523+
mode: Some(Mode::In),
524+
subtype: Subtype::new(time.to_owned()),
525+
has_default: false,
526+
}),
527+
time.decl_pos(),
528+
)));
529+
530+
let ent = Arc::new(NamedEntity::implicit(
531+
time.clone().into(),
532+
self.symbol("TO_STRING"),
533+
NamedEntityKind::Subprogram(Signature::new(params, Some(string))),
534+
time.decl_pos(),
535+
));
536+
537+
if let Some(implicit) = time.kind().implicits() {
538+
// This is safe because the standard package is analyzed in a single thread
539+
unsafe { implicit.push(&ent) };
540+
}
541+
res.push(ent);
542+
}
410543
res
411544
}
412545
}

0 commit comments

Comments
 (0)