Esempio 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);
        }
Esempio 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);
        }
Esempio 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);
        }
Esempio n. 4
0
 public FindStructuresAction(List <InstanceTree> scope, StructDef def, string expr)
 {
     _scope = scope;
     _def   = def;
     if (expr.Length > 0)
     {
         _expr = ExpressionParser.Parse(expr);
     }
 }
Esempio 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;
 }
Esempio n. 6
0
 public FindStructuresAction(List<InstanceTree> scope, StructDef def, string expr)
 {
     _scope = scope;
     _def = def;
     if (expr.Length > 0)
     {
         _expr = ExpressionParser.Parse(expr);
     }
 }
Esempio 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;
 }
Esempio 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;
 }
Esempio 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);
        }
Esempio 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;
 }
Esempio 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());
        }
Esempio n. 12
0
 public void Add(StructDef def)
 {
     _structDefs.Add(def);
 }
Esempio n. 13
0
 public DataFile(string name, StructDef def)
 {
     _name = name;
     RootStructDef = def;
 }
Esempio n. 14
0
 public void LoadData(string fileName, StructDef def)
 {
     var dataFile = new DataFile(fileName, def);
     _dataFiles.Add(dataFile);
     LoadDataFile(dataFile);
 }
Esempio 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;
        }
Esempio 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);
        }
Esempio n. 17
0
 protected StructField(StructDef structDef, string defaultAttribute, bool acceptsChildren)
 {
     _structDef        = structDef;
     _defaultAttribute = defaultAttribute;
     _acceptsChildren  = acceptsChildren;
 }
Esempio n. 18
0
 protected StructField(StructDef structDef)
 {
     _structDef = structDef;
 }
Esempio n. 19
0
 protected StructField(StructDef structDef, string defaultAttribute, bool acceptsChildren)
 {
     _structDef = structDef;
     _defaultAttribute = defaultAttribute;
     _acceptsChildren = acceptsChildren;
 }
Esempio n. 20
0
 protected StructField(StructDef structDef)
 {
     _structDef = structDef;
 }
Esempio 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);
        }