Exemplo n.º 1
0
        public StepFile ReadFile()
        {
            var fileSyntax = _lexer.LexFileSyntax();

            foreach (var headerMacro in fileSyntax.Header.Macros)
            {
                ApplyHeaderMacro(headerMacro);
            }

            var itemMap = new Dictionary <int, 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);
                }

                var item = StepRepresentationItem.FromTypedParameter(binder, itemInstance.SimpleItemInstance, itemInstance.Id);
                if (item != null)
                {
                    itemMap.Add(itemInstance.Id, item);
                    _file.Items.Add(item);
                }
            }

            binder.BindRemainingValues();

            return(_file);
        }
Exemplo n.º 2
0
        public void BindValue(StepSyntax syntax, Action <StepBoundItem> bindAction)
        {
            if (syntax is StepSimpleItemSyntax)
            {
                var typedParameter = (StepSimpleItemSyntax)syntax;
                var item           = StepRepresentationItem.FromTypedParameter(this, typedParameter);
                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
                    var boundItem = new StepBoundItem(_itemMap[itemInstance.Id], 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);
            }
        }