public TutorialAnimation(IEnumerable<TutorialAnimationCheckpoint> checkpoints) { this.checkpoints = new List<TutorialAnimationCheckpoint>(checkpoints); this.checkpoints.TrimExcess(); restartAnimation(); }
private UstExprs.Expression VisitTemplateLiteral(TemplateLiteral templateLiteral) { var elems = new Collections.List <INode>(templateLiteral.Expressions.Count + templateLiteral.Quasis.Count); elems.AddRange(templateLiteral.Expressions); elems.AddRange(templateLiteral.Quasis); elems.Sort(NodeLocationComparer.Instance); UstExprs.Expression result = null; for (int i = 0; i < elems.Count; i++) { UstExprs.Expression expr; if (elems[i] is Expression expression) { expr = VisitExpression(expression); } else { expr = VisitTemplateElement((TemplateElement)elems[i]); } var opLiteral = new UstLiterals.BinaryOperatorLiteral(UstTokens.BinaryOperator.Plus, TextSpan.FromBounds(expr.TextSpan.End, expr.TextSpan.End)); result = result == null ? expr : new UstExprs.BinaryOperatorExpression(result, opLiteral, expr, result.TextSpan.Union(expr.TextSpan)); } return(result); }
private MethodInfo GetMethodInfo(MethodCall objCall) { Collections.List <string> dllPath = null; System.Reflection.Assembly objAssembly = null; Type classType = null; MethodInfo methodInfo = null; if (objCall.assemblyName == null) { dllPath = GetAssemblyPath(objCall.className); } else { dllPath = new System.Collections.Generic.List <string>(); dllPath.Add(objCall.assemblyName); } foreach (string path in dllPath) { methodInfo = null; objAssembly = System.Reflection.Assembly.LoadFrom(path); classType = objAssembly.GetType(objCall.className); if (classType == null) { continue; } if (objCall.parameters.Count < 1) { methodInfo = classType.GetMethod(objCall.methodName, new System.Type[] { }); } else { Collections.List <Type> types = new System.Collections.Generic.List <Type>(); foreach (object para in objCall.parameters) { string varaibleName = para.ToString(); types.Add(this.symbolTable[varaibleName].LocalType); } methodInfo = classType.GetMethod(objCall.methodName, types.ToArray()); if (methodInfo != null) { objCall.assemblyName = path; break; } } } if (methodInfo == null) { throw new Exception("Method Not Found:" + objCall.className + "." + objCall.methodName); } return(methodInfo); }
private Collections.List <PropertyDeclaration> VisitProperties(List <Property> properties) { var props = new Collections.List <PropertyDeclaration>(properties.Count); foreach (Property prop in properties) { props.Add(VisitClassProperty(prop)); } return(props); }
private Collections.List <PropertyDeclaration> VisitClassBody(ClassBody classBody) { var properties = new Collections.List <PropertyDeclaration>(classBody.Body.Count); foreach (ClassProperty classProperty in classBody.Body) { properties.Add(VisitClassProperty(classProperty)); } return(properties); }
private UstSpecific.ArrayPatternExpression VisitArrayPattern(ArrayPattern arrayPattern) { var elements = new Collections.List <ParameterDeclaration>(arrayPattern.Elements.Count); foreach (IArrayPatternElement elem in arrayPattern.Elements) { ParameterDeclaration paramDecl = VisitArrayPatternElement(elem); elements.Add(paramDecl); } return(new UstSpecific.ArrayPatternExpression(elements, GetTextSpan(arrayPattern))); }
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(); }
private Collections.List <ParameterDeclaration> VisitParameters(Esprima.Ast.List <INode> parameters) { var result = new Collections.List <ParameterDeclaration>(parameters.Count); foreach (INode param in parameters) { UstTokens.IdToken name; if (param is Identifier identifier) { name = VisitIdentifier(identifier); } else { // TODO: extend parameter declaration name = new UstTokens.IdToken("", GetTextSpan(param)); } result.Add(new ParameterDeclaration(null, null, name, name.TextSpan)); } return(result); }
public RootUst Convert(ParseTree langParseTree) { try { var esprimaParseTree = (JavaScriptEsprimaParseTree)langParseTree; if (SourceFile == null) { SourceFile = esprimaParseTree.SourceFile; } var program = VisitProgram(esprimaParseTree.SyntaxTree); var rootUst = new RootUst(SourceFile, Language.JavaScript, GetTextSpan(esprimaParseTree.SyntaxTree)) { Nodes = new Ust[] { program }, }; var comments = new Collections.List <CommentLiteral>(esprimaParseTree.Comments.Count); foreach (Comment comment in esprimaParseTree.Comments) { TextSpan textSpan = GetTextSpan(comment); comments.Add(new CommentLiteral(SourceFile.GetSubstring(textSpan), textSpan) { Root = rootUst, }); } rootUst.Comments = comments.ToArray(); rootUst.Root = ParentRoot; rootUst.FillAscendants(); return(rootUst); } catch (Exception ex) when(!(ex is ThreadAbortException)) { Logger.LogError(new ConversionException(SourceFile, ex)); return(null); } }
private TypeDeclaration VisitClassDeclaration(ClassDeclaration classDeclaration) { var name = classDeclaration.Id != null ? VisitIdentifier(classDeclaration.Id) : null; var baseTypes = new Collections.List <TypeToken>(); if (classDeclaration.SuperClass != null) { if (VisitExpression(classDeclaration.SuperClass) is TypeToken superClassTypeToken) { baseTypes.Add(superClassTypeToken); } } var properties = VisitClassBody(classDeclaration.Body); return(new TypeDeclaration(null, name, properties, GetTextSpan(classDeclaration)) { BaseTypes = baseTypes }); }
private static void Translate <TEntity>(System.Data.Common.DbDataReader reader, out Collections.List <TEntity> entities) where TEntity : class { // Initilize list entities = new Collections.List <TEntity>(); System.Type type = typeof(TEntity); System.Reflection.MethodInfo methodInfo = type.GetMethod("Factory", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public); while (reader.Read()) { // Create Object TEntity entity = (TEntity)methodInfo.Invoke(null, new object[0]); foreach (System.Reflection.PropertyInfo property in type.GetProperties()) { if (IsComplexType(property)) // Complex Type { Entities.EntityObject complexEntity = null; if (TryGetValue(property, reader, out complexEntity)) { property.SetValue(entity, complexEntity, null); } } else if (IsPrimitiveType(property)) // Primitive Type { object value = null; if (TryGetValue(property.Name, reader, out value)) { property.SetValue(entity, value, null); } } } entities.Add(entity); } }
public void RequestChunks(int Id, Vector3 PlayerPosition, int RenderDistance) { if (!GetTree().IsNetworkServer()) { RpcId(Net.ServerId, nameof(RequestChunks), new object[] { Id, PlayerPosition, RenderDistance }); return; } Collections.List <Tuple <int, int> > LoadedChunks = RemoteLoadedChunks[Id]; foreach (Collections.KeyValuePair <System.Tuple <int, int>, Collections.List <Structure> > Chunk in Chunks) { Vector3 ChunkPos = new Vector3(Chunk.Key.Item1, 0, Chunk.Key.Item2); Tuple <int, int> ChunkTuple = GetChunkTuple(ChunkPos); if (ChunkPos.DistanceTo(new Vector3(PlayerPosition.x, 0, PlayerPosition.z)) <= RenderDistance * (Building.PlatformSize * 9)) { //This chunk is close enough to the player that we should send it along if (!LoadedChunks.Contains(ChunkTuple)) { //If not already in the list of loaded chunks for this client then add it RemoteLoadedChunks[Id].Add(ChunkTuple); //And send it SendChunk(Id, ChunkTuple); } //If already loaded then don't send it } else { //This chunk is to far away if (LoadedChunks.Contains(ChunkTuple)) { //If it is in the list of loaded chunks for this client then remove RemoteLoadedChunks[Id].Remove(ChunkTuple); } } } }
/// <summary> /// Private function for handling subroutines. /// Encountered subroutines are handled first! Nested subs may not yield the expected outcome... Refer to sample script file. /// </summary> /// <param name="t_arg">Token that holds the ParL value after the function name</param> /// <returns>Token after the one that contains the ParR value</returns> private Token ParseFunction(ref Token t_arg) { string fname = t_arg.val; if (t_arg.next.kind != 4) { throw new Exception("Expected '(' after function name!"); } t_arg = t_arg.next.next; //eat parL and get next char // Collections.List <Token> args = new Collections.List <Token>(); while (t_arg.kind != 8) { switch (t_arg.kind) { case 1: args.Add(new Token() { val = t_arg.val, kind = t_arg.kind }); break; case 2: args.Add(new Token() { val = t_arg.val, kind = t_arg.kind }); break; case 3: args.Add(ParseFunction(ref t_arg)); break; default: throw new Exception("Unsupported character as argument!"); } t_arg = t_arg.next; } char op = '\0'; /* * List of functions. Some were added later on to be able to run certain test cases. * That might explain the messy appearance of this bit.. Highly influenced by foobar2000 scripting. */ switch (fname) { case "if": if (args.Count < 2) { throw new ArgumentException("Expected at least 2 arguments!"); } return((this.ConvertToBool(GetValue(args[0]))) ? args[1] : new Token() { val = String.Empty, kind = 1, line = 0, next = null }); case "if2": if (args.Count < 3) { throw new ArgumentException("Expected at least 3 arguments!"); } return(new Token() { val = (this.ConvertToBool(GetValue(args[0]))) ? GetValue(args[1]) : GetValue(args[2]), kind = 1 }); case "puts": if (args.Count < 2) { throw new ArgumentException("Expected at least 2 arguments!"); } if (args[0].kind != 2) { throw new Exception("Expected a variable for the first argument"); } _VARS[args[0].val] = GetValue(args[1]); return(new Token() { kind = 1, val = "" }); case "add": op = '+'; goto case "mathop"; case "sub": op = '-'; goto case "mathop"; case "mul": op = '*'; goto case "mathop"; case "div": op = '/'; goto case "mathop"; case "mathop": { if (args.Count < 2) { throw new ArgumentException("Expected at least 2 arguments!"); } double a, b; if (double.TryParse(GetValue(args[0]), out a) && double.TryParse(GetValue(args[1]), out b)) { switch (op) { case '+': return(new Token() { kind = 1, val = (a + b).ToString() }); case '-': return(new Token() { kind = 1, val = (a - b).ToString() }); case '/': return(new Token() { kind = 1, val = (a / b).ToString() }); case '*': return(new Token() { kind = 1, val = (a * b).ToString() }); default: throw new ArgumentException("Invalid operator detected."); } } else { throw new ArgumentException("Non-numeric arguments detected."); } } case "eq": if (args.Count < 2) { throw new ArgumentException("Expected at least 2 arguments!"); } else if (args.Count == 2) { return new Token() { kind = 1, val = GetValue(args[0]).Equals(GetValue(args[1])).ToString() } } ; else //more than 2 arguments { int argnum = 1; bool state = false; while (argnum < args.Count) { state = state | GetValue(args[0]).Equals(GetValue(args[argnum++])); } return(new Token() { kind = 1, val = state.ToString() }); } case "and": if (args.Count < 2) { throw new ArgumentException("Expected at least 2 arguments!"); } else if (args.Count == 2) { return(new Token() { kind = 1, val = (Convert.ToBoolean(GetValue(args[0])) && Convert.ToBoolean(GetValue(args[1]))).ToString() }); } else //more than 2 arguments { int argnum = 1; bool state = true; while (argnum < args.Count) { state = state & Boolean.Parse(GetValue(args[argnum++])); } return(new Token() { kind = 1, val = state.ToString() }); } case "cmp": if (args.Count < 3 || args.Count > 3) { throw new ArgumentException("Expected 3 arguments!"); } else { int scenario; bool result; double arg0, arg1; if (Int32.TryParse(GetValue(args[2]), out scenario) && Double.TryParse(GetValue(args[0]), out arg0) && Double.TryParse(GetValue(args[1]), out arg1)) { switch (scenario) { case -1: result = (arg0 < arg1); break; case 1: result = (arg0 > arg1); break; default: result = (arg0 == arg1); break; } } else { throw new ArgumentException("Expected numerical arguments! Use eq function for string comparison!"); } return(new Token() { kind = 1, val = result.ToString() }); } //IO Functions that were never implemented.. case "open": { if (args.Count < 2) { throw new ArgumentException("Expected at least 2 arguments!"); } try { IO.StreamReader temp = new IO.StreamReader(GetValue(args[1])); _PIPES[args[0].val] = temp; } catch (IO.IOException ie) { throw ie; } return(new Token() { kind = 1, val = "" }); } case "close": { if (args.Count < 1) { throw new ArgumentException("Expected 1 argument!"); } IO.StreamReader temp; if (_PIPES.TryGetValue(GetValue(args[0]), out temp)) { temp.Close(); _PIPES.Remove(GetValue(args[0])); } return(new Token() { kind = 1, val = "" }); } default: throw new Exception("Unexistent function name."); } }
protected static void ExecuteStoreQuery <TEntity>(Helpers.ApiContext apiContext, System.String sqlQuery, object[] parameters, out Collections.List <TEntity> entities) where TEntity : class { System.Data.IDbConnection connection = (apiContext.CurrentContext.Connection as System.Data.EntityClient.EntityConnection).StoreConnection; connection.Open(); using (System.Data.IDbCommand command = connection.CreateCommand()) { command.CommandText = sqlQuery; int index = 0; foreach (object value in parameters) { command.Parameters.Add(new System.Data.SqlClient.SqlParameter("@p" + index++, value)); } using (System.Data.Common.DbDataReader reader = (System.Data.Common.DbDataReader)command.ExecuteReader()) { Translate <TEntity>(reader, out entities); } } }
protected static void ExecuteStoreQuery <TEntity>(Helpers.ApiContext apiContext, System.String sqlQuery, out Collections.List <TEntity> entities) where TEntity : class { ExecuteStoreQuery <TEntity>(apiContext, sqlQuery, new object[0], out entities); }
private void OpenParametersBlock() { Collections.List <string> NewBlock = new Collections.List <string>(); ParametersStack.Add(NewBlock); }
public ParseTree Parse(TextFile sourceFile, out TimeSpan parserTimeSpan) { if (sourceFile.Data == null) { return(null); } var errorHandler = new JavaScriptEsprimaErrorHandler(sourceFile) { Logger = Logger, Offset = Offset, OriginFile = OriginFile }; try { var parserOptions = new ParserOptions(sourceFile.FullName) { Range = true, Comment = true, Tolerant = true, ErrorHandler = errorHandler }; var parser = new JavaScriptParser(sourceFile.Data, parserOptions); var stopwatch = Stopwatch.StartNew(); Program ast = parser.ParseProgram(JavaScriptType == JavaScriptType.Strict); stopwatch.Stop(); parserTimeSpan = stopwatch.Elapsed; var scanner = new Scanner(sourceFile.Data, parserOptions); errorHandler.Scanner = scanner; errorHandler.Logger = DummyLogger.Instance; // Ignore errors on tokenization because of the first stage var comments = new Collections.List <Comment>(); stopwatch.Restart(); Token token; do { comments.AddRange(scanner.ScanComments()); try { token = scanner.Lex(); } catch (Exception ex) when(!(ex is ThreadAbortException)) { // TODO: handle the end of the stream without exception Logger.LogError(new ParsingException(sourceFile, ex)); break; } }while (token.Type != TokenType.EOF); stopwatch.Stop(); TimeSpan lexerTimeSpan = stopwatch.Elapsed; // TODO: store lexer time // TODO: comments handling without scanner, https://github.com/sebastienros/esprima-dotnet/issues/39 var result = new JavaScriptEsprimaParseTree(ast, comments); result.SourceFile = sourceFile; return(result); } catch (Exception ex) when(!(ex is ThreadAbortException)) { ParsingException exception = ex is ParserException parserException ? errorHandler.CreateException(parserException.Index, parserException.Message) : ex is ParsingException parsingException ? parsingException : new ParsingException(sourceFile, ex); Logger.LogError(exception); return(null); } }
public JavaScriptEsprimaParseTree(Program syntaxTree, Collections.List <Comment> comments) { SyntaxTree = syntaxTree ?? throw new ArgumentNullException(nameof(syntaxTree)); Comments = comments ?? throw new ArgumentNullException(nameof(comments)); }