private static object[][] createArrays(object[] types, int[] ranks, int rank) { int length = types.Length; // bool b = false; foreach (object t in types) { if (t is ArrayReturnType) { ArrayReturnType rt = t as ArrayReturnType; length = rt.Dimension[0]; //b = true; break; } } object[][] o = new object[length][]; if (rank == 1) { for (int i = 0; i < o.Length; i++) { object[] ob = new object[types.Length]; o[i] = ob; for (int j = 0; j < types.Length; j++) { object tt = ArrayReturnType.GetBaseType(types[j]); ob[j] = tt; } } return(o); } return(null); }
/// <summary> /// Get string type of object /// </summary> /// <param name="o">Object</param> /// <returns>The string type</returns> public string GetType(object o) { if (o is ArrayReturnType) { ArrayReturnType t = o as ArrayReturnType; string st = "object"; if (!t.IsObjectType) { st = GetType(t.ElementType); } st += "["; int[] n = t.Dimension; for (int i = 0; i < n.Length - 1; i++) { st += ','; } st += ']'; return(st); } Type type = o.GetType(); if (dictionary.ContainsKey(type)) { return(dictionary[type]); } if (o is Type) { Type t = o as Type; return(t.FullName); } return("object"); }
IObjectOperation IBinaryAcceptor.Accept(object typeA, object typeB) { object[] t = new object[] { typeA, typeB }; ArrayReturnType[] ats = new ArrayReturnType[2]; for (int i = 0; i < t.Length; i++) { object ty = t[i]; if (!(ty is ArrayReturnType)) { return(null); } ArrayReturnType at = ty as ArrayReturnType; if (at.IsObjectType) { return(null); } if (!at.ElementType.Equals(a)) { return(null); } if (at.Dimension.Length != 2) { return(null); } ats[i] = at; } if (ats[0].Dimension[0] != ats[1].Dimension[0] | ats[0].Dimension[1] != ats[1].Dimension[1]) { return(null); } int[] dim = ats[0].Dimension; return(CreateOpreation(dim[0], dim[1])); }
ObjectFormulaTree IChildTreeCreator.this[ObjectFormulaTree[] children] { get { if (children.Length != 2) { return(null); } ArrayReturnType[] types = new ArrayReturnType[2]; for (int i = 0; i < 2; i++) { object t = children[i].ReturnType; if (t is ArrayReturnType) { ArrayReturnType art = t as ArrayReturnType; int[] d = art.Dimension; if (d.Length == 1) { if (d[0] == -1) { types[i] = art; } } continue; } return(null); } if (types[1].ElementType.Equals(false)) { return(Create(children)); } return(null); } }
IObjectOperation IBinaryAcceptor.Accept(object typeA, object typeB) { if (!(typeA is ArrayReturnType & typeB is ArrayReturnType)) { return(null); } ArrayReturnType ta = typeA as ArrayReturnType; ArrayReturnType tb = typeB as ArrayReturnType; if (ta.IsObjectType | tb.IsObjectType) { return(null); } if (!ta.ElementType.Equals(a) | !tb.ElementType.Equals(a)) { return(null); } if (ta.Dimension.Length != 1 | tb.Dimension.Length != 1) { return(null); } if (ta.Dimension[0] != tb.Dimension[0]) { return(null); } return(new Vector3DProduct()); }
private object[] GetFieldValue(IPhysicalField field) { if (fieldValue.ContainsKey(field)) { return(fieldValue[field]); } object[] o = new object[field.Count]; for (int i = 0; i < o.Length; i++) { object type = field.GetType(i); if (type.GetType().Equals(typeof(double))) { double a = 0; o[i] = a; continue; } if (type is ArrayReturnType) { ArrayReturnType art = type as ArrayReturnType; o[i] = new double[art.Dimension[0]]; } fieldValue[field] = o; } return(o); }
/// <summary> /// Accepts operation /// </summary> /// <param name="type">Argument type</param> /// <returns>The operation</returns> public IObjectOperation Accept(object type) { IObjectOperation ownOp = acceptor.Accept(type); if (ownOp != null) { return(ownOp); } if (type is ArrayReturnType) { ArrayReturnType a = type as ArrayReturnType; if (a.IsObjectType) { op = acceptor.Accept(a) as IMultiVariableOperation; if (op == null) { return(null); } types = new object[] { type }; ArrayOperation.CreateAllArrays(op, types, out y, out yy, out rank, out ranks); returnType = new ArrayReturnType(op.ReturnType, rank, true); return(this); } } return(null); }
/// <summary> /// Constructor /// </summary> /// <param name="array">Measure dtata</param> /// <param name="name">Measure name</param> public ConstDoubleArrayMeasure(double[] array, string name) { this.array = array; this.name = name; type = new ArrayReturnType(FixedTypes.Double, new int[] { array.Length }, false); par = getPar; }
ObjectFormulaTree IChildTreeCreator.this[ObjectFormulaTree[] children] { get { if (children.Length != 2) { return(null); } ArrayReturnType[] types = new ArrayReturnType[2]; for (int i = 0; i < 2; i++) { object t = children[i].ReturnType; if (t is ArrayReturnType) { ArrayReturnType art = t as ArrayReturnType; int[] d = art.Dimension; if (d.Length == 1) { if (d[0] == -1) { types[i] = art; } } continue; } return(null); } object et = types[1].ElementType; if (et.Equals((float)0))//!!! return when VariableDouble is made if (et is double | et is float) { return(Create(children)); } return(null); } }
/// <summary> /// Construtor /// </summary> /// <param name="collection">Collection</param> protected AbstractDoubleTransformer(IObjectCollection collection) { runtime = StaticExtensionDataPerformerPortable.Factory.Create(collection, 0); this.collection = collection; SetEvents(); type = new ArrayReturnType(a, new int[] { 1 }, true); }
/// <summary> /// Prepares itself /// </summary> protected virtual void Prepare() { runtime = StaticExtensionDataPerformerPortable.Factory.Create(collection, 0); List <string[]> l = collection.GetDoubleVariables(); type = new ArrayReturnType(a, new int[] { l.Count }, false); outbuffer = new double[l.Count]; }
internal DynamicalArrayBinaryLeftOperation(object typeA, object typeB, IObjectOperation op) { types = new object[] { typeA, typeB }; ArrayReturnType art = typeA as ArrayReturnType; type = new ArrayReturnType(op.ReturnType, art.Dimension, art.IsObjectType); this.op = op; }
internal RealMatrixPower(int dim) { this.dim = dim; type = new ArrayReturnType(a, new int[] { dim, dim }, false); buffer = new double[dim, dim]; result = new double[dim, dim]; mult = new double[dim, dim]; }
internal ScalarVectorProduct(int dimension) { if (dimension < 0) { return; } type = new ArrayReturnType(a, new int[] { dimension }, false); result = new double[dimension]; }
/// <summary> /// Get type of array element /// </summary> /// <param name="type"></param> /// <returns></returns> public override object GetBaseType(object type) { if (type is ArrayReturnType) { ArrayReturnType at = type as ArrayReturnType; return(at.ElementType); } return(base.GetBaseType(type)); }
/// <summary> /// Gets dimension of type /// </summary> /// <param name="type">The type</param> /// <returns>The dimension</returns> public override int[] GetDimension(object type) { if (type is ArrayReturnType) { ArrayReturnType at = type as ArrayReturnType; return(at.Dimension); } return(base.GetDimension(type)); }
/// <summary> /// Gets all measurements of one dimension real array /// </summary> /// <param name="ao">Associated object</param> /// <returns>Names of measurements</returns> public static string[] GetOneDimensionRealArrays(this IAssociatedObject ao) { INamedComponent nc = null; if (ao is INamedComponent) { nc = ao as INamedComponent; } else { nc = ao.Object as INamedComponent; } IDesktop desktop = nc.Root.Desktop; if (desktop == null) { desktop = nc.Desktop; } if (desktop == null) { return(new string[0]); } List <string> l = new List <string>(); desktop.ForEach <IMeasurements>((IMeasurements m) => { IAssociatedObject aob = m as IAssociatedObject; INamedComponent ncm = aob.Object as INamedComponent; string nm = ncm.GetName(desktop); for (int i = 0; i < m.Count; i++) { IMeasurement mea = m[i]; if (mea == null) { continue; } object t = mea.Type; if (!(t is ArrayReturnType)) { continue; } ArrayReturnType art = t as ArrayReturnType; Double a = 0; if (!art.ElementType.Equals(a)) { continue; } if (art.Dimension.Length != 1) { continue; } l.Add(nm + "." + mea.Name); } }); return(l.ToArray()); }
/// <summary> /// Accepts operation /// </summary> /// <param name="type">Return type</param> /// <returns>The operation</returns> public IObjectOperation Accept(object type) { if (!(type is ArrayReturnType)) { return(null); } object t = ArrayReturnType.GetBaseType(type); return(new ArraySingleOperation(operationType, type)); }
private int GetLength(object type) { if (!(type is ArrayReturnType)) { return(0); } ArrayReturnType art = type as ArrayReturnType; return(art.Dimension.Length); }
/// <summary> /// Constructor /// </summary> /// <param name="type">The type</param> protected ArrayDisassemblyObject(ArrayReturnType type) { this.type = type; object o = type.ElementType; int[] dim = type.Dimension; for (int i = 0; i < dim[0]; i++) { types.Add(new Tuple <string, object>((i + 1) + "", o)); } }
static IReturnType WrapArray(IProjectContent pc, IReturnType t, TypeReference reference) { if (reference.IsArrayType) { for (int i = reference.RankSpecifier.Length - 1; i >= 0; --i) { t = new ArrayReturnType(pc, t, reference.RankSpecifier[i] + 1); } } return(t); }
internal Variable(IObjectOperation variable, ObjectFormulaTree[] children) { this.variable = variable; this.children = children; type = children[0].ReturnType; types = new object[] { type }; ArrayReturnType art = children[0].ReturnType as ArrayReturnType; retType = art.ElementType; tree = Convert(children[1]); }
/// <summary> /// Constructor /// </summary> /// <param name="operationType">Operation type</param> /// <param name="type">Type of return</param> public ArraySingleOperation(ArraySingleOperationType operationType, object type) { this.operationType = operationType; ArrayReturnType art = type as ArrayReturnType; object t = art.ElementType; if (t is Double) { Double a = 0; returnType = a; } }
/// <summary> /// The "is dynamical array detection" /// </summary> /// <param name="type">Type</param> /// <returns>True if type is dynamical array</returns> static public bool IsDynamicalArray(this object type) { if (type is ArrayReturnType) { ArrayReturnType t = type as ArrayReturnType; if (t.Dimension.Length == 1) { return(t.Dimension[0] == -1); } } return(false); }
private IObjectOperation GetDynamicalOperation(ArrayReturnType type, IObjectOperation operation) { if (type.IsDynamicalArray()) { IObjectOperation op = StaticExtensionFormulaEditor.GetUnaryParallel(type, operation); if (op != null) { return(op); } return(new DynamicalArrayUnaryOperation(type, operation)); } return(null); }
private void CreateMesurements(IPhysicalField field) { string name = this.GetRelativeName(field as IAssociatedObject) + "_"; name = name.Replace(".", "_"); name = name.Replace("/", "_"); int n = field.Count; IList <IMeasurement> lm = new List <IMeasurement>(); IList <ProcessField> pr = new List <ProcessField>(); IList <object> lo = new List <object>(); dic[field] = lm; proc[field] = pr; results[field] = lo; IMeasurement mea = null; measures.Clear(); for (int i = 0; i < n; i++) { object result = null; ProcessField pf = null; string na = name + (i + 1); object type = field.GetType(i); object tt = field.GetTransformationType(i); if (type is ArrayReturnType) { if (tt.Equals(Field3D_Types.CovariantVector)) { pf = ProcessCovariantVector; } else { pf = ProcessInvariantVector; } ArrayReturnType art = type as ArrayReturnType; int dim = art.Dimension[0]; result = new double[dim]; mea = new FieldMeasurement(na, type, result); } else { pf = ProcessSimpleType; result = new object[1]; mea = new FieldMeasurementElement(na, type, result as object[]); } lm.Add(mea); pr.Add(pf); lo.Add(result); measures.Add(mea); } }
private void Post() { if (names == null) { return; } measures = new IMeasurement[names.Length]; for (int i = 0; i < names.GetLength(0); i++) { measures[i] = this.FindMeasurement(names[i], false); } val = new double[measures.Length]; type = new ArrayReturnType(a, new int[] { measures.Length }, false); }
protected override void FixGeneratedCode(IClass formClass, CodeMemberMethod code) { base.FixGeneratedCode(formClass, code); Dictionary <string, IReturnType> variables = new Dictionary <string, IReturnType>(); foreach (IField f in formClass.DefaultReturnType.GetFields()) { variables[f.Name] = f.ReturnType; } variables[""] = formClass.DefaultReturnType; foreach (CodeStatement statement in code.Statements) { CodeExpressionStatement ces = statement as CodeExpressionStatement; if (ces != null) { CodeMethodInvokeExpression cmie = ces.Expression as CodeMethodInvokeExpression; if (cmie != null && cmie.Parameters.Count == 1) { CodeArrayCreateExpression cace = cmie.Parameters[0] as CodeArrayCreateExpression; if (cace != null) { IReturnType rt = ResolveType(cmie.Method.TargetObject, variables); if (rt != null) { foreach (IMethod m in rt.GetMethods()) { if (m.Name == cmie.Method.MethodName && m.Parameters.Count == 1 && m.Parameters[0].IsParams && m.Parameters[0].ReturnType.IsArrayReturnType) { ArrayReturnType paramArt = m.Parameters[0].ReturnType.CastToArrayReturnType(); if (paramArt.ArrayDimensions == 1 && paramArt.FullyQualifiedName == cace.CreateType.BaseType) { cace.UserData["Explode"] = true; } } } } } } } CodeVariableDeclarationStatement cvds = statement as CodeVariableDeclarationStatement; if (cvds != null) { variables[cvds.Name] = new SearchClassReturnType(formClass.ProjectContent, formClass, formClass.Region.BeginLine + 1, 0, cvds.Type.BaseType, cvds.Type.TypeArguments.Count); } } }
/// <summary> /// Creates code from tree /// </summary> /// <param name="tree">The tree</param> /// <param name="ret">Return identifier</param> /// <param name="parameters">Parameters of tree</param> /// <param name="variables">Variables of tree</param> /// <param name="initializers">Initializers</param> /// <returns>List of code strings</returns> protected IList <string> CreateArrayCode(ObjectFormulaTree tree, string ret, string[] parameters, out IList <string> variables, out IList <string> initializers) { List <string> vari = new List <string>(); List <string> init = new List <string>(); variables = vari; initializers = init; IObjectOperation op = tree.Operation; if (!(op is ArrayOperation)) { return(null); } ArrayOperation ao = op as ArrayOperation; object[] types = ao.Types; string[] par = new string[parameters.Length]; for (int i = 0; i < par.Length; i++) { par[i] = GetModifier(types[i]) + parameters[i]; } ArrayReturnType art = ao.ReturnType as ArrayReturnType; List <ObjectFormulaTree> ch = new List <ObjectFormulaTree>(); for (int i = 0; i < tree.Count; i++) { if (tree[i] != null) { ch.Add(tree[i]); } } ObjectFormulaTree t = new ObjectFormulaTree(ao.SingleOperation, ch); List <string> list = new List <string>(); bool success; if (cycle) { ProcessCycleArrayCode(0, tree, t, ret + "[", par, parameters, types, art, list, vari, init, out success); } else { ProcessArrayCode(0, tree, t, ret + "[", par, types, art, list, vari, init, out success); } if (!success) { return(null); } return(list); }
private string GetModifier(object type) { string s = ""; if (type is ArrayReturnType) { ArrayReturnType art = type as ArrayReturnType; if (art.IsObjectType) { s = "(" + typeCreator.GetType(art.ElementType) + ")"; } } return(s); }
public override object VisitFieldDeclaration(AST.FieldDeclaration fieldDeclaration, object data) { DomRegion region = GetRegion(fieldDeclaration.StartLocation, fieldDeclaration.EndLocation); DefaultClass c = GetCurrentClass(); ModifierEnum modifier = ConvertModifier(fieldDeclaration.Modifier, (c.ClassType == ClassType.Struct && this.IsVisualBasic) ? ModifierEnum.Public : ModifierEnum.Private); string doku = GetDocumentation(region.BeginLine, fieldDeclaration.Attributes); if (currentClass.Count > 0) { for (int i = 0; i < fieldDeclaration.Fields.Count; ++i) { AST.VariableDeclaration field = (AST.VariableDeclaration)fieldDeclaration.Fields[i]; IReturnType retType; if (c.ClassType == ClassType.Enum) { retType = c.DefaultReturnType; } else { retType = CreateReturnType(fieldDeclaration.GetTypeForField(i)); if (!field.FixedArrayInitialization.IsNull) retType = new ArrayReturnType(cu.ProjectContent, retType, 1); } DefaultField f = new DefaultField(retType, field.Name, modifier, region, c); ConvertAttributes(fieldDeclaration, f); f.Documentation = doku; if (c.ClassType == ClassType.Enum) { f.Modifiers = ModifierEnum.Const | ModifierEnum.Public; } c.Fields.Add(f); } } return null; }
static IReturnType WrapArray(IProjectContent pc, IReturnType t, TypeReference reference) { if (reference.IsArrayType) { for (int i = reference.RankSpecifier.Length - 1; i >= 0; --i) { int dimensions = reference.RankSpecifier[i] + 1; if (dimensions > 0) { t = new ArrayReturnType(pc, t, dimensions); } } } return t; }