Пример #1
0
 protected ReferenceBase(StructField baseField, string attrName, string targetName, TextPosition position)
 {
     _baseField = baseField;
     _attrName = attrName;
     _targetName = targetName;
     _position = position;
 }
Пример #2
0
        internal void SetFieldAttribute(StructField field, string key, string value, TextPosition pos)
        {
            if (field == null) return;

            Type fieldType = field.GetType();

            while(true)
            {
                Dictionary<string, AttributeType> fieldsForType;
                if (_registry.TryGetValue(fieldType, out fieldsForType))
                {
                    AttributeType attrType;
                    if (fieldsForType.TryGetValue(key, out attrType))
                    {
                        SetFieldAttributeValue(field, key, attrType, value, pos);
                        return;
                    }
                }
                if (fieldType.Equals(typeof(StructField))) break;
                fieldType = fieldType.BaseType;
            }

            try
            {
                field.SetAttribute(key, value);
            }
            catch(Exception)
            {
                throw new ParseException("Unknown attribute " + key, pos);
            }
        }
Пример #3
0
 public TextPosition OffsetBy(TextPosition position)
 {
     if (position.Line == 1)
         return new TextPosition(_file, _line, _col + position.Col);
     else
         return new TextPosition(_file, _line + position.Line - 1, position.Col);
 }
Пример #4
0
 public void SetAttribute(string name, string value, TextPosition position)
 {
     if (name == "filemask")
         _fileMask = value;
     else if (name == "byteorder")
     {
         if (value == "intel" || value == "littleendian")
             _byteOrder = ByteOrder.LittleEndian;
         else if (value == "motorola" || value == "bigendian")
             _byteOrder = ByteOrder.BigEndian;
         else
             throw new ParseException("Unknown byteorder value " + value, position);
     }
     else if (name == "hidden")
         _hidden = true;
     else if (name == "preload")
         _preload = true;
     else if (name == "fieldlike")
         _fieldLike = (Int32.Parse(value) > 0);
     else
         throw new ParseException("Unknown attribute " + name, position);
 }
Пример #5
0
 public EnumReference(StructField baseField, string attrName, string targetName, TextPosition position)
     : base(baseField, attrName, targetName, position)
 {
 }
Пример #6
0
 public ParseException(string message, TextPosition position, int length)
     : base(message)
 {
     _position = position;
     _length = length;
 }
Пример #7
0
 private static void SetFieldAttributeValue(StructField field, string key, AttributeType type, string value,
     TextPosition pos)
 {
     switch(type)
     {
         case AttributeType.Expression:
             try
             {
                 field.SetAttributeValue(key, ExpressionParser.Parse(value));
             }
             catch(ParseException ex)
             {
                 throw new ParseException(ex.Message, pos.OffsetBy(ex.Position));
             }
             break;
         case AttributeType.String:
             field.SetAttributeValue(key, value);
             break;
         case AttributeType.Int:
             field.SetAttributeValue(key, Int32.Parse(value));
             break;
         case AttributeType.Bool:
             field.SetAttributeValue(key, (Int32.Parse(value) != 0));
             break;
         case AttributeType.StructRef:
             field.StructDef.StructFile.AddReference(new StructReference(field, key, value, pos));
             break;
         case AttributeType.EnumRef:
             field.StructDef.StructFile.AddReference(new EnumReference(field, key, value, pos));
             break;
     }
 }
Пример #8
0
 public Attribute(string name, string value, TextPosition position)
 {
     _key = name;
     _value = value;
     _position = position;
 }
Пример #9
0
 public StructReference(StructField baseField, string attrName, string targetName,
                        TextPosition pos) : base(baseField, attrName, targetName, pos)
 {
 }