public EnumerationDefinition MakeEnumerationDefinition(Enumeration enumeration, string name)
        {
            name = string.IsNullOrEmpty(enumeration.Name) ? name : enumeration.Name;
            var result = new EnumerationDefinition {
                Name = name
            };

            if (_context.IsKnownUnitName(name))
            {
                return(result);
            }
            _context.AddUnit(result);

            result.TypeName = TypeHelper.GetTypeName(enumeration.Type);
            result.Content  = enumeration.Comment?.BriefText;
            result.Items    = enumeration.Items
                              .Select(x =>
                                      new EnumerationItem
            {
                Name    = x.Name,
                Value   = ConvertValue(x.Value, enumeration.BuiltinType.Type).ToString(),
                Content = x.Comment?.BriefText
            })
                              .ToArray();
            return(result);
        }
Пример #2
0
        public void Process(TranslationUnit translationUnit)
        {
            foreach (var function in translationUnit.Functions.Where(x => !x.IsInline))
            {
                var            functionName = function.Name;
                FunctionExport export;
                if (!_context.FunctionExportMap.TryGetValue(functionName, out export))
                {
                    Console.WriteLine($"Export not found. Skipping {functionName} function.");
                    continue;
                }

                var functionDefinition = new FunctionDefinition
                {
                    Name            = functionName,
                    ReturnType      = GetReturnTypeName(function.ReturnType.Type, functionName),
                    Content         = function.Comment?.BriefText,
                    LibraryName     = export.LibraryName,
                    Parameters      = function.Parameters.Select((x, i) => GetParameter(function, x, i)).ToArray(),
                    IsObsolete      = IsObsolete(function),
                    ObsoleteMessage = GetObsoleteMessage(function)
                };
                _context.AddUnit(functionDefinition);
            }
        }
        private void MakeDefinition(Class @class, string name)
        {
            name = string.IsNullOrEmpty(@class.Name) ? name : @class.Name;

            var definition = _context.Units.OfType <StructureDefinition>().FirstOrDefault(x => x.Name == name);

            if (definition == null)
            {
                definition = new StructureDefinition {
                    Name = name
                };
                _context.AddUnit(definition);
            }

            if ([email protected] && !definition.IsComplete)
            {
                definition.IsComplete = true;

                var  bitFieldNames    = new List <string>();
                var  bitFieldComments = new List <string>();
                long bitCounter       = 0;
                var  fields           = new List <StructureField>();
                foreach (var field in @class.Fields)
                {
                    if (field.IsBitField)
                    {
                        bitFieldNames.Add($"{field.Name}{field.BitWidth}");
                        bitFieldComments.Add(field.Comment?.BriefText ?? string.Empty);
                        bitCounter += field.BitWidth;
                        if (bitCounter % 8 == 0)
                        {
                            fields.Add(GetBitField(bitFieldNames, bitCounter, bitFieldComments));
                            bitFieldNames.Clear();
                            bitFieldComments.Clear();
                            bitCounter = 0;
                        }
                        continue;
                    }

                    var typeName = field.Class.Name + "_" + field.Name;
                    fields.Add(new StructureField
                    {
                        Name      = field.Name,
                        FieldType = GetTypeDefinition(field.Type, typeName),
                        Content   = field.Comment?.BriefText
                    });
                }

                if (bitFieldNames.Any() || bitCounter > 0)
                {
                    throw new InvalidOperationException();
                }

                definition.Fileds  = fields.ToArray();
                definition.Content = @class.Comment?.BriefText;
            }
        }
Пример #4
0
 public void Process(TranslationUnit translationUnit)
 {
     foreach (var macro in translationUnit.PreprocessedEntities.OfType <MacroDefinition>().Where(x => !string.IsNullOrWhiteSpace(x.Expression)))
     {
         var macroDefinition = new Definitions.MacroDefinition
         {
             Name       = macro.Name,
             Expression = macro.Expression
         };
         _context.AddUnit(macroDefinition);
     }
 }