/** * Inserts C-variable information from a map into a target scope in the program database. * * @param target a scope into which fields are to be inserted * @param fields a map of String->ContainedConnection. The ContainedConnection */ public static void transferFields( Scope<Namespace> target, Map<String, ContainedConnection<Entity, Field>> fields) { Collection<ContainedConnection<Entity, Field>> fieldSet = fields.values(); // Go over fields in the set, insert each of them to the target // scope for (ContainedConnection<Entity, Field> element : fieldSet) { // Each member of the fields map is a contained-connection which // describes field visibility and storage with reference to the // target scope Field field = element.getContained(); target.addMember(field, element.getVisibility(), element.getStorage()); } }
/** * Creates two big maps that associate names to their entities. * * @param anchor a scope to start scanning from */ private void collectEntitiesByName(Scope<? extends Entity> anchor) { // Go through the aggregates for (ContainedConnection<? extends Entity, Aggregate> connection : anchor.getAggregates()) { collectContained(connection); // - descend Aggregate aggregate = connection.getContained(); collectEntitiesByName(aggregate.getScope()); } // Go through aliases for (ContainedConnection<? extends Entity, Alias> connection : anchor.getAliass()) { collectContained(connection); } // Go through enumerated types for (ContainedConnection<? extends Entity, sourceanalysis.Enum> connection : anchor.getEnums()) { collectContained(connection); } // Even go through constant data members for (ContainedConnection<? extends Entity, Field> connection : anchor.getFields()) { Field field = connection.getContained(); try { Type type = field.getType(); if (type.isFlat() && type.isConst() && type.getBaseType() instanceof Primitive) collectContained(connection); } catch (MissingInformationException e) { // Fields with no type are ignored } } // Look in inner namespace scopes for (ContainedConnection<? extends Entity, Namespace> connection : anchor.getNamespaces()) { // - descend Namespace namespace = connection.getContained(); collectEntitiesByName(namespace.getScope()); } }
/** * Inserts a single entity to both maps using a ContainedConnection. * * @param connection a ContainedConnection pointing to current entity */ private void collectContained( ContainedConnection<? extends Entity, ? extends Entity> connection) { Entity inside = connection.getContained(); m_entitiesByName.put(inside.getName(), inside); m_entitiesByFullName.put(inside.getFullName(), inside); }