public ComponentCommander(ISpatialOsComponentInternal component, ISpatialCommunicator communicator) { commandResponseThunksRegistered = new HashSet <Type>(); requestIdToCallback = new Dictionary <uint, ICommandCallbackWrapper>(); this.component = component; this.communicator = communicator; dispatcherCallbackKeys = new Collections.List <ulong>(); dispatcherCallbackKeys.Add( communicator.RegisterReserveEntityIdResponse(CreateOnResponseThunk <ReserveEntityIdResponseOp, ReserveEntityIdResult>( op => op.RequestId.Id, op => op.StatusCode, op => op.Message, op => op.EntityId.HasValue ? new ReserveEntityIdResult(op.EntityId.Value) : new Option <ReserveEntityIdResult>()))); dispatcherCallbackKeys.Add( communicator.RegisterCreateEntityResponse(CreateOnResponseThunk <CreateEntityResponseOp, CreateEntityResult>( op => op.RequestId.Id, op => op.StatusCode, op => op.Message, op => op.EntityId.HasValue ? new CreateEntityResult(op.EntityId.Value) : new Option <CreateEntityResult>()))); dispatcherCallbackKeys.Add( communicator.RegisterReserveEntityIdsResponse(CreateOnResponseThunk <ReserveEntityIdsResponseOp, ReserveEntityIdsResult>( op => op.RequestId.Id, op => op.StatusCode, op => op.Message, op => new ReserveEntityIdsResult(op.FirstEntityId.Value, op.NumberOfEntityIds)))); dispatcherCallbackKeys.Add( communicator.RegisterDeleteEntityResponse(CreateOnResponseThunk <DeleteEntityResponseOp, DeleteEntityResult>( op => op.RequestId.Id, op => op.StatusCode, op => op.Message, op => new DeleteEntityResult(op.EntityId)))); dispatcherCallbackKeys.Add( communicator.RegisterEntityQueryResponse(CreateOnResponseThunk <EntityQueryResponseOp, EntityQueryResult>( op => op.RequestId.Id, op => op.StatusCode, op => op.Message, op => new EntityQueryResult(op.ResultCount, op.Result)))); if (component != null) { component.OnAuthorityChange += OnComponentAuthorityChange; } }
internal static Collections.List <T> .iterator find <T>(Collections.List <T> .iterator first, Collections.List <T> .iterator last, T val) { if (!first.IsAvailable) { return(first); } var list = first.List; int lastIndex; if (last.IsAvailable) { Debug.Assert(last.List == list); lastIndex = last.Index; } else { lastIndex = list.Count; } var comparer = Sys.EqualityComparer <T> .Default; for (var i = first.Index; i < lastIndex; i++) { if (comparer.Equals(list[i], val)) { return(new Collections.List <T> .iterator(list, i)); } } return(last); }
private ArgsUst VisitArguments(Esprima.Ast.List <ArgumentListElement> arguments) { var args = new Collections.List <UstExprs.Expression>(arguments.Count); foreach (ArgumentListElement arg in arguments) { // TODO: all cases of type casting if (arg is SpreadElement spreadElement) { // TODO: spread elements processing Logger.LogDebug("Spread elements are not supported for now"); } else if (arg is Expression expression) { args.Add(VisitExpression(expression)); } else { // TODO: Logger.LogDebug($"{arg.GetType().Name} are not supported for now"); } } return(new ArgsUst(args)); }
// Главная функция кодогенератора. Получает на вход синтаксическое дерево, обходит его и в хое его обхода с // помощью библиотеки System.Reflection строит исполняемый файл на MSIL, который потом можно запускать вне компилятора (однако, на компьютере должна быть установлена .Net Framwork) // Путь к файлу задаётся в интерфейсе компилятора public bool Proceed(Node Tree, RichTextBox RTB, string FileName) { _Tree = Tree; _RTB = RTB; InitFileName(FileName); try { Reflect.AssemblyName Name = new Reflect.AssemblyName(FileName); AsmBuilder = System.AppDomain.CurrentDomain.DefineDynamicAssembly(Name, Emit.AssemblyBuilderAccess.Save); ModBuilder = AsmBuilder.DefineDynamicModule(FileName); TypeTable = new Collections.Dictionary <string, Emit.TypeBuilder>(); CreatedTypeTable = new Collections.Dictionary <string, System.Type>(); SymbolTable = new Collections.List <Collections.Dictionary <string, Emit.LocalBuilder> >(); BeforeCompile(Tree); CreateCode(Tree); AsmBuilder.Save(FileName); this.SymbolTable = null; this.AssemblerGenerator = null; this.TypeTable = null; File.Move(FileName, FileName + ".exe"); File.Delete(FileName); return(true); } catch (System.Exception Exc) { _RTB.Text = Exc.Message; return(false); } }
public void List_InitialiseDefaultListTest() { var list = new Collections.List <int>(); Assert.Equal(0, list.Count); Assert.Equal((int)Math.Round(4 * 1.2m), list.Capacity); }
private UstExprs.Expression VisitClassExpression(ClassExpression classExpression) { var className = classExpression.Id != null ? VisitIdentifier(classExpression.Id) : null; var baseTypes = new Collections.List <UstTokens.TypeToken>(); if (classExpression.SuperClass != null) { if (VisitExpression(classExpression.SuperClass) is UstTokens.TypeToken superClassTypeToken) { baseTypes.Add(superClassTypeToken); } } var properties = VisitClassBody(classExpression.Body); var typeDeclaration = new TypeDeclaration(null, className, properties, GetTextSpan(classExpression)) { BaseTypes = baseTypes }; return(typeDeclaration.ToExpressionIfRequired()); }
private UstExprs.ArrayCreationExpression VisitArrayExpression(ArrayExpression arrayExpression) { var inits = new Collections.List <UstExprs.Expression>(arrayExpression.Elements.Count); foreach (ArrayExpressionElement element in arrayExpression.Elements) { UstExprs.Expression expr = null; if (element is SpreadElement spreadElement) { Logger.LogDebug("Spread elements are not supported for now"); // TODO } else if (element is Expression expression) { expr = VisitExpression(expression); } else if (element != null) { Logger.LogDebug($"{element.GetType().Name} are not supported for now"); // TODO } inits.Add(expr); } return(new UstExprs.ArrayCreationExpression(null, null, inits, GetTextSpan(arrayExpression))); }
private UstSpecific.CommaExpression VisitSequenceExpression(SequenceExpression sequenceExpression) { var exprs = new Collections.List <UstExprs.Expression>(sequenceExpression.Expressions.Count); foreach (Expression expr in sequenceExpression.Expressions) { exprs.Add(VisitExpression(expr)); } return(new UstSpecific.CommaExpression(exprs, GetTextSpan(sequenceExpression))); }
/// <summary> /// Creates a requirement set (a set of attribute sets) that a worker satisfies if and only /// it satisfies at least one of the attribute sets. /// </summary> public static WorkerRequirementSet MakeRequirementSet(WorkerAttributeSet attribute1, params WorkerAttributeSet[] attributes) { var list = new Collections.List <WorkerAttributeSet>(attributes.Length + 1); foreach (var attribute in Enumerate(attribute1, attributes)) { list.Add(attribute); } return(new WorkerRequirementSet(list)); }
/// <summary> /// Creates an attribute set that a worker satisfies if and only if it has all of the attributes. /// </summary> public static WorkerAttributeSet MakeAttributeSet(string attribute1, params string[] attributes) { var list = new Collections.List <string>(attributes.Length + 1); foreach (var attribute in Enumerate(attribute1, attributes)) { list.Add(attribute); } return(new WorkerAttributeSet(list)); }
private Collections.List <UstStmts.Statement> VisitStatements(Esprima.Ast.List <StatementListItem> listItems) { var statements = new Collections.List <UstStmts.Statement>(listItems.Count); foreach (StatementListItem listItem in listItems) { statements.Add(VisitStatementListItem(listItem).ToStatementIfRequired()); } return(statements); }
private void CompileMethodDecl(Node ActiveNode) { OpenBlockVariables(); OpenParametersBlock(); // Разбираем список переменных CreateCode(ActiveNode.Nodes[4]); // Создаём объявление метода Emit.MethodBuilder Method; if (FormalIds.Count == 0) { Method = CurrentType.DefineMethod(ActiveNode.Nodes[2].Value, Reflect.MethodAttributes.Public, TypeByTypeId(ActiveNode.Nodes[1]), System.Type.EmptyTypes); System.Type Tst = System.Type.GetType(ActiveNode.Nodes[1].Nodes[0].Value); } else { Collections.List <System.Type> FormalParameters = new Collections.List <System.Type>(); for (int i = 0; i < FormalIds.Count; i++) { FormalParameters.Add(TypeByTypeId(FormalTypes[i])); } Method = CurrentType.DefineMethod(ActiveNode.Nodes[2].Value, Reflect.MethodAttributes.Public, TypeByTypeId(ActiveNode.Nodes[1]), FormalParameters.ToArray()); } this.AssemblerGenerator = Method.GetILGenerator(); // Обнуляем список формальных параметров FormalTypes = new Collections.List <Node>(); FormalIds = new Collections.List <Node>(); // Вызываем разбор объявлений переменных CreateCode(ActiveNode.Nodes[7]); // Вызываем разбор тела метода CreateCode(ActiveNode.Nodes[8]); CreateCode(ActiveNode.Nodes[10]); // Завершаем метод AssemblerGenerator.Emit(Emit.OpCodes.Ret); CloseBlockVariables(); CloseParametersBLock(); }
public Collections.List <String> GetMemberNames() { var size = Count; var keys = new Collections.List <String>(size); for (int index = 0; index < size; index++) { var local = entries[index].Key; keys.Add(local.Name); } return(keys); }
public CheckedListBox() { InitializeComponent(); Items = new InternalObjectCollecton(this); GroupItemsCount = new SMAH1.Collections.List <int>(); GroupItemsCount.CountChanged += new EventHandler(List_CountChanged); ItemThreeState = new ThreeStateCollection(this); ItemChecked = new CheckedCollection(this); ItemCheckState = new CheckStateCollection(this); pnlLabelsInternal.AutoSize = true; }
/// <summary> /// Get PropertyUsageAttributes for all properties in entity /// </summary> /// <param name="apiContext"></param> /// <param name="entityType"></param> /// <param name="propertiesUsageAttributes"></param> /// <returns></returns> public static Helpers.ActionResult GetPropertiesUsageAttributes(Helpers.ApiContext apiContext, Type entityType, out Collections.IEnumerable <Helpers.PropertyUsageAttributes> propertiesUsageAttributes) { // API doesn't allow null parameters. This method requires at least 1 item in the collection. if (apiContext == null) { throw new System.ArgumentNullException("apiContext"); } if (entityType == null) { throw new System.ArgumentNullException("entityType"); } Helpers.ActionResult result = Helpers.ActionResult.Factory(true); try { using (Model.OrmsContext contexte = (Model.OrmsContext)apiContext.CurrentContext) { System.Data.Metadata.Edm.EntityType edmEntityType = (from item in contexte.MetadataWorkspace.GetItems(System.Data.Metadata.Edm.DataSpace.CSpace) where item.BuiltInTypeKind == System.Data.Metadata.Edm.BuiltInTypeKind.EntityType && (item as System.Data.Metadata.Edm.EntityType).Name == entityType.Name select item as System.Data.Metadata.Edm.EntityType).First(); propertiesUsageAttributes = from p in edmEntityType.Properties //where p.Name.ToLower() == fieldName select SetPropertyUsageAttributes(p); //select new Helpers.PropertyUsageAttributes //{ // Name = p.Name, // MaxLength = p.TypeUsage.EdmType.Name.ToLower() == "string" ? System.Convert.ToInt32(p.TypeUsage.Facets["MaxLength"].Value) : (-1), // Required = !System.Convert.ToBoolean(p.TypeUsage.Facets["Nullable"].Value), // Type = p.TypeUsage.EdmType.Name //}; if (propertiesUsageAttributes == null) { propertiesUsageAttributes = new Collections.List <Helpers.PropertyUsageAttributes>(); } } } catch (System.Exception ex) { object forDebugging = ex; throw; } return(result); }
private UstStmts.ExpressionStatement VisitVariableDeclaration(VariableDeclaration variableDeclaration) { var variables = new Collections.List <UstExprs.AssignmentExpression>(variableDeclaration.Declarations.Count); foreach (VariableDeclarator decl in variableDeclaration.Declarations) { var left = (UstExprs.Expression)Visit(decl.Id); // TODO: fix? var initExpr = decl.Init != null?VisitExpression(decl.Init) : null; variables.Add(new UstExprs.AssignmentExpression(left, initExpr, GetTextSpan(decl))); } var varDecl = new UstExprs.VariableDeclarationExpression(null, variables, GetTextSpan(variableDeclaration)); return(new UstStmts.ExpressionStatement(varDecl)); }
private UstStmts.TryCatchFinally.TryCatchStatement VisitTryStatement(TryStatement tryStatement) { var block = (UstStmts.BlockStatement)VisitStatement(tryStatement.Block); var catchClauses = new Collections.List <UstStmts.TryCatchFinally.CatchClause>(); if (tryStatement.Handler != null) { var body = VisitBlockStatement(tryStatement.Handler.Body); var varName = VisitArrayPatternElement(tryStatement.Handler.Param); catchClauses.Add(new UstStmts.TryCatchFinally.CatchClause(varName?.Type, varName?.Name, body, GetTextSpan(tryStatement.Handler))); } return(new UstStmts.TryCatchFinally.TryCatchStatement(block, GetTextSpan(tryStatement)) { CatchClauses = catchClauses, FinallyBlock = tryStatement.Finalizer != null ? (UstStmts.BlockStatement)VisitStatement(tryStatement.Finalizer) : null }); }
public void List_InitialiseWithRandomIntegerArrayTest() { var random = new Random(); var arraySize = random.Next(20, 200); var items = new int[arraySize]; for (int i = 0; i < items.Length; i++) { items[i] = random.Next(); } var list = new Collections.List <int>(items); Assert.Equal(items.Length, list.Count); Assert.Equal((int)Math.Round(arraySize * 1.2m), list.Capacity); for (int i = 0; i < items.Length; i++) { Assert.Equal(items[i], list[i]); } }
private UstStmts.Switch.SwitchStatement VisitSwitchStatement(SwitchStatement switchStatement) { var expression = VisitExpression(switchStatement.Discriminant); var switchSections = new Collections.List <UstStmts.Switch.SwitchSection>(switchStatement.Cases.Count); foreach (SwitchCase @case in switchStatement.Cases) { var caseLabels = new Collections.List <UstExprs.Expression>(); if (@case.Test != null) { // Default label if null caseLabels.Add(VisitExpression(@case.Test)); } var switchSection = new UstStmts.Switch.SwitchSection( caseLabels, VisitStatements(@case.Consequent), GetTextSpan(@case)); switchSections.Add(switchSection); } return(new UstStmts.Switch.SwitchStatement(expression, switchSections, GetTextSpan(switchStatement))); }
private UstStmts.ForStatement VisitForStatement(ForStatement forStatement) { var initList = new Collections.List <UstStmts.Statement>(1); if (forStatement.Init != null) { initList.Add(Visit(forStatement.Init).ToStatementIfRequired()); } UstExprs.Expression condition = forStatement.Test != null ? VisitExpression(forStatement.Test) : null; var iteratorList = new Collections.List <UstExprs.Expression>(1); if (forStatement.Update != null) { iteratorList.Add(VisitExpression(forStatement.Update)); } var body = VisitStatement(forStatement.Body); return(new UstStmts.ForStatement(initList, condition, iteratorList, body, GetTextSpan(forStatement))); }
public override Base GetListing(Collections.List nameParts) { return(TheFileSystem.GetListingFromListings(nameParts, Parent, GetListings())); }
private UstStmts.BlockStatement VisitBlockStatement(BlockStatement blockStatement) { Collections.List <UstStmts.Statement> statements = VisitStatements(blockStatement.Body); return(new UstStmts.BlockStatement(statements, GetTextSpan(blockStatement))); }