コード例 #1
0
ファイル: ReferenceBase.cs プロジェクト: thawk/structorian
 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
ファイル: TextPosition.cs プロジェクト: thawk/structorian
 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
ファイル: StructDef.cs プロジェクト: thawk/structorian
 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
ファイル: EnumReference.cs プロジェクト: thawk/structorian
 public EnumReference(StructField baseField, string attrName, string targetName, TextPosition position)
     : base(baseField, attrName, targetName, position)
 {
 }
コード例 #6
0
ファイル: ParseException.cs プロジェクト: thawk/structorian
 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
ファイル: StructParser.cs プロジェクト: thawk/structorian
 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)
 {
 }