private List <int> GetParamsCountList(NamedFunction namedFunction) { var result = new List <int>(); var argumentsList = namedFunction.Arguments; if (!argumentsList.Any()) { result.Add(0); return(result); } var totalCount = argumentsList.Count(); var argumentsWithoutDefaultValueCount = argumentsList.Count(p => !p.HasDefaultValue); if (totalCount == argumentsWithoutDefaultValueCount) { result.Add(totalCount); return(result); } for (var i = argumentsWithoutDefaultValueCount; i <= totalCount; i++) { result.Add(i); } return(result); }
protected NamedFunction CreateNamedFunction() { var result = new NamedFunction(); DefaultSettingsOfCodeEntityHelper.SetUpNamedFunction(result, CurrentDefaultSetings); return(result); }
private Dictionary <int, List <NamedFunction> > GetDictByParamsCount(NamedFunction namedFunction) { var holder = namedFunction.Holder; #if DEBUG //Log($"holder = {holder}"); #endif if (_namedFunctionsDict.ContainsKey(holder)) { var dict = _namedFunctionsDict[holder]; if (dict.ContainsKey(namedFunction.Name)) { return(dict[namedFunction.Name]); } { var targetDict = new Dictionary <int, List <NamedFunction> >(); dict[namedFunction.Name] = targetDict; return(targetDict); } } { var dict = new Dictionary <StrongIdentifierValue, Dictionary <int, List <NamedFunction> > >(); _namedFunctionsDict[holder] = dict; var targetDict = new Dictionary <int, List <NamedFunction> >(); dict[namedFunction.Name] = targetDict; return(targetDict); } }
public void GetNamedFunction(string latex, IList <Element> container, Marker marker) { var functionNames = new string[] { "sin", "cos", "tan", "arcsin", "arccos", "arctan", "sinh", "cosh", "tanh", "csc", "sec", "cot", "coth", "det", "exp", "ln", "log" }; for (var j = 0; j < functionNames.Length; j++) { var command = "\\" + functionNames[j]; var name = functionNames[j]; if (marker.Position <= latex.Length - command.Length) { if (latex.Substring(marker.Position, command.Length) == command) { var f = new NamedFunction(); f.Content = name; container.Add(f); marker.Position += command.Length; break; } } } }
private static int IndexOf(NamedFunction fn, NamedFunction[] fns) { for (int i = 0; i < fns.Length; i++) { if (fns[i] == fn) { return(i); } } return(-1); }
static DelegatingMethodHandle() { try { NF_getTarget = new NamedFunction(typeof(DelegatingMethodHandle).getDeclaredMethod("getTarget")); } catch (ReflectiveOperationException ex) { throw newInternalError(ex); } }
private List <uint> IsFit(NamedFunction function, List <Value> positionedParameters, LocalCodeExecutionContext localCodeExecutionContext, ResolverOptions options) { var inheritanceResolver = _context.DataResolversFactory.GetInheritanceResolver(); var positionedParametersEnumerator = positionedParameters.GetEnumerator(); var result = new List <uint>(); foreach (var argument in function.Arguments) { #if DEBUG //Log($"argument = {argument}"); #endif if (!positionedParametersEnumerator.MoveNext()) { if (argument.HasDefaultValue) { result.Add(0u); continue; } throw new NotImplementedException(); } var parameterItem = positionedParametersEnumerator.Current; #if DEBUG //Log($"parameterItem = {parameterItem}"); #endif var distance = inheritanceResolver.GetDistance(argument.TypesList, parameterItem, localCodeExecutionContext, options); #if DEBUG //Log($"distance = {distance}"); #endif if (!distance.HasValue) { return(null); } result.Add(distance.Value); } return(result); }
/// <inheritdoc/> protected override void OnEnter() { Result = CreateCodeEntity(); Result.Kind = KindOfCodeEntity.Function; _namedFunction = CreateNamedFunction(); _namedFunction.CodeEntity = Result; Result.NamedFunction = _namedFunction; Result.CodeFile = _context.CodeFile; Result.ParentCodeEntity = CurrentCodeEntity; SetCurrentCodeEntity(Result); if (Result.ParentCodeEntity != null) { _namedFunction.Holder = Result.ParentCodeEntity.Name; } }
static Lazy() { try { NamedFunction[] nfs = new NamedFunction[] { NF_internalMemberName = new NamedFunction(typeof(DirectMethodHandle).getDeclaredMethod("internalMemberName", typeof(Object))), NF_internalMemberNameEnsureInit = new NamedFunction(typeof(DirectMethodHandle).getDeclaredMethod("internalMemberNameEnsureInit", typeof(Object))), NF_ensureInitialized = new NamedFunction(typeof(DirectMethodHandle).getDeclaredMethod("ensureInitialized", typeof(Object))), NF_fieldOffset = new NamedFunction(typeof(DirectMethodHandle).getDeclaredMethod("fieldOffset", typeof(Object))), NF_checkBase = new NamedFunction(typeof(DirectMethodHandle).getDeclaredMethod("checkBase", typeof(Object))), NF_staticBase = new NamedFunction(typeof(DirectMethodHandle).getDeclaredMethod("staticBase", typeof(Object))), NF_staticOffset = new NamedFunction(typeof(DirectMethodHandle).getDeclaredMethod("staticOffset", typeof(Object))), NF_checkCast = new NamedFunction(typeof(DirectMethodHandle).getDeclaredMethod("checkCast", typeof(Object), typeof(Object))), NF_allocateInstance = new NamedFunction(typeof(DirectMethodHandle).getDeclaredMethod("allocateInstance", typeof(Object))), NF_constructorMethod = new NamedFunction(typeof(DirectMethodHandle).getDeclaredMethod("constructorMethod", typeof(Object))) }; foreach (NamedFunction nf in nfs) { // Each nf must be statically invocable or we get tied up in our bootstraps. assert(InvokerBytecodeGenerator.IsStaticallyInvocable(nf.member)) : nf; nf.resolve(); } } catch (ReflectiveOperationException ex) { throw newInternalError(ex); } }
/// <inheritdoc/> public void Append(NamedFunction namedFunction) { lock (_lockObj) { #if DEBUG //Log($"namedFunction = {namedFunction}"); #endif AnnotatedItemHelper.CheckAndFillUpHolder(namedFunction, _realStorageContext.MainStorageContext.CommonNamesStorage); namedFunction.CheckDirty(); var namedFunctionName = namedFunction.Name; var paramsCountList = GetParamsCountList(namedFunction); #if DEBUG //Log($"paramsCountList = {paramsCountList.WritePODListToString()}"); #endif var targetDict = GetDictByParamsCount(namedFunction); foreach (var count in paramsCountList) { List <NamedFunction> targetList = null; if (targetDict.ContainsKey(count)) { targetList = targetDict[count]; } else { targetList = new List <NamedFunction>(); targetDict[count] = targetList; } if (!targetList.Contains(namedFunction)) { targetList.Add(namedFunction); } } } }
/// Editing methods for lambda forms. // Each editing method can (potentially) cache the edited LF so that it can be reused later. internal virtual LambdaForm BindArgumentForm(int pos) { Transform key = Transform.Of(Transform.Kind.BIND_ARG, pos); LambdaForm form = GetInCache(key); if (form != null) { assert(form.ParameterConstraint(0) == NewSpeciesData(LambdaForm.ParameterType(pos))); return(form); } LambdaFormBuffer buf = Buffer(); buf.StartEdit(); BoundMethodHandle.SpeciesData oldData = OldSpeciesData(); BoundMethodHandle.SpeciesData newData = NewSpeciesData(LambdaForm.ParameterType(pos)); Name oldBaseAddress = LambdaForm.Parameter(0);// BMH holding the values Name newBaseAddress; NamedFunction getter = newData.GetterFunction(oldData.FieldCount()); if (pos != 0) { // The newly created LF will run with a different BMH. // Switch over any pre-existing BMH field references to the new BMH class. buf.ReplaceFunctions(oldData.GetterFunctions(), newData.GetterFunctions(), oldBaseAddress); newBaseAddress = oldBaseAddress.withConstraint(newData); buf.RenameParameter(0, newBaseAddress); buf.ReplaceParameterByNewExpression(pos, new Name(getter, newBaseAddress)); } else { // cannot bind the MH arg itself, unless oldData is empty assert(oldData == BoundMethodHandle.SpeciesData.EMPTY); newBaseAddress = (new Name(L_TYPE)).withConstraint(newData); buf.ReplaceParameterByNewExpression(0, new Name(getter, newBaseAddress)); buf.InsertParameter(0, newBaseAddress); } form = buf.EndEdit(); return(PutInCache(key, form)); }
private void CallStrongIdentifierValue(StrongIdentifierValue methodName, KindOfFunctionParameters kindOfParameters, Dictionary <StrongIdentifierValue, Value> namedParameters, List <Value> positionedParameters, bool isSync) { #if DEBUG //Log($"methodName = {methodName}"); //Log($"kindOfParameters = {kindOfParameters}"); //Log($"namedParameters = {namedParameters.WriteDict_1_ToString()}"); //Log($"positionedParameters = {positionedParameters.WriteListToString()}"); //Log($"isSync = {isSync}"); #endif NamedFunction method = null; switch (kindOfParameters) { case KindOfFunctionParameters.NoParameters: method = _methodsResolver.Resolve(methodName, _currentCodeFrame.LocalContext); break; case KindOfFunctionParameters.NamedParameters: method = _methodsResolver.Resolve(methodName, namedParameters, _currentCodeFrame.LocalContext); break; case KindOfFunctionParameters.PositionedParameters: method = _methodsResolver.Resolve(methodName, positionedParameters, _currentCodeFrame.LocalContext); break; default: throw new ArgumentOutOfRangeException(nameof(kindOfParameters), kindOfParameters, null); } #if DEBUG //Log($"method = {method}"); #endif CallExecutable(method, kindOfParameters, namedParameters, positionedParameters, isSync); }
public SourceVariableNodesRowset(VariableName variableName, NamedFunction functionCall, RowsetAlias rowsetAlias): base(functionCall, rowsetAlias) { this.variableName = variableName; }
// [Rule("<SourceRowset> ::= <SchemaName> ~'.' <TableName> ~'.' <ColumnName> ~'.' <FunctionCall> <RowsetAlias>")] // public SourceTableColumnNodesRowset(SchemaName schemaName, TableName tableName, ColumnName columnName, ExpressionFunctionCall functionCall, RowsetAlias rowsetAlias): this(new Qualified<SchemaName, TableName>(schemaName, tableName), columnName, functionCall, rowsetAlias) {} private SourceTableColumnNodesRowset(Qualified<SchemaName, TableName> tableNameQualified, ColumnName columnName, NamedFunction functionCall, RowsetAlias rowsetAlias): base(functionCall, rowsetAlias) { Debug.Assert(tableNameQualified != null); Debug.Assert(columnName != null); this.tableNameQualified = tableNameQualified; this.columnName = columnName; }
public SourceTableColumnNodesRowset(SchemaName tableName, TableName columnName, NamedFunction functionCall, RowsetAlias rowsetAlias): this(new Qualified<SchemaName, TableName>(null, new TableName(tableName.Value)), new ColumnName(columnName.Value), functionCall, rowsetAlias) { tableNameQualified.LockOverride(); // TableName here is usually an alias to a table, so don't prefix this }
public SourceFunctionRowset(NamedFunction function, RowsetAlias rowsetAlias): base(rowsetAlias) { Debug.Assert(function != null); this.function = function; }
public SourceFunctionRowset(SchemaName schemaName, NamedFunction function, RowsetAlias rowsetAlias): this(function.QualifiedWith(schemaName), rowsetAlias) {}
internal static LambdaForm MakeReinvokerForm(MethodHandle target, int whichCache, Object constraint, NamedFunction getTargetFn) { String debugString; switch (whichCache) { case MethodTypeForm.LF_REBIND: debugString = "BMH.reinvoke"; break; case MethodTypeForm.LF_DELEGATE: debugString = "MH.delegate"; break; default: debugString = "MH.reinvoke"; break; } // No pre-action needed. return(MakeReinvokerForm(target, whichCache, constraint, debugString, true, getTargetFn, null)); }
public static void SetUpNamedFunction(NamedFunction namedFunction, DefaultSettingsOfCodeEntity defaultSettings) { var context = new Dictionary <object, object>(); SetUpAnnotatedItem(namedFunction, defaultSettings, context); }
/// <summary> /// Create a LF which simply reinvokes a target of the given basic type. </summary> internal static LambdaForm MakeReinvokerForm(MethodHandle target, int whichCache, Object constraint, String debugString, bool forceInline, NamedFunction getTargetFn, NamedFunction preActionFn) { MethodType mtype = target.Type().BasicType(); bool customized = (whichCache <0 || mtype.ParameterSlotCount()> MethodType.MAX_MH_INVOKER_ARITY); bool hasPreAction = (preActionFn != null); LambdaForm form; if (!customized) { form = mtype.Form().CachedLambdaForm(whichCache); if (form != null) { return(form); } } const int THIS_DMH = 0; const int ARG_BASE = 1; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int ARG_LIMIT = ARG_BASE + mtype.parameterCount(); int ARG_LIMIT = ARG_BASE + mtype.ParameterCount(); int nameCursor = ARG_LIMIT; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int PRE_ACTION = hasPreAction ? nameCursor++ : -1; int PRE_ACTION = hasPreAction ? nameCursor++: -1; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int NEXT_MH = customized ? -1 : nameCursor++; int NEXT_MH = customized ? -1 : nameCursor++; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int REINVOKE = nameCursor++; int REINVOKE = nameCursor++; LambdaForm.Name[] names = LambdaForm.Arguments(nameCursor - ARG_LIMIT, mtype.InvokerType()); assert(names.Length == nameCursor); names[THIS_DMH] = names[THIS_DMH].WithConstraint(constraint); Object[] targetArgs; if (hasPreAction) { names[PRE_ACTION] = new LambdaForm.Name(preActionFn, names[THIS_DMH]); } if (customized) { targetArgs = Arrays.CopyOfRange(names, ARG_BASE, ARG_LIMIT, typeof(Object[])); names[REINVOKE] = new LambdaForm.Name(target, targetArgs); // the invoker is the target itself } else { names[NEXT_MH] = new LambdaForm.Name(getTargetFn, names[THIS_DMH]); targetArgs = Arrays.CopyOfRange(names, THIS_DMH, ARG_LIMIT, typeof(Object[])); targetArgs[0] = names[NEXT_MH]; // overwrite this MH with next MH names[REINVOKE] = new LambdaForm.Name(mtype, targetArgs); } form = new LambdaForm(debugString, ARG_LIMIT, names, forceInline); if (!customized) { form = mtype.Form().SetCachedLambdaForm(whichCache, form); } return(form); }
public SourceTableVariableNodesRowset(VariableName tableName, ColumnName columnName, NamedFunction functionCall, RowsetAlias rowsetAlias): base(functionCall, rowsetAlias) { Debug.Assert(tableName != null); Debug.Assert(columnName != null); this.tableName = tableName; this.columnName = columnName; }
private List <uint> IsFit(NamedFunction function, Dictionary <StrongIdentifierValue, Value> namedParameters, LocalCodeExecutionContext localCodeExecutionContext, ResolverOptions options) { #if DEBUG //Log($"namedParameters = {namedParameters.WriteDict_1_ToString()}"); #endif var inheritanceResolver = _context.DataResolversFactory.GetInheritanceResolver(); var result = new List <uint>(); var countOfUsedParameters = 0; foreach (var argument in function.Arguments) { #if DEBUG //Log($"argument = {argument}"); #endif var argumentName = argument.Name; if (namedParameters.ContainsKey(argumentName)) { countOfUsedParameters++; var parameterValue = namedParameters[argumentName]; #if DEBUG //Log($"parameterValue = {parameterValue}"); #endif var distance = inheritanceResolver.GetDistance(argument.TypesList, parameterValue, localCodeExecutionContext, options); #if DEBUG //Log($"distance = {distance}"); #endif if (!distance.HasValue) { return(null); } result.Add(distance.Value); } else { if (argument.HasDefaultValue) { result.Add(0u); continue; } else { return(null); } } } #if DEBUG //Log($"countOfUsedParameters = {countOfUsedParameters}"); //Log($"namedParameters.Count = {namedParameters.Count}"); #endif if (countOfUsedParameters < namedParameters.Count) { return(null); } return(result); }
protected SourceNodesRowset(NamedFunction functionCall, RowsetAlias rowsetAlias): base(rowsetAlias) { Debug.Assert(functionCall != null); functionCall.FunctionName.LockOverride(); this.functionCall = functionCall; }