public StepFile ReadFile() { var fileSyntax = _lexer.LexFileSyntax(); foreach (var headerMacro in fileSyntax.Header.Macros) { ApplyHeaderMacro(headerMacro); } var itemMap = new Dictionary <int, List <StepRepresentationItem> >(); var binder = new StepBinder(itemMap); StepRepresentationItem.UnsupportedItemTypes.Clear(); foreach (var itemInstance in fileSyntax.Data.ItemInstances) { if (itemMap.ContainsKey(itemInstance.Id)) { throw new StepReadException("Duplicate item instance", itemInstance.Line, itemInstance.Column); } List <StepRepresentationItem> items = new List <StepRepresentationItem>(); if (itemInstance.SimpleItemInstance is StepSimpleItemSyntax) { var item = StepRepresentationItem.FromTypedParameterToItem(binder, itemInstance.SimpleItemInstance, itemInstance.Id); if (item != null) { items.Add(item); } } else if (itemInstance.SimpleItemInstance is StepComplexItemSyntax) { items = StepRepresentationItem.FromTypedParameterToItems(binder, itemInstance.SimpleItemInstance, itemInstance.Id); } else { LogWriter.Instance.WriteErrorLog("Unsupported step item syntax " + itemInstance.SimpleItemInstance.GetType().Name); } if (items.Count > 0) { itemMap.Add(itemInstance.Id, items); foreach (var item in items) { _file.Items.Add(item); } } } binder.BindRemainingValues(); return(_file); }
public void BindValue(StepSyntax syntax, Action <StepBoundItem> bindAction) { if (syntax is StepSimpleItemSyntax) { var typedParameter = (StepSimpleItemSyntax)syntax; var item = StepRepresentationItem.FromTypedParameterToItem(this, typedParameter, typedParameter.Id); var boundItem = new StepBoundItem(item, syntax); bindAction(boundItem); } else if (syntax is StepEntityInstanceReferenceSyntax) { var itemInstance = (StepEntityInstanceReferenceSyntax)syntax; if (_itemMap.ContainsKey(itemInstance.Id)) { // pointer already defined, bind immediately foreach (var item in _itemMap[itemInstance.Id]) { var boundItem = new StepBoundItem(item, syntax); bindAction(boundItem); } } else { // not already defined, save it for later if (!_unboundPointers.ContainsKey(itemInstance.Id)) { _unboundPointers.Add(itemInstance.Id, new List <Tuple <StepSyntax, Action <StepBoundItem> > >()); } _unboundPointers[itemInstance.Id].Add(Tuple.Create(syntax, bindAction)); } } else if (syntax is StepAutoSyntax) { bindAction(StepBoundItem.AutoItem(syntax)); } else { throw new StepReadException("Unable to bind pointer, this should be unreachable", syntax.Line, syntax.Column); } }