コード例 #1
0
        private static void ProcessAndValidate(BuildData buildData, StructureInfo structureInfo)
        {
            foreach (var fieldInfo in structureInfo.Fields)
            {
                if (fieldInfo.Type.IsBitField)
                {
                    throw new NotImplementedException($"TODO: support bit-fields in structure fields (found field {fieldInfo} in structure {structureInfo.Name})");
                }

                // Pointers are fine
                if (fieldInfo.Type.IsPtr)
                {
                    continue;
                }

                // In-build types
                if (CSharpNativeToManagedBasicTypes.ContainsKey(fieldInfo.Type.Type))
                {
                    continue;
                }
                if (CSharpNativeToManagedDefault.ContainsKey(fieldInfo.Type.Type))
                {
                    continue;
                }

                // Find API type info for this field type
                var apiType = FindApiTypeInfo(buildData, fieldInfo.Type, structureInfo);
                if (apiType != null)
                {
                    continue;
                }

                throw new Exception($"Unknown field type '{fieldInfo.Type} {fieldInfo.Name}' in structure '{structureInfo.Name}'.");
            }
        }
コード例 #2
0
        private static StructureInfo ParseStructure(ref ParsingContext context)
        {
            var desc = new StructureInfo
            {
                Children  = new List <ApiTypeInfo>(),
                Access    = context.CurrentAccessLevel,
                Fields    = new List <FieldInfo>(),
                Functions = new List <FunctionInfo>(),
            };

            // Read the documentation comment
            desc.Comment = ParseComment(ref context);

            // Read parameters from the tag
            var tagParams = ParseTagParameters(ref context);

            // Read 'struct' keyword
            var token = context.Tokenizer.NextToken();

            if (token.Value != "struct")
            {
                throw new Exception($"Invalid API_STRUCT usage (expected 'struct' keyword but got '{token.Value} {context.Tokenizer.NextToken().Value}').");
            }

            // Read name
            desc.Name = desc.NativeName = ParseName(ref context);

            // Read structure inheritance
            token = context.Tokenizer.NextToken();
            if (token.Type == TokenType.Colon)
            {
                // Current class does have inheritance defined
                var accessToken = context.Tokenizer.ExpectToken(TokenType.Identifier);
                switch (accessToken.Value)
                {
                case "public":
                    token = context.Tokenizer.ExpectToken(TokenType.Identifier);
                    break;

                case "protected":
                    token = context.Tokenizer.ExpectToken(TokenType.Identifier);
                    break;

                case "private":
                    token = context.Tokenizer.ExpectToken(TokenType.Identifier);
                    break;

                default:
                    token = accessToken;
                    break;
                }

                desc.BaseType = new TypeInfo
                {
                    Type = token.Value,
                };
                token = context.Tokenizer.NextToken();
                if (token.Type == TokenType.LeftAngleBracket)
                {
                    var genericType = context.Tokenizer.ExpectToken(TokenType.Identifier);
                    context.Tokenizer.ExpectToken(TokenType.RightAngleBracket);
                    desc.BaseType.GenericArgs = new List <TypeInfo>
                    {
                        new TypeInfo
                        {
                            Type = genericType.Value,
                        }
                    };
                }
                else
                {
                    token = context.Tokenizer.PreviousToken();
                }
            }
            else
            {
                // No base type
                token = context.Tokenizer.PreviousToken();
            }

            // Process tag parameters
            foreach (var tag in tagParams)
            {
                switch (tag.Tag.ToLower())
                {
                case "public":
                    desc.Access = AccessLevel.Public;
                    break;

                case "protected":
                    desc.Access = AccessLevel.Protected;
                    break;

                case "private":
                    desc.Access = AccessLevel.Private;
                    break;

                case "inbuild":
                    desc.IsInBuild = true;
                    break;

                case "nopod":
                    desc.ForceNoPod = true;
                    break;

                case "attributes":
                    desc.Attributes = tag.Value;
                    break;

                case "name":
                    desc.Name = tag.Value;
                    break;

                case "namespace":
                    desc.Namespace = tag.Value;
                    break;

                default:
                    Log.Warning($"Unknown or not supported tag parameter {tag} used on struct {desc.Name} at line {context.Tokenizer.CurrentLine}");
                    break;
                }
            }
            return(desc);
        }