Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions rasn-compiler/src/validator/linking/constraints.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use std::collections::BTreeMap;
use std::collections::HashMap;

use crate::intermediate::{constraints::*, error::*, *};

impl Constraint {
pub(super) fn link_cross_reference(
&mut self,
identifier: &String,
tlds: &BTreeMap<String, ToplevelDefinition>,
tlds: &HashMap<String, ToplevelDefinition>,
) -> Result<(), GrammarError> {
match self {
Constraint::Subtype(t) => t.set.link_cross_reference(identifier, tlds),
Expand All @@ -27,7 +27,7 @@ impl SubtypeElements {
pub(super) fn link_cross_reference(
&mut self,
identifier: &String,
tlds: &BTreeMap<String, ToplevelDefinition>,
tlds: &HashMap<String, ToplevelDefinition>,
) -> Result<(), GrammarError> {
match self {
SubtypeElements::SingleValue {
Expand Down Expand Up @@ -117,7 +117,7 @@ impl ElementOrSetOperation {
pub(super) fn link_cross_reference(
&mut self,
identifier: &String,
tlds: &BTreeMap<String, ToplevelDefinition>,
tlds: &HashMap<String, ToplevelDefinition>,
) -> Result<(), GrammarError> {
match self {
ElementOrSetOperation::Element(e) => e.link_cross_reference(identifier, tlds),
Expand Down
24 changes: 12 additions & 12 deletions rasn-compiler/src/validator/linking/information_object.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::BTreeMap;
use std::collections::HashMap;

use crate::intermediate::{information_object::*, *};

Expand All @@ -8,7 +8,7 @@ use super::{
};

impl ToplevelInformationDefinition {
pub fn resolve_class_reference(mut self, tlds: &BTreeMap<String, ToplevelDefinition>) -> Self {
pub fn resolve_class_reference(mut self, tlds: &HashMap<String, ToplevelDefinition>) -> Self {
if let ClassLink::ByName(name) = &self.class {
if let Some(ToplevelDefinition::Class(c)) = tlds.get(name) {
self.class = ClassLink::ByReference(c.definition.clone());
Expand All @@ -22,7 +22,7 @@ impl ToplevelInformationDefinition {
/// values in `SET`s or `SEQUENCE`s.
pub fn collect_supertypes(
&mut self,
tlds: &BTreeMap<String, ToplevelDefinition>,
tlds: &HashMap<String, ToplevelDefinition>,
) -> Result<(), GrammarError> {
match (&mut self.value, &self.class) {
(ASN1Information::Object(ref mut o), ClassLink::ByReference(class)) => {
Expand Down Expand Up @@ -63,7 +63,7 @@ impl ToplevelInformationDefinition {
fn resolve_and_link(
fields: &mut InformationObjectFields,
class: &ObjectClassDefn,
tlds: &BTreeMap<String, ToplevelDefinition>,
tlds: &HashMap<String, ToplevelDefinition>,
) -> Result<Option<ToplevelInformationDefinition>, GrammarError> {
match resolve_custom_syntax(fields, class) {
Ok(()) => link_object_fields(fields, class, tlds).map(|_| None),
Expand Down Expand Up @@ -91,7 +91,7 @@ fn resolve_and_link(
fn link_object_fields(
fields: &mut InformationObjectFields,
class: &ObjectClassDefn,
tlds: &BTreeMap<String, ToplevelDefinition>,
tlds: &HashMap<String, ToplevelDefinition>,
) -> Result<(), GrammarError> {
match fields {
InformationObjectFields::DefaultSyntax(ref mut fields) => {
Expand Down Expand Up @@ -136,7 +136,7 @@ fn link_object_fields(
impl ASN1Information {
pub fn link_object_set_reference(
&mut self,
tlds: &BTreeMap<String, ToplevelDefinition>,
tlds: &HashMap<String, ToplevelDefinition>,
) -> bool {
match self {
ASN1Information::ObjectSet(s) => s.link_object_set_reference(tlds),
Expand All @@ -155,7 +155,7 @@ impl ASN1Information {
impl SyntaxApplication {
pub fn link_object_set_reference(
&mut self,
tlds: &BTreeMap<String, ToplevelDefinition>,
tlds: &HashMap<String, ToplevelDefinition>,
) -> bool {
match self {
SyntaxApplication::ObjectSetDeclaration(o) => o.link_object_set_reference(tlds),
Expand Down Expand Up @@ -183,7 +183,7 @@ impl ObjectClassDefn {
impl InformationObject {
pub fn link_object_set_reference(
&mut self,
tlds: &BTreeMap<String, ToplevelDefinition>,
tlds: &HashMap<String, ToplevelDefinition>,
) -> bool {
match &mut self.fields {
InformationObjectFields::DefaultSyntax(d) => d
Expand All @@ -210,7 +210,7 @@ impl InformationObject {
impl ObjectSetValue {
pub fn link_object_set_reference(
&mut self,
tlds: &BTreeMap<String, ToplevelDefinition>,
tlds: &HashMap<String, ToplevelDefinition>,
) -> Option<Vec<ObjectSetValue>> {
match self {
ObjectSetValue::Reference(id) => match tlds.get(id) {
Expand Down Expand Up @@ -256,7 +256,7 @@ impl ObjectSetValue {
impl ObjectSet {
pub fn link_object_set_reference(
&mut self,
tlds: &BTreeMap<String, ToplevelDefinition>,
tlds: &HashMap<String, ToplevelDefinition>,
) -> bool {
let mut flattened: Vec<_> = self
.values
Expand All @@ -275,7 +275,7 @@ impl ObjectSet {

pub fn resolve_object_set_references(
&mut self,
tlds: &BTreeMap<String, ToplevelDefinition>,
tlds: &HashMap<String, ToplevelDefinition>,
) -> Result<(), GrammarError> {
let mut flattened_members = Vec::new();
let mut needs_recursing = false;
Expand Down Expand Up @@ -318,7 +318,7 @@ impl ObjectSet {
impl InformationObjectField {
pub fn link_object_set_reference(
&mut self,
tlds: &BTreeMap<String, ToplevelDefinition>,
tlds: &HashMap<String, ToplevelDefinition>,
) -> bool {
match self {
InformationObjectField::ObjectSetField(ObjectSetField { value, .. }) => {
Expand Down
52 changes: 26 additions & 26 deletions rasn-compiler/src/validator/linking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ mod utils;

use std::{
borrow::{BorrowMut, Cow},
collections::BTreeMap,
collections::{BTreeMap, HashMap},
};

use crate::{
Expand Down Expand Up @@ -117,7 +117,7 @@ impl ToplevelDefinition {
pub fn recurses(
&self,
name: &str,
tlds: &BTreeMap<String, ToplevelDefinition>,
tlds: &HashMap<String, ToplevelDefinition>,
reference_graph: Vec<&str>,
) -> bool {
match self {
Expand Down Expand Up @@ -183,7 +183,7 @@ impl ToplevelDefinition {
/// returns `true` if the reference was resolved successfully.
pub fn link_constraint_reference(
&mut self,
tlds: &BTreeMap<String, ToplevelDefinition>,
tlds: &HashMap<String, ToplevelDefinition>,
) -> Result<bool, GrammarError> {
match self {
ToplevelDefinition::Type(t) => {
Expand All @@ -200,7 +200,7 @@ impl ToplevelDefinition {
/// Traverses top-level declarations and marks recursive types
pub fn mark_recursive(
&mut self,
tlds: &BTreeMap<String, ToplevelDefinition>,
tlds: &HashMap<String, ToplevelDefinition>,
) -> Result<(), GrammarError> {
match self {
ToplevelDefinition::Type(t) => {
Expand All @@ -217,7 +217,7 @@ impl ToplevelDefinition {
/// Collects supertypes of ASN1 values.
pub fn collect_supertypes(
&mut self,
tlds: &BTreeMap<String, ToplevelDefinition>,
tlds: &HashMap<String, ToplevelDefinition>,
) -> Result<(), GrammarError> {
match self {
ToplevelDefinition::Type(t) => t.ty.collect_supertypes(tlds),
Expand All @@ -243,7 +243,7 @@ impl ToplevelValueDefinition {
/// The supertypes are recorded in a `LinkedASN1Value`
pub fn collect_supertypes(
&mut self,
tlds: &BTreeMap<String, ToplevelDefinition>,
tlds: &HashMap<String, ToplevelDefinition>,
) -> Result<(), GrammarError> {
if let Some(ToplevelDefinition::Type(tld)) =
tlds.get(self.associated_type.as_str().as_ref())
Expand All @@ -261,7 +261,7 @@ impl ASN1Type {
/// values in `SET`s or `SEQUENCE`s.
pub fn collect_supertypes(
&mut self,
tlds: &BTreeMap<String, ToplevelDefinition>,
tlds: &HashMap<String, ToplevelDefinition>,
) -> Result<(), GrammarError> {
match self {
ASN1Type::Set(ref mut s) | ASN1Type::Sequence(ref mut s) => {
Expand Down Expand Up @@ -297,7 +297,7 @@ impl ASN1Type {

pub fn link_choice_selection_type(
&mut self,
tlds: &BTreeMap<String, ToplevelDefinition>,
tlds: &HashMap<String, ToplevelDefinition>,
) -> Result<(), GrammarError> {
match self {
ASN1Type::ChoiceSelectionType(c) => {
Expand Down Expand Up @@ -346,7 +346,7 @@ impl ASN1Type {

pub fn link_components_of_notation(
&mut self,
tlds: &BTreeMap<String, ToplevelDefinition>,
tlds: &HashMap<String, ToplevelDefinition>,
) -> bool {
match self {
ASN1Type::Choice(c) => c
Expand Down Expand Up @@ -389,7 +389,7 @@ impl ASN1Type {
pub fn link_constraint_reference(
&mut self,
name: &String,
tlds: &BTreeMap<String, ToplevelDefinition>,
tlds: &HashMap<String, ToplevelDefinition>,
) -> Result<Option<ASN1Type>, GrammarError> {
let mut self_replacement = None;
match self {
Expand Down Expand Up @@ -470,7 +470,7 @@ impl ASN1Type {
pub(crate) fn resolve_parameters(
identifier: &String,
_parent: Option<&String>,
tlds: &BTreeMap<String, ToplevelDefinition>,
tlds: &HashMap<String, ToplevelDefinition>,
args: &[Parameter],
) -> Result<ASN1Type, GrammarError> {
match tlds.get(identifier) {
Expand Down Expand Up @@ -567,7 +567,7 @@ impl ASN1Type {
pub fn recurses(
&self,
name: &str,
tlds: &BTreeMap<String, ToplevelDefinition>,
tlds: &HashMap<String, ToplevelDefinition>,
mut reference_graph: Vec<&str>,
) -> bool {
match self {
Expand Down Expand Up @@ -597,7 +597,7 @@ impl ASN1Type {
pub fn mark_recursive(
&mut self,
name: &str,
tlds: &BTreeMap<String, ToplevelDefinition>,
tlds: &HashMap<String, ToplevelDefinition>,
) -> Result<Vec<Cow<'_, str>>, GrammarError> {
match self {
ASN1Type::Choice(choice) => {
Expand Down Expand Up @@ -698,7 +698,7 @@ impl ASN1Type {

fn link_elsewhere_declared(
&mut self,
tlds: &BTreeMap<String, ToplevelDefinition>,
tlds: &HashMap<String, ToplevelDefinition>,
) -> Result<(), GrammarError> {
match self {
ASN1Type::Choice(c) => c
Expand Down Expand Up @@ -805,7 +805,7 @@ impl ASN1Type {
}
}

pub fn resolve_class_reference(self, tlds: &BTreeMap<String, ToplevelDefinition>) -> Self {
pub fn resolve_class_reference(self, tlds: &HashMap<String, ToplevelDefinition>) -> Self {
match self {
ASN1Type::Choice(c) => ASN1Type::Choice(Choice {
extensible: c.extensible,
Expand Down Expand Up @@ -841,7 +841,7 @@ impl ASN1Type {
}
}

fn reassign_type_for_ref(mut self, tlds: &BTreeMap<String, ToplevelDefinition>) -> Self {
fn reassign_type_for_ref(mut self, tlds: &HashMap<String, ToplevelDefinition>) -> Self {
if let Self::ObjectClassField(ref ocf) = self {
if let Some(t) = tlds
.iter()
Expand All @@ -860,7 +860,7 @@ impl ASN1Type {

pub fn link_subtype_constraint(
&mut self,
tlds: &BTreeMap<String, ToplevelDefinition>,
tlds: &HashMap<String, ToplevelDefinition>,
) -> Result<(), GrammarError> {
if let Self::ElsewhereDeclaredType(e) = self {
if let Some(ToplevelDefinition::Type(t)) = tlds.get(&e.identifier) {
Expand All @@ -874,7 +874,7 @@ impl ASN1Type {
impl ASN1Value {
pub fn link_with_type(
&mut self,
tlds: &BTreeMap<String, ToplevelDefinition>,
tlds: &HashMap<String, ToplevelDefinition>,
ty: &ASN1Type,
type_name: Option<&String>,
) -> Result<(), GrammarError> {
Expand Down Expand Up @@ -1337,7 +1337,7 @@ impl ASN1Value {
}

fn link_enum_or_distinguished(
tlds: &BTreeMap<String, ToplevelDefinition>,
tlds: &HashMap<String, ToplevelDefinition>,
e: &DeclarationElsewhere,
identifier: &mut String,
mut supertypes: Vec<String>,
Expand Down Expand Up @@ -1400,7 +1400,7 @@ impl ASN1Value {
fn link_array_like(
val: &mut [(Option<String>, Box<ASN1Value>)],
s: &SequenceOrSetOf,
tlds: &BTreeMap<String, ToplevelDefinition>,
tlds: &HashMap<String, ToplevelDefinition>,
) -> Result<ASN1Value, GrammarError> {
let _ = val.iter_mut().try_for_each(|v| {
v.1.link_with_type(
Expand All @@ -1417,7 +1417,7 @@ impl ASN1Value {
fn link_struct_like(
val: &mut [(Option<String>, Box<ASN1Value>)],
s: &SequenceOrSet,
tlds: &BTreeMap<String, ToplevelDefinition>,
tlds: &HashMap<String, ToplevelDefinition>,
type_name: Option<&String>,
) -> Result<ASN1Value, GrammarError> {
val.iter_mut().try_for_each(|v| {
Expand Down Expand Up @@ -1494,7 +1494,7 @@ impl ASN1Value {
/// The `LDAP-SYNTAX` field refers to a field ob an information object `dn`.
pub fn resolve_elsewhere_with_parent(
&mut self,
tlds: &BTreeMap<String, ToplevelDefinition>,
tlds: &HashMap<String, ToplevelDefinition>,
) -> Result<(), GrammarError> {
if let Self::ElsewhereDeclaredValue {
module: None,
Expand Down Expand Up @@ -1586,7 +1586,7 @@ impl ASN1Value {
pub fn link_elsewhere_declared(
&mut self,
identifier: &String,
tlds: &BTreeMap<String, ToplevelDefinition>,
tlds: &HashMap<String, ToplevelDefinition>,
) -> Result<(), GrammarError> {
match self {
Self::ElsewhereDeclaredValue {
Expand Down Expand Up @@ -1632,7 +1632,7 @@ fn bit_string_value_from_named_bits(

#[cfg(test)]
mod tests {
use std::collections::BTreeMap;
use std::collections::HashMap;

use crate::intermediate::{types::*, *};

Expand All @@ -1651,8 +1651,8 @@ mod tests {

#[test]
fn links_asn1_value() {
let tlds: BTreeMap<String, ToplevelDefinition> = {
let mut map = BTreeMap::new();
let tlds: HashMap<String, ToplevelDefinition> = {
let mut map = HashMap::new();
map.insert(
"RootBool".into(),
ToplevelDefinition::Type(tld!(
Expand Down
4 changes: 2 additions & 2 deletions rasn-compiler/src/validator/linking/types.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::BTreeMap;
use std::collections::HashMap;

use super::{
ASN1Type, DeclarationElsewhere, GrammarError, ToplevelDefinition, ToplevelTypeDefinition,
Expand All @@ -7,7 +7,7 @@ use super::{
impl DeclarationElsewhere {
pub fn root<'a>(
&self,
tlds: &'a BTreeMap<String, ToplevelDefinition>,
tlds: &'a HashMap<String, ToplevelDefinition>,
) -> Result<&'a ASN1Type, GrammarError> {
match tlds.get(&self.identifier).ok_or_else(|| GrammarError::new(
&format!("Failed to resolve reference of ElsewhereDefined: {}", self.identifier),
Expand Down
4 changes: 2 additions & 2 deletions rasn-compiler/src/validator/linking/utils.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::BTreeMap;
use std::collections::HashMap;

use crate::{
intermediate::{
Expand All @@ -12,7 +12,7 @@ use crate::{
pub(crate) fn find_tld_or_enum_value_by_name(
type_name: &String,
name: &String,
tlds: &BTreeMap<String, ToplevelDefinition>,
tlds: &HashMap<String, ToplevelDefinition>,
) -> Option<ASN1Value> {
if let Some(ToplevelDefinition::Value(v)) = tlds.get(name) {
return Some(v.value.clone());
Expand Down
Loading
Loading