public List <TypeInfo> Inheritance; // Data from parsing, used to interfaces and base type construct in Init public override void Init(Builder.BuildData buildData) { base.Init(buildData); if (BaseType == null && Interfaces == null && Inheritance != null) { // Extract base class and interfaces from inheritance info for (int i = 0; i < Inheritance.Count; i++) { var apiTypeInfo = BindingsGenerator.FindApiTypeInfo(buildData, Inheritance[i], Parent); if (apiTypeInfo is InterfaceInfo interfaceInfo) { if (Interfaces == null) { Interfaces = new List <InterfaceInfo>(); } Interfaces.Add(interfaceInfo); } else if (apiTypeInfo is ClassStructInfo otherInfo) { if (otherInfo == this) { throw new Exception($"Type '{Name}' inherits from itself."); } if (BaseType != null) { throw new Exception($"Invalid '{Name}' inheritance (only single base class is allowed for scripting types, excluding interfaces)."); } BaseType = otherInfo; } } } BaseType?.EnsureInited(buildData); }
public override void Read(BinaryReader reader) { Access = (AccessLevel)reader.ReadByte(); BaseTypeInheritance = (AccessLevel)reader.ReadByte(); BaseType = BindingsGenerator.Read(reader, BaseType); Inheritance = BindingsGenerator.Read(reader, Inheritance); base.Read(reader); }
public override void Read(BinaryReader reader) { Access = (AccessLevel)reader.ReadByte(); BaseTypeInheritance = (AccessLevel)reader.ReadByte(); IsTemplate = reader.ReadBoolean(); BaseType = BindingsGenerator.Read(reader, BaseType); Inheritance = BindingsGenerator.Read(reader, Inheritance); Functions = BindingsGenerator.Read(reader, Functions); base.Read(reader); }
private void InflateType(Builder.BuildData buildData, ClassStructInfo typedef, ref TypeInfo typeInfo) { if (BindingsGenerator.CSharpNativeToManagedBasicTypes.ContainsKey(typeInfo.Type)) { return; } if (BindingsGenerator.CSharpNativeToManagedDefault.ContainsKey(typeInfo.Type)) { return; } // Find API type info for this field type var apiType = BindingsGenerator.FindApiTypeInfo(buildData, typeInfo, typedef); if (apiType == null) { // TODO: implement more advanced template types inflating with tokenization of the generic definition typeInfo = Type.GenericArgs[0]; } }
private static void ParseInheritance(ref ParsingContext context, ClassStructInfo desc, out bool isFinal) { desc.BaseType = null; desc.BaseTypeInheritance = AccessLevel.Private; var token = context.Tokenizer.NextToken(); isFinal = token.Value == "final"; if (isFinal) { token = context.Tokenizer.NextToken(); } if (token.Type == TokenType.Colon) { while (token.Type != TokenType.LeftCurlyBrace) { var accessToken = context.Tokenizer.ExpectToken(TokenType.Identifier); switch (accessToken.Value) { case "public": desc.BaseTypeInheritance = AccessLevel.Public; token = context.Tokenizer.ExpectToken(TokenType.Identifier); break; case "protected": desc.BaseTypeInheritance = AccessLevel.Protected; token = context.Tokenizer.ExpectToken(TokenType.Identifier); break; case "private": token = context.Tokenizer.ExpectToken(TokenType.Identifier); break; default: token = accessToken; break; } var inheritType = new TypeInfo { Type = token.Value, }; if (desc.Inheritance == null) { desc.Inheritance = new List <TypeInfo>(); } desc.Inheritance.Add(inheritType); token = context.Tokenizer.NextToken(); if (token.Type == TokenType.LeftCurlyBrace) { break; } if (token.Type == TokenType.Colon) { token = context.Tokenizer.ExpectToken(TokenType.Colon); token = context.Tokenizer.NextToken(); inheritType.Type = token.Value; token = context.Tokenizer.NextToken(); continue; } if (token.Type == TokenType.DoubleColon) { token = context.Tokenizer.NextToken(); inheritType.Type += token.Value; token = context.Tokenizer.NextToken(); continue; } if (token.Type == TokenType.LeftAngleBracket) { var genericType = context.Tokenizer.ExpectToken(TokenType.Identifier); token = context.Tokenizer.ExpectToken(TokenType.RightAngleBracket); inheritType.GenericArgs = new List <TypeInfo> { new TypeInfo { Type = genericType.Value, } }; // TODO: find better way to resolve this (custom base type attribute?) if (inheritType.Type == "ShaderAssetTypeBase") { desc.Inheritance[desc.Inheritance.Count - 1] = inheritType.GenericArgs[0]; } token = context.Tokenizer.NextToken(); } } token = context.Tokenizer.PreviousToken(); } else { // No base type token = context.Tokenizer.PreviousToken(); } }
private static void ParseInheritance(ref ParsingContext context, ClassStructInfo desc, out bool isFinal) { desc.BaseType = null; desc.BaseTypeInheritance = AccessLevel.Private; var token = context.Tokenizer.NextToken(); isFinal = token.Value == "final"; if (isFinal) { token = context.Tokenizer.NextToken(); } if (token.Type == TokenType.Colon) { while (token.Type != TokenType.LeftCurlyBrace) { var accessToken = context.Tokenizer.ExpectToken(TokenType.Identifier); switch (accessToken.Value) { case "public": desc.BaseTypeInheritance = AccessLevel.Public; token = context.Tokenizer.ExpectToken(TokenType.Identifier); break; case "protected": desc.BaseTypeInheritance = AccessLevel.Protected; token = context.Tokenizer.ExpectToken(TokenType.Identifier); break; case "private": token = context.Tokenizer.ExpectToken(TokenType.Identifier); break; default: token = accessToken; break; } var baseTypeInfo = new TypeInfo { Type = token.Value, }; if (token.Value.Length > 2 && token.Value[0] == 'I' && char.IsUpper(token.Value[1])) { // Interface if (desc.InterfaceNames == null) { desc.InterfaceNames = new List <TypeInfo>(); } desc.InterfaceNames.Add(baseTypeInfo); token = context.Tokenizer.NextToken(); continue; } if (desc.BaseType != null) { // Allow for multiple base classes, just the first one needs to be a valid base type break; throw new Exception($"Invalid '{desc.Name}' inheritance (only single base class is allowed for scripting types, excluding interfaces)."); } desc.BaseType = baseTypeInfo; token = context.Tokenizer.NextToken(); if (token.Type == TokenType.LeftCurlyBrace) { break; } if (token.Type == TokenType.LeftAngleBracket) { var genericType = context.Tokenizer.ExpectToken(TokenType.Identifier); token = context.Tokenizer.ExpectToken(TokenType.RightAngleBracket); desc.BaseType.GenericArgs = new List <TypeInfo> { new TypeInfo { Type = genericType.Value, } }; // TODO: find better way to resolve this (custom base type attribute?) if (desc.BaseType.Type == "ShaderAssetTypeBase") { desc.BaseType = desc.BaseType.GenericArgs[0]; } token = context.Tokenizer.NextToken(); } } token = context.Tokenizer.PreviousToken(); } else { // No base type token = context.Tokenizer.PreviousToken(); } }