Ejemplo n.º 1
0
        private void LoadFieldGroup(StructLexer lexer, StructDef structDef, StructField parentField)
        {
            lexer.GetNextToken(StructTokenType.OpenCurly);
            StructField linkToField = null;

            while (lexer.PeekNextToken() != StructTokenType.CloseCurly)
            {
                StructField field = LoadField(lexer, structDef, parentField);

                if (field != null)
                {
                    bool isLinked = false;
                    if (linkToField != null)
                    {
                        isLinked = linkToField.CanLinkField(field);
                    }

                    if (isLinked)
                    {
                        linkToField.LinkField(field);
                    }
                    else
                    {
                        linkToField = field;
                    }

                    field.Validate();
                }
            }
            lexer.GetNextToken(StructTokenType.CloseCurly);
        }
Ejemplo n.º 2
0
        private void LoadStruct(StructLexer lexer, List <Attribute> attrs)
        {
            string name = lexer.GetNextToken(StructTokenType.String);

            if (_curStructFile.GetStructByName(name) != null)
            {
                throw new Exception("Duplicate structure name '" + name + "'");
            }

            LoadAttributes(lexer, attrs);

            StructDef structDef = new StructDef(_curStructFile, name);

            foreach (Attribute attr in attrs)
            {
                try
                {
                    structDef.SetAttribute(attr.Key, attr.Value, attr.Position);
                }
                catch (ParseException ex)
                {
                    _errors.Add(ex);
                }
            }

            LoadFieldGroup(lexer, structDef, null);
            _curStructFile.Add(structDef);
        }
Ejemplo n.º 3
0
        private StructField LoadField(StructLexer lexer, StructDef structDef, StructField parentField)
        {
            List <Attribute> attrs = new List <Attribute>();

            LoadAttributes(lexer, attrs);
            TextPosition fieldPosition = lexer.CurrentPosition;
            string       fieldType     = lexer.GetNextToken(StructTokenType.String);
            StructField  field         = null;

            try
            {
                field          = _fieldFactory.CreateField(structDef, fieldType, _attributeRegistry);
                field.Name     = fieldType;
                field.Position = fieldPosition;
            }
            catch (Exception ex)
            {
                _errors.Add(new ParseException(ex.Message, fieldPosition));
            }
            LoadAttributes(lexer, attrs);
            if (lexer.PeekNextToken() != StructTokenType.Semicolon && lexer.PeekNextToken() != StructTokenType.OpenCurly)
            {
                TextPosition pos = lexer.CurrentPosition;
                string       tag = lexer.GetNextToken(StructTokenType.String);
                LoadAttributes(lexer, attrs);
                if (field != null)
                {
                    _attributeRegistry.SetFieldAttribute(field, field.DefaultAttribute, tag, pos);
                }
            }

            foreach (Attribute attr in attrs)
            {
                _attributeRegistry.SetFieldAttribute(field, attr.Key, attr.Value, attr.Position);
            }

            if (lexer.PeekNextToken() == StructTokenType.OpenCurly)
            {
                LoadFieldGroup(lexer, structDef, field);
            }
            else
            {
                lexer.GetNextToken(StructTokenType.Semicolon);
            }

            if (field != null)
            {
                field.EndPosition = lexer.LastTokenEndPosition;
                if (parentField == null)
                {
                    structDef.AddField(field);
                }
                else
                {
                    parentField.AddChildField(field);
                }
            }
            return(field);
        }
Ejemplo n.º 4
0
 public FindStructuresAction(List <InstanceTree> scope, StructDef def, string expr)
 {
     _scope = scope;
     _def   = def;
     if (expr.Length > 0)
     {
         _expr = ExpressionParser.Parse(expr);
     }
 }
Ejemplo n.º 5
0
 public StructInstance(StructDef def, InstanceTreeNode parent, Stream stream, long offset)
 {
     if (offset < 0) throw new ArgumentOutOfRangeException("offset");
     SequenceIndex = -1;
     _def = def;
     _parent = parent;
     _stream = stream;
     _offset = offset;
 }
Ejemplo n.º 6
0
 public FindStructuresAction(List<InstanceTree> scope, StructDef def, string expr)
 {
     _scope = scope;
     _def = def;
     if (expr.Length > 0)
     {
         _expr = ExpressionParser.Parse(expr);
     }
 }
Ejemplo n.º 7
0
 public StructInstance(StructDef def, InstanceTreeNode parent, Stream stream,
                       StructInstance followInstance, bool followChildren)
 {
     SequenceIndex   = -1;
     _def            = def;
     _parent         = parent;
     _stream         = stream;
     _followInstance = followInstance;
     _followChildren = followChildren;
 }
Ejemplo n.º 8
0
 public StructInstance(StructDef def, InstanceTreeNode parent, Stream stream, 
     StructInstance followInstance, bool followChildren)
 {
     SequenceIndex = -1;
     _def = def;
     _parent = parent;
     _stream = stream;
     _followInstance = followInstance;
     _followChildren = followChildren;
 }
Ejemplo n.º 9
0
        public override void Resolve()
        {
            StructDef target = _baseField.StructDef.StructFile.GetStructByName(_targetName);

            if (target == null)
            {
                throw new ParseException("Unknown struct " + _targetName, _position);
            }
            _baseField.SetAttributeValue(_attrName, target);
        }
Ejemplo n.º 10
0
 public StructInstance(StructDef def, InstanceTreeNode parent, Stream stream, long offset)
 {
     if (offset < 0)
     {
         throw new ArgumentOutOfRangeException("offset");
     }
     SequenceIndex = -1;
     _def          = def;
     _parent       = parent;
     _stream       = stream;
     _offset       = offset;
 }
Ejemplo n.º 11
0
        private static IConvertible SizeOf(StructInstance context, Expression[] parameters)
        {
            if (parameters.Length != 1)
            {
                throw new LoadDataException("SizeOf function requires an argument");
            }
            if (!(parameters [0] is SymbolExpression))
            {
                throw new LoadDataException("SizeOf argument must be a symbol");
            }
            string symbol = ((SymbolExpression)parameters[0]).Symbol;

            StructFile structFile = context.Def.StructFile;
            StructDef  def        = structFile.GetStructByName(symbol);

            if (def == null)
            {
                throw new LoadDataException("Structure '" + symbol + "' not found");
            }
            return(def.GetDataSize());
        }
Ejemplo n.º 12
0
 public void Add(StructDef def)
 {
     _structDefs.Add(def);
 }
Ejemplo n.º 13
0
 public DataFile(string name, StructDef def)
 {
     _name = name;
     RootStructDef = def;
 }
Ejemplo n.º 14
0
 public void LoadData(string fileName, StructDef def)
 {
     var dataFile = new DataFile(fileName, def);
     _dataFiles.Add(dataFile);
     LoadDataFile(dataFile);
 }
Ejemplo n.º 15
0
        private StructField LoadField(StructLexer lexer, StructDef structDef, StructField parentField)
        {
            List<Attribute> attrs = new List<Attribute>();
            LoadAttributes(lexer, attrs);
            TextPosition fieldPosition = lexer.CurrentPosition;
            string fieldType = lexer.GetNextToken(StructTokenType.String);
            StructField field = null;
            try
            {
                field = _fieldFactory.CreateField(structDef, fieldType, _attributeRegistry);
                field.Name = fieldType;
                field.Position = fieldPosition;
            }
            catch(Exception ex)
            {
                _errors.Add(new ParseException(ex.Message, fieldPosition));
            }
            LoadAttributes(lexer, attrs);
            if (lexer.PeekNextToken() != StructTokenType.Semicolon && lexer.PeekNextToken() != StructTokenType.OpenCurly)
            {
                TextPosition pos = lexer.CurrentPosition;
                string tag = lexer.GetNextToken(StructTokenType.String);
                LoadAttributes(lexer, attrs);
                if (field != null)
                    _attributeRegistry.SetFieldAttribute(field, field.DefaultAttribute, tag, pos);
            }

            foreach (Attribute attr in attrs)
                _attributeRegistry.SetFieldAttribute(field, attr.Key, attr.Value, attr.Position);

            if (lexer.PeekNextToken() == StructTokenType.OpenCurly)
                LoadFieldGroup(lexer, structDef, field);
            else
                lexer.GetNextToken(StructTokenType.Semicolon);

            if (field != null)
            {
                field.EndPosition = lexer.LastTokenEndPosition;
                if (parentField == null)
                    structDef.AddField(field);
                else
                    parentField.AddChildField(field);
            }
            return field;
        }
Ejemplo n.º 16
0
        private void LoadFieldGroup(StructLexer lexer, StructDef structDef, StructField parentField)
        {
            lexer.GetNextToken(StructTokenType.OpenCurly);
            StructField linkToField = null;
            while(lexer.PeekNextToken() != StructTokenType.CloseCurly)
            {
                StructField field = LoadField(lexer, structDef, parentField);

                if (field != null)
                {
                    bool isLinked = false;
                    if (linkToField != null)
                        isLinked = linkToField.CanLinkField(field);

                    if (isLinked)
                        linkToField.LinkField(field);
                    else
                        linkToField = field;

                    field.Validate();
                }
            }
            lexer.GetNextToken(StructTokenType.CloseCurly);
        }
Ejemplo n.º 17
0
 protected StructField(StructDef structDef, string defaultAttribute, bool acceptsChildren)
 {
     _structDef        = structDef;
     _defaultAttribute = defaultAttribute;
     _acceptsChildren  = acceptsChildren;
 }
Ejemplo n.º 18
0
 protected StructField(StructDef structDef)
 {
     _structDef = structDef;
 }
Ejemplo n.º 19
0
 protected StructField(StructDef structDef, string defaultAttribute, bool acceptsChildren)
 {
     _structDef = structDef;
     _defaultAttribute = defaultAttribute;
     _acceptsChildren = acceptsChildren;
 }
Ejemplo n.º 20
0
 protected StructField(StructDef structDef)
 {
     _structDef = structDef;
 }
Ejemplo n.º 21
0
        private void LoadStruct(StructLexer lexer, List<Attribute> attrs)
        {
            string name = lexer.GetNextToken(StructTokenType.String);
            if (_curStructFile.GetStructByName(name) != null)
                throw new Exception("Duplicate structure name '" + name + "'");

            LoadAttributes(lexer, attrs);

            StructDef structDef = new StructDef(_curStructFile, name);
            foreach (Attribute attr in attrs)
            {
                try
                {
                    structDef.SetAttribute(attr.Key, attr.Value, attr.Position);
                }
                catch(ParseException ex)
                {
                    _errors.Add(ex);
                }
            }

            LoadFieldGroup(lexer, structDef, null);
            _curStructFile.Add(structDef);
        }