public FunctionNotDefinedError(string functionName, IEnumerable<Type> argTypes, FunctionScope scope, SourceLocation location) : base(location) { _functionName = functionName; _argTypes = argTypes; _scope = scope; }
public AstHelper(ModuleBuilder moduleBuilder) { ModuleBuilder = moduleBuilder; Expecting = new Expecting(); Functions = new FunctionScope(); Variables = new VariableScope(); Types = new TypeScope(); Errors = new ErrorSet(); ReturnScope = new ReturnScope(); }
public void Clear() { foreach (KeyValuePair<string, ControlPropertyMetaDataPair> kvp in this.Properties) { IEntityControl ctrl = kvp.Value.Control; using (FunctionScope fsControl = new FunctionScope(this.RemoveControlValueChanged, ctrl, this.AddControlValueChanged, ctrl)) { ctrl.Clear(); } } }
public void resolves_function_wih_same_number_of_parameters() { var scope = new FunctionScope(); ConstantExpression function1 = Expression.Constant(1); ConstantExpression function2 = Expression.Constant(2); scope.Add("f1", new FunctionReference(function1, typeof (void), typeof (string))); scope.Add("f1", new FunctionReference(function2, typeof (void), typeof (int))); FunctionReference result = scope["f1", typeof (int)]; Assert.AreSame(function2, result.Function); }
public void resolves_correct_function_with_different_arguments_returns_function_with_no_args() { var scope = new FunctionScope(); ConstantExpression function1 = Expression.Constant(1); ConstantExpression function2 = Expression.Constant(2); scope.Add("f1", new FunctionReference(function1, typeof (void))); scope.Add("f1", new FunctionReference(function2, typeof (void), typeof (int))); FunctionReference result = scope["f1"]; Assert.AreSame(function1, result.Function); }
public void resolves_function_when_called_with_nil_parameter_and_different_number_of_args() { var scope = new FunctionScope(); ConstantExpression function1 = Expression.Constant(1); ConstantExpression function2 = Expression.Constant(2); scope.Add("f1", new FunctionReference(function1, typeof (void))); scope.Add("f1", new FunctionReference(function2, typeof (void), typeof (string))); FunctionReference result = scope["f1", typeof (Null)]; Assert.AreSame(function2, result.Function); }
protected override Result _execute(ImmutableArray <EvaluatedParameter> parameters, FunctionScope function_scope) { if (parameters.Length != 1) { throw new WrongParameterCountException(this, expected: 1, actual: parameters.Length); } FinalExpression param_1 = parameters [0].EvaluatedValue; if (param_1.GetScalarAffinity() == ScalarAffinity.ARRAY) { return(new Result(new BoolExpression(true))); } else { return(new Result(new BoolExpression(false))); } }
protected override Result _execute(ImmutableArray <EvaluatedParameter> parameters, FunctionScope function_scope) { return(Result.NULL); }
IAnalysisSet SpecialSuper(Node node, AnalysisUnit unit, IAnalysisSet[] args, NameExpression[] keywordArgNames) { if (args.Length < 0 || args.Length > 2) { return(AnalysisSet.Empty); } var classes = AnalysisSet.Empty; var instances = AnalysisSet.Empty; if (args.Length == 0) { if (unit.State.LanguageVersion.Is3x()) { // No-arg version is magic in 3k - first arg is implicitly the enclosing class, and second is implicitly // the first argument of the enclosing method. Look up that information from the scope. // We want to find the nearest enclosing class scope, and the function scope that is immediately beneath // that class scope. If there is no such combo, a no-arg super() is invalid. var scopes = unit.Scope; ClassScope classScope = null; FunctionScope funcScope = null; foreach (var s in scopes.EnumerateTowardsGlobal) { funcScope = s as FunctionScope; if (funcScope != null) { classScope = s.OuterScope as ClassScope; if (classScope != null) { break; } } } if (classScope != null && funcScope != null) { classes = classScope.Class.SelfSet; // Get first arg of function. if (funcScope.Function.FunctionDefinition.Parameters.Length > 0) { instances = classScope.Class.Instance.SelfSet; } } } } else { classes = args[0]; if (args.Length > 1) { instances = args[1]; } } if (classes == null) { return(AnalysisSet.Empty); } return(unit.InterpreterScope.GetOrMakeNodeValue(node, NodeValueKind.Super, _ => { var res = AnalysisSet.Empty; foreach (var classInfo in classes.OfType <ClassInfo>()) { res = res.Add(new SuperInfo(classInfo, instances)); } return res; })); }
protected override Result _execute(ImmutableArray <EvaluatedParameter> parameters, FunctionScope function_scope) { foreach (EvaluatedParameter p in parameters) { function_scope.Root.Context.Console.Err.Write(p.EvaluatedValue.GetStringValue()); } return(new Result(new NullExpression()).DoFastReturn()); }
//Controls Values To Entity' s Properties //and also DBRecord.ValidateControls(); public bool ReadValues() { bool ret = true; foreach (KeyValuePair<string, ControlPropertyMetaDataPair> kvp in this.Properties) { IEntityControl ctrl = kvp.Value.Control; using (FunctionScope fsEntity = new FunctionScope(this.RemoveEntityPropertyChanged, this.AddEntityPropertyChanged)) { ret = this.SetControlValueToEntity(ctrl) && ret; } } return ret; }
protected override Result _execute(ImmutableArray <EvaluatedParameter> parameters, FunctionScope function_scope) { if (parameters.Length != 1) { throw new WrongParameterCountException(this, expected: 1, actual: parameters.Length); } FinalExpression param_1 = parameters [0].EvaluatedValue; bool does_exist = function_scope.Root.Functions.Contains(param_1.GetStringValue()); return(new Result(new BoolExpression(does_exist))); }
protected override Result _execute(ImmutableArray <EvaluatedParameter> parameters, FunctionScope function_scope) { if (parameters.Length != 2 && parameters.Length != 3) { throw new WrongParameterCountException(this, expected: 2, actual: parameters.Length); } string haystack = parameters [0].EvaluatedValue.GetStringValue(); string needle = parameters [1].EvaluatedValue.GetStringValue(); long startindex = parameters.Length >= 3 ? parameters [2].EvaluatedValue.GetLongValue() : 0; int index = haystack.LastIndexOf(needle, (int)startindex, StringComparison.Ordinal); if (index == -1) { return(new Result(new BoolExpression(false))); } return(new Result(new LongExpression(index))); }
/// <summary> /// Compiles the source text into a module. /// </summary> /// <param name="sourceText">The source text.</param> /// <param name="module">The source module.</param> /// <returns>The compiled module.</returns> public static Module Compile(string sourceText, string module = "") { var parser = new Parser(sourceText, module); // ------------------------------------------------------------------------- LexicalScope scope = new FunctionScope(null) { Token = parser.Next }; void EnterFunctionScope(Token token) { scope = new FunctionScope(scope) { Token = token }; } void EnterBlockScope(Token token) { scope = new BlockScope(scope) { Token = token }; } void EnterLoopScope(Token token) { scope = new LoopScope(scope) { Token = token }; } void LeaveScope() { scope = scope.Scope; Debug.Assert(scope != null); } // ------------------------------------------------------------------------- Slot MakeSlot(string name) { foreach (var found in scope.SlotsInScope) { if (found.Name == name) { throw parser.Error($"'{name}' is already defined in this scope"); } } var slot = new Slot { Name = name, Scope = scope }; scope.Slots.Add(slot); return(slot); } Slot FindSlot(string name) { foreach (var found in scope.SlotsInScope) { if (found.Name == name) { return(found); } } throw parser.Error($"Undefined '{name}'"); } // ------------------------------------------------------------------------- // Identifier declaration parser.Syntax.Declaration(Token.Word).Do((token, context) => new Identifier(MakeSlot(token.Text)) { Token = token, Scope = scope, }); // ------------------------------------------------------------------------- // Grouping: ( expr ) // Function expression: ( ) => expr_or_block // Function expression: ( ...ident ) => expr_or_block // Function expression: ( ident , ... ) => expr_or_block parser.Syntax.Primitive("(").Do((token, context) => { var isFunction = parser.Match(")", "=>") || parser.Match(Token.Word, ",") || parser.Match(Token.Word, ")", "=>") || parser.Match("...", Token.Word, ")", "=>"); if (isFunction) { var expression = new FunctionExpression { Token = token, Scope = scope, }; EnterFunctionScope(token); { parser.RepeatZeroOrMoreWithSeparatorUntil(")", ",", delegate { var isRestParameter = parser.Optional("..."); if (parser.Declaration(context) is Identifier parameter) { var index = expression.Parameters.Count; expression.Parameters.Add(parameter); parameter.Slot.Kind = SlotKind.Parameter; parameter.Slot.ReadOnly = true; // <- parameters are always read-only if (isRestParameter) { parameter.Slot.Source = SlotSource.ArgumentSlice; parameter.Slot.SourceIndex = index; parser.Next.Require(")", "The rest parameter must be the last"); } else { parameter.Slot.Source = SlotSource.Argument; parameter.Slot.SourceIndex = index; } } else { throw parser.Error("Expected a parameter name"); } }); var arrow = parser.Required("=>"); if (parser.Optional("{") is Token begin) { expression.Body = new Block { Token = begin, Scope = scope, }; parser.RepeatZeroOrMoreUntil("}", delegate { expression.Body.Statements.Add(parser.Statement(context) as Statement); }); } else if (parser.Expression(context) is Expression value) { expression.Body = new Block { Token = arrow, Scope = scope, Statements = { new ReturnStatement { Token = arrow, Scope = scope, Value = value, }, }, }; } else { throw parser.Error("Expected an expression after '=>'"); } }
public void FunctionCallExpression(CParser.FunctionCallExpression FunctionCallExpression) { var Function = FunctionCallExpression.Function; if (Function is CParser.IdentifierExpression) { var IdentifierExpression = Function as CParser.IdentifierExpression; var FunctionName = IdentifierExpression.Identifier; var ParametersExpressions = FunctionCallExpression.Parameters.Expressions; // Special functions. switch (FunctionName) { // Alloca Special Function. case "alloca": { #if true // alloca requires the stack to be empty after calling it? var Stack = SafeILGenerator.StackSave(); var AllocaAddressLocal = SafeILGenerator.DeclareLocal(typeof(void *)); { Traverse(ParametersExpressions); SafeILGenerator.StackAlloc(); } SafeILGenerator.StoreLocal(AllocaAddressLocal); SafeILGenerator.StackRestore(Stack); SafeILGenerator.LoadLocal(AllocaAddressLocal); #else var AllocaLocal = SafeILGenerator.DeclareLocal(typeof(void *), "AllocaLocal"); Traverse(FunctionCallExpression.Parameters.Expressions); //SafeILGenerator.ConvertTo(typeof(void*)); SafeILGenerator.StackAlloc(); SafeILGenerator.ConvertTo(typeof(void *)); SafeILGenerator.StoreLocal(AllocaLocal); SafeILGenerator.LoadLocal(AllocaLocal); //throw(new NotImplementedException("Currently this does not work!")); #endif } break; // Normal plain function. default: { var VariableReference = VariableScope.Find(IdentifierExpression.Identifier); var FunctionReference = FunctionScope.Find(IdentifierExpression.Identifier); if (VariableReference != null) { var CFunctionType = VariableReference.CType.GetSpecifiedCType <CFunctionType>(); var ReturnType = ConvertCTypeToType(CFunctionType.Return); var ParameterTypes = CFunctionType.Parameters.Select(Item => ConvertCTypeToType(Item.CType)).ToArray(); Traverse(ParametersExpressions); Traverse(IdentifierExpression); SafeILGenerator.CallManagedFunction(CallingConventions.Standard, ReturnType, ParameterTypes, null); } else if (FunctionReference != null) { Type[] ParameterTypes; if (FunctionReference.SafeMethodTypeInfo == null) { if (FunctionReference.MethodInfo.CallingConvention == CallingConventions.VarArgs) { ParameterTypes = FunctionCallExpression.Parameters.Expressions.Select(Expression => ConvertCTypeToType(Expression.GetCachedCType(this))).ToArray(); } else { ParameterTypes = FunctionReference.MethodInfo.GetParameters().Select(Parameter => Parameter.ParameterType).ToArray(); } } else { ParameterTypes = FunctionReference.SafeMethodTypeInfo.Parameters; } if (ParameterTypes.Length != ParametersExpressions.Length) { throw (new Exception(String.Format( "Function parameter count mismatch {0} != {1} calling function '{2}'", ParameterTypes.Length, ParametersExpressions.Length, FunctionName ))); } ParameterTypes = ParameterTypes.Select(Item => GetRealType(Item)).ToArray(); for (int n = 0; n < ParametersExpressions.Length; n++) { var Expression = ParametersExpressions[n]; var ExpressionCType = Expression.GetCachedCType(this); var ExpressionType = ConvertCTypeToType(ExpressionCType); var ParameterType = GetRealType(ParameterTypes[n]); Traverse(Expression); // Expected a string. Convert it! if (ParameterType == typeof(string)) { if (ExpressionType == typeof(sbyte *)) { SafeILGenerator.ConvertTo(typeof(sbyte *)); SafeILGenerator.Call((CLibUtils.PointerToStringDelegate)CLibUtils.GetStringFromPointer); } else { throw (new NotImplementedException(String.Format("Invalid string expression {0}", ExpressionType))); } } else { SafeILGenerator.ConvertTo(ParameterType); } } if (FunctionReference.SafeMethodTypeInfo == null && FunctionReference.MethodInfo.CallingConvention == CallingConventions.VarArgs) { //SafeILGenerator.LoadFunctionPointer(FunctionReference.MethodInfo, IsVirtual: false); //SafeILGenerator.CallManagedFunction(CallingConventions.VarArgs, FunctionReference.MethodInfo.ReturnType, ParameterTypes, null); SafeILGenerator.Call(FunctionReference.MethodInfo, FunctionReference.SafeMethodTypeInfo, ParameterTypes); } else { SafeILGenerator.Call(FunctionReference.MethodInfo, FunctionReference.SafeMethodTypeInfo); } } else { throw (new Exception(String.Format("Unknown function '{0}'", IdentifierExpression.Identifier))); } //SafeILGenerator.__ILGenerator.Emit(OpCodes.Call //throw (new NotImplementedException("Function: " + IdentifierExpression.Value)); } break; } } else { throw (new NotImplementedException()); } }
protected override Result _execute(ImmutableArray <EvaluatedParameter> parameters, FunctionScope function_scope) { if (parameters.Length != 3 && parameters.Length != 4) { throw new WrongParameterCountException(this, expected: 1, actual: parameters.Length); } string search = parameters [0].EvaluatedValue.GetStringValue(); string replace = parameters [1].EvaluatedValue.GetStringValue(); string subject = parameters [2].EvaluatedValue.GetStringValue(); string count = parameters.Length >= 4 ? parameters [3].EvaluatedValue.GetStringValue() : null; string res = Replace(subject, search, replace, _comparison); return(new Result(new StringExpression(res))); }
protected override Result _execute(ImmutableArray <EvaluatedParameter> parameters, FunctionScope function_scope) { return(new Result("localhost")); }
protected override Result _execute(ImmutableArray <EvaluatedParameter> parameters, FunctionScope function_scope) { if (parameters.Length != 1) { throw new WrongParameterCountException(this, expected: 1, actual: parameters.Length); } FinalExpression param_1 = parameters [0].EvaluatedValue; if (param_1 is ArrayPointerExpression array_pointer) { return(new Result(new LongExpression(array_pointer.Array.GetAll().Count()))); } else { return(new Result(new LongExpression(0))); } }
public void return_same_function_when_requested_two_times() { var scope = new FunctionScope(); scope.Add("Foo", new FunctionReference(null, typeof (void))); // request for function "Foo()" FunctionReference function = scope["Foo"]; FunctionReference function1 = scope["Foo"]; Assert.AreSame(function, function1); }
public void return_function_implemented_if_added() { var scope = new FunctionScope(); var functionReference = new FunctionReference(null, typeof (void)); scope.Add("Foo", functionReference); FunctionReference function = scope["Foo"]; Assert.AreSame(functionReference, function); }
protected override Result _execute(ImmutableArray <EvaluatedParameter> parameters, FunctionScope function_scope) { if (parameters.Length != 1) { throw new WrongParameterCountException(this, expected: 1, actual: parameters.Length); } FinalExpression param_1 = parameters [0].EvaluatedValue; var possible_paths = IncludePathHelper.ResolveToFull(param_1.GetStringValue(), function_scope); Log.Debug($"check if path is a regular file: {possible_paths.Select (p => p.Original).Join (", ")}"); bool does_exist = possible_paths.Any(p => System.IO.File.Exists(p.Original)); return(new Result(new BoolExpression(does_exist))); }
private void OnEntityPropertyChanged(object sender, PropertyChangedEventArgs e) { ControlPropertyMetaDataPair pair; if (this.Properties.TryGetValue(e.PropertyName, out pair))//Entity Property' sine bağlı Control olmayabilir elbette. { IEntityControl ctrl = pair.Control; using (FunctionScope fsControl = new FunctionScope(this.RemoveControlValueChanged, ctrl, this.AddControlValueChanged, ctrl)) { ctrl.Value = pair.SchemaProperty.Property.GetValue(sender); } } }
protected override Result _execute(ImmutableArray <EvaluatedParameter> parameters, FunctionScope function_scope) { if (parameters.Length != 1 && parameters.Length != 2) { throw new WrongParameterCountException(this, expected: 1, actual: parameters.Length); } string path = parameters [0].EvaluatedValue.GetStringValue(); string mask = parameters.Length >= 2 ? parameters [1].EvaluatedValue.GetStringValue() : null; if (!string.IsNullOrEmpty(mask)) { path = path.TrimEnd(mask.ToCharArray()); } else { path = path.TrimEnd(); } return(new Result(new StringExpression(path))); }
protected override Result _execute(ImmutableArray <EvaluatedParameter> parameters, FunctionScope function_scope) { return(new Result(new StringExpression("xxx"))); }
protected override Result _execute(ImmutableArray <EvaluatedParameter> parameters, FunctionScope function_scope) { long ticks = DateTime.UtcNow.Ticks; long microseconds = ticks / (TimeSpan.TicksPerMillisecond / 1000); return(new Result(new LongExpression(microseconds))); }
private bool SetControlValueToEntity(IEntityControl ctrl) { PropertyMetaData schemaProperty = this.Properties[ctrl.PropertyName].SchemaProperty; PropertyInfo entityPi = schemaProperty.Property; if (entityPi.SetMethod != null) { SchemaInfo entitySchema = schemaProperty.Schema; using (FunctionScope fsEntity = new FunctionScope(this.RemoveEntityPropertyChanged, this.AddEntityPropertyChanged)) { using (FunctionScope fsControl = new FunctionScope(this.RemoveControlValueChanged, ctrl, this.AddControlValueChanged, ctrl)) { ctrl.RemoveErrorMessage(); object value = ctrl.Value; bool notNull = ctrl.Required || !entitySchema.IsNullable; ConvertResult convertResult = this.Converter.Convert(value, entityPi.PropertyType, !notNull); switch (convertResult.Result) { case ValidationResult.Valid: entityPi.SetValue(this.entity, convertResult.ConvertedValue); return true; case ValidationResult.ValidNull: entityPi.SetValue(this.entity, null); return true; case ValidationResult.Invalid: ctrl.ShowErrorMessage(StringResources.InvalidDataMessage); return false; case ValidationResult.InvalidNull: ctrl.ShowErrorMessage(StringResources.InvalidNullDataMessage); return false; } } } } return true; }
/// <nodoc /> public Expression ParseExpression(RuntimeModelContext runtimeModelContext, AbsolutePath path, string expression) { Contract.Requires(runtimeModelContext != null); Contract.Requires(expression != null); return(ParseExpression(runtimeModelContext, path, expression, localScope: FunctionScope.Empty(), useSemanticNameResolution: true)); }
//Entity Property Values To Controls public void DataBind() { foreach (KeyValuePair<string, ControlPropertyMetaDataPair> kvp in this.Properties) { PropertyInfo entityPi = kvp.Value.SchemaProperty.Property; IEntityControl ctrl = kvp.Value.Control; //Eklendi Çıkarılabilir. SelectById de remove etmiyordu. ctrl.RemoveErrorMessage(); // object entityValue = entityPi.GetValue(this.entity); using (FunctionScope fsControl = new FunctionScope(this.RemoveControlValueChanged, ctrl, this.AddControlValueChanged, ctrl)) { ctrl.Value = entityValue; } } }
/// <nodoc/> public Expression ParseExpression(RuntimeModelContext runtimeModelContext, AbsolutePath path, string spec, FunctionScope localScope, bool useSemanticNameResolution) { Contract.Requires(runtimeModelContext != null); Contract.Requires(spec != null); var parser = new TypeScript.Net.Parsing.Parser(); // Wrap expression in a function call to make the parser happy. // Currently an object literal '{...};' is not a valid statement. var sourceFile = parser.ParseSourceFileContent( path.ToString(runtimeModelContext.PathTable), @"function createExpression(a: any) {} createExpression(" + spec + ");"); if (sourceFile.ParseDiagnostics.Count != 0) { ReportParseDiagnosticsIfNeeded(runtimeModelContext, sourceFile, path); return(null); } var workspaceConfiguration = WorkspaceConfiguration.CreateForTesting(); var workspace = new Workspace( provider: null, workspaceConfiguration: workspaceConfiguration, modules: new[] { CreateModuleFor(runtimeModelContext, sourceFile) }, failures: Enumerable.Empty <Failure>(), preludeModule: null, configurationModule: null); workspace = SemanticWorkspaceProvider.ComputeSemanticWorkspace(runtimeModelContext.PathTable, workspace, workspaceConfiguration).GetAwaiter().GetResult(); // Because we just created source file to parse, we know exactly what the AST is there. // This information helped to simplify analysis logic and migrate to semantic-base name resolution. var invocation = sourceFile.Statements[1].Cast <IExpressionStatement>().Expression.Cast <ICallExpression>(); // Only for expressions, full names should be preserved. // Only for expressions, no checks for definition before use to avoid contract assertion in location computation. m_conversionConfiguration.UnsafeOptions.DisableDeclarationBeforeUseCheck = true; var converter = CreateAstConverter(sourceFile, runtimeModelContext, path, m_conversionConfiguration, workspace: workspace); return(converter.ConvertExpression(invocation, localScope, useSemanticNameResolution)); }
protected override Result _execute(ImmutableArray <EvaluatedParameter> parameters, FunctionScope function_scope) { if (parameters.Length != 1) { throw new WrongParameterCountException(this, expected: 1, actual: parameters.Length); } string path = parameters [0].EvaluatedValue.GetStringValue(); path = System.IO.Path.GetDirectoryName(path); return(new Result(new StringExpression(path))); }
protected override Result _execute(ImmutableArray <EvaluatedParameter> parameters, FunctionScope function_scope) { if (parameters.Length > 3) { throw new WrongParameterCountException(this, expected: 1, actual: parameters.Length); } FinalExpression param_1 = parameters [0].EvaluatedValue; var possible_paths = IncludePathHelper.ResolveToFull(param_1.GetStringValue(), function_scope); Log.Debug($"create directory: {possible_paths.Select (p => p.Original).Join (", ")}"); return(new Result(new BoolExpression(true))); }