public void RoundTripStruct() { ModuleDeclaration module = ReflectToModules("public struct Foo {\npublic var x:Int\n } ", "SomeModule").Find(m => m.Name == "SomeModule"); StructDeclaration fooClass = module.AllStructs.Where(cl => cl.Name == "Foo").FirstOrDefault(); Assert.IsNotNull(fooClass); StructDeclaration unrootedFoo = fooClass.MakeUnrooted() as StructDeclaration; Entity entity = new Entity { SharpNamespace = "SomeModule", SharpTypeName = "Foo", Type = unrootedFoo }; TypeDatabase db = new TypeDatabase(); db.Add(entity); MemoryStream ostm = new MemoryStream(); db.Write(ostm, "SomeModule"); ostm.Seek(0, SeekOrigin.Begin); TypeDatabase dbread = new TypeDatabase(); var errors = dbread.Read(ostm); Utils.CheckErrors(errors); Entity entityRead = dbread.EntityForSwiftName("SomeModule.Foo"); Assert.IsNotNull(entityRead); Assert.AreEqual(entity.SharpNamespace, entityRead.SharpNamespace); Assert.AreEqual(entity.SharpTypeName, entityRead.SharpTypeName); Assert.IsTrue(entity.Type is StructDeclaration); }
private uFrameDatabaseConfig GetConfig(TypeDatabase db, string title) { var config = db.GetSingle <uFrameDatabaseConfig>(); if (config == null) { config = new uFrameDatabaseConfig { CodeOutputPath = "Assets/Code", Namespace = title, BuildVersion = uFrameVersion.BuildVersion, MajorVersion = uFrameVersion.MajorVersion, MinorVersion = uFrameVersion.MinorVersion, }; db.Add(config); db.Commit(); } config.Database = db; config.Title = title; if (!Configurations.ContainsKey(config.Identifier)) { Configurations.Add(config.Identifier, config); } return(config); }
public override void Initialize(QFrameworkContainer container) { base.Initialize(container); var path = DbRootPath; var dbDirectories = Directory.GetDirectories(path, "*.db", SearchOption.AllDirectories); foreach (var item in dbDirectories) { var db = new TypeDatabase(new JsonRepositoryFactory(item)); var config = GetConfig(db, Path.GetFileNameWithoutExtension(item)); config.FullPath = item; container.RegisterInstance <IGraphConfiguration>(config, config.Identifier); } CurrentConfiguration = Configurations.ContainsKey(CurrentDatabaseIdentifier) ? Configurations[CurrentDatabaseIdentifier] : Configurations.Values.FirstOrDefault(); if (CurrentConfiguration != null) { container.RegisterInstance <IGraphConfiguration>(CurrentConfiguration); container.RegisterInstance <IRepository>(CurrentConfiguration.Database); //var typeDatabase = container.Resolve<IRepository>(); CurrentConfiguration.Database.AddListener <IDataRecordInserted>(this); CurrentConfiguration.Database.AddListener <IDataRecordRemoved>(this); CurrentConfiguration.Database.AddListener <IDataRecordPropertyChanged>(this); CurrentConfiguration.Database.AddListener <IDataRecordPropertyBeforeChange>(this); } else { InvertApplication.Log("A uFrameDatabase doesn't exist."); } }
public void Setup() { ValidateOptions(Options); Generator = Generators[Options.GeneratorKind](this); TypeDatabase.SetupTypeMaps(); }
public void Setup() { ValidateOptions(Options); TypeDatabase.SetupTypeMaps(); Generator = CreateGeneratorFromKind(Options.GeneratorKind); }
private bool IsTypeComplete(Type type) { TypeMap typeMap; if (TypeDatabase.FindTypeMap(type, out typeMap) && !typeMap.IsIgnored) { return(true); } var desugared = type.Desugar(); var finalType = (desugared.GetFinalPointee() ?? desugared).Desugar(); var templateSpecializationType = finalType as TemplateSpecializationType; if (templateSpecializationType != null) { finalType = templateSpecializationType.Desugared.Type; } Declaration decl; if (!finalType.TryGetDeclaration(out decl)) { return(true); } return(!decl.IsIncomplete); }
public override void Initialize(QFrameworkContainer container) { var typeDatabase = new TypeDatabase(new JsonRepositoryFactory(Path.Combine(Application.dataPath, "../uFrame"))); container.RegisterInstance <IRepository>(typeDatabase, "Settings"); container.RegisterInstance <IDesctiptorsService>(new DescriptorsService(typeDatabase)); }
private string TranslateEnumExpression(Function function, Type desugared, string @params) { TypeMap typeMap; if ((function.Parameters.Count == 0 || HasSingleZeroArgExpression(function)) && TypeDatabase.FindTypeMap(desugared, out typeMap)) { var typeInSignature = typeMap.CSharpSignatureType(new CSharpTypePrinterContext { MarshalKind = CSharpMarshalKind.DefaultExpression, Type = desugared }).SkipPointerRefs().Desugar(); Enumeration @enum; if (typeInSignature.TryGetEnum(out @enum)) { return("0"); } } if (@params.Contains("::")) { return(regexDoubleColon.Replace(@params, desugared + ".")); } return(regexName.Replace(@params, desugared + ".$1")); }
public static bool ImportAndMerge(PlatformName platformName, TypeDatabase peerDatabase, ErrorHandling errors) { Ex.ThrowOnNull(peerDatabase, nameof(peerDatabase)); var initialErrorCount = errors.ErrorCount; var newDb = ImportFrom(platformName, errors, peerDatabase); peerDatabase.Merge(newDb, errors); return(initialErrorCount != errors.ErrorCount); }
private bool IsDeclIgnored(Declaration decl) { var parameter = decl as Parameter; if (parameter != null && parameter.Type.Desugar().IsPrimitiveType(PrimitiveType.Null)) { return(true); } TypeMap typeMap; return(TypeDatabase.FindTypeMap(decl, out typeMap) ? typeMap.IsIgnored : decl.Ignore); }
public void Execute(ValidateDatabaseCommand command) { //InvertApplication.Log("YUP"); var list = new List <ErrorInfo>(); var repo = new TypeDatabase(new JsonRepositoryFactory(command.FullPath)); var items = repo.AllOf <IDiagramNode>(); foreach (IDiagramNode t in items) { if (command.Worker.CancellationPending) { return; } var item = t; var item1 = item; command.Worker.ReportProgress(1, item1.Name); item.Validate(list); } }
BindingImporter(string assemblyPath, ErrorHandling errors, TypeDatabase peerDatabase = null) { Ex.ThrowOnNull(assemblyPath, nameof(assemblyPath)); this.errors = Ex.ThrowOnNull(errors, nameof(errors)); this.peerDatabase = peerDatabase; aggregator = new TypeAggregator(assemblyPath); aggregator.IsObjCChecker = (nameSpace, typeName) => { if (peerDatabase == null) { return(false); } var entity = peerDatabase.EntityForDotNetName(new DotNetName(nameSpace, typeName)); if (entity != null) { return(entity.Type.IsObjC); } return(false); }; }
/// <summary> /// Retorna a abstração da classe de conexao /// </summary> /// <param name="typeOfDatabase"></param> /// <param name="strConnection"></param> /// <returns></returns> public static DbConnection CreateConnection(TypeDatabase typeOfDatabase, String strConnection) { DbConnection connection = null; switch (typeOfDatabase) { case TypeDatabase.Postgresql: connection = new Npgsql.NpgsqlConnection(strConnection); break; case TypeDatabase.Oracle: connection = new Oracle.ManagedDataAccess.Client.OracleConnection(strConnection); break; case TypeDatabase.Firebird: connection = new FbConnection(strConnection); break; default: throw new NotImplementedException(); } return(connection); }
public static DbCommand CreateCommand(TypeDatabase typeOfDatabase, String cmdText, DbConnection connection) { DbCommand cmd = null; switch (typeOfDatabase) { case TypeDatabase.Postgresql: cmd = new Npgsql.NpgsqlCommand(cmdText, (Npgsql.NpgsqlConnection)connection); break; case TypeDatabase.Oracle: cmd = new Oracle.ManagedDataAccess.Client.OracleCommand(cmdText, (Oracle.ManagedDataAccess.Client.OracleConnection)connection); break; case TypeDatabase.Firebird: cmd = new FirebirdSql.Data.FirebirdClient.FbCommand(cmdText, (FbConnection)connection); break; default: throw new NotImplementedException(); } return(cmd); }
public void Execute(CreateDatabaseCommand command) { if (Directory.Exists(command.Name)) { throw new Exception(string.Format("Database {0} already exists.", command.Name)); } var dbDir = Directory.CreateDirectory(Path.Combine(DbRootPath, command.Name + ".db")); var db = new TypeDatabase(new JsonRepositoryFactory(dbDir.FullName)); var config = GetConfig(db, command.Name); config.Namespace = command.Namespace; config.Title = command.Name; config.CodeOutputPath = command.CodePath; config.Namespace = command.Namespace ?? config.Namespace; config.FullPath = dbDir.FullName; config.Database = db; db.Commit(); CurrentDatabaseIdentifier = config.Identifier; InvertApplication.Container = null; if (InvertApplication.Container != null) { InvertApplication.SignalEvent <INotify>(_ => _.Notify(command.Name + " Database " + " has been created!", NotificationIcon.Info)); } }
public BindingImporter(PlatformName platform, ErrorHandling errors, TypeDatabase peerDatabase = null) : this(TypeAggregator.PathForPlatform(platform), errors, peerDatabase) { this.platform = platform; }
public static TypeDatabase ImportFrom(PlatformName platformName, ErrorHandling errors, TypeDatabase peerDatabase = null) { var importer = new BindingImporter(platformName, errors, peerDatabase); return(importer.Import()); }
private bool?CheckForDefaultConstruct(Type desugared, Expression expression, ref string result) { var type = desugared.GetFinalPointee() ?? desugared; Class decl; if (!type.TryGetClass(out decl)) { return(false); } var ctor = expression as CXXConstructExpr; TypeMap typeMap; var typePrinter = new CSharpTypePrinter(Context); typePrinter.PushMarshalKind(CSharpMarshalKind.DefaultExpression); var typePrinterResult = type.Visit(typePrinter).Type; if (TypeDatabase.FindTypeMap(decl, type, out typeMap)) { var typeInSignature = typeMap.CSharpSignatureType( typePrinter.TypePrinterContext).SkipPointerRefs().Desugar(); Enumeration @enum; if (typeInSignature.TryGetEnum(out @enum)) { if (ctor != null && (ctor.Arguments.Count == 0 || HasSingleZeroArgExpression((Function)ctor.Declaration))) { result = "0"; return(true); } return(false); } if (ctor != null && typePrinterResult == "string" && ctor.Arguments.Count == 0) { result = "\"\""; return(true); } } if (ctor == null) { CheckForSimpleExpressions(expression, ref result, desugared); return(decl.IsValueType ? (bool?)false : null); } var method = (Method)expression.Declaration; var expressionSupported = decl.IsValueType && method.Parameters.Count == 0; if (expression.String.Contains('(')) { var argsBuilder = new StringBuilder("new "); argsBuilder.Append(typePrinterResult); argsBuilder.Append('('); for (var i = 0; i < ctor.Arguments.Count; i++) { var argument = ctor.Arguments[i]; var argResult = argument.String; expressionSupported &= PrintExpression(method.Parameters[i].Type.Desugar(), argument, ref argResult) ?? false; argsBuilder.Append(argResult); if (i < ctor.Arguments.Count - 1) { argsBuilder.Append(", "); } } argsBuilder.Append(')'); result = argsBuilder.ToString(); } else { if (method.Parameters.Count > 0) { var paramType = method.Parameters[0].Type.SkipPointerRefs().Desugar(); Enumeration @enum; if (paramType.TryGetEnum(out @enum)) { result = TranslateEnumExpression(method, paramType, expression.String); } } } return(expressionSupported ? true : (bool?)null); }