Ejemplo n.º 1
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.º 2
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());
        }