public static void Main(string[] args) { byte[] byteArray = new byte[] { 10, 12, 14 }; AField sf = new AField(0, 0, ref byteArray); Console.WriteLine(sf); }
private Record TableFieldArrayToRecord(IParcelable[] recData) { int size = recData.Length; Record rec = new Record(); AField[] aFieldArr = new AField[size]; for (int i = 0; i < size; i++) { AField aF = new AField(); aF.setFieldData(((TableField)recData[i]).getValue()); aFieldArr[i] = aF; } rec.setFields(aFieldArr); return(rec); }
public static void Main (string[] args) { byte[] byteArray = new byte[] { 10, 12, 14 }; AField sf = new AField(0, 0, ref byteArray); Console.WriteLine(sf); }
// It has a bug since it doesn't compute some paths until the root (i.e. the variable) public Set<VariableEffect> EffectsInVariables2(AField af) { Set<VariableEffect> variableEffects = new Set<VariableEffect>(); // Get the fields that are backward reachable from the modified field Set<List<Edge>> paths = PointsToGraph.DFSPathFrom(af.Src, false, true, true); //IEnumerable<IEnumerable<Edge>> paths2 = PointsToGraph.DFSPath(af.Src, false, true, true); foreach (List<Edge> currentPath in paths) { currentPath.Reverse(); IPTAnalysisNode rootNode; //foreach (Edge e in currentPath) // Console.Out.Write("{0} ", e); //Console.Out.WriteLine(); if (currentPath.Count > 0) rootNode = currentPath[0].Src; else rootNode = af.Src; // we ignore newly allocated objetcs if (rootNode.IsInside) continue; Variable v = null; if (rootNode.IsVariableReference) { IVarRefNode vrNode = rootNode as IVarRefNode; v = vrNode.ReferencedVariable; if (!(v is Parameter) && !v.Equals(PTGraph.GlobalScope)) continue; } if (rootNode.Equals(GNode.nGBL)) { v = PTGraph.GlobalScope; } if (rootNode.IsParameterNode && ((PNode)rootNode).IsByValue) { bool fieldUpdate = !af.Field.Equals(PTGraph.asterisk); foreach (Edge e in currentPath) { if (fieldUpdate) break; fieldUpdate = fieldUpdate || !e.Field.Equals(PTGraph.asterisk); } if (!fieldUpdate) continue; } string nodeName = rootNode.Name; if (af.Field.IsStatic) nodeName = af.Field.DeclaringType.Name.Name; if (v != null) { VariableEffect vEffect = ComputeOneEffectPath(af, currentPath, v); variableEffects.Add(vEffect); } } return variableEffects; }
public abstract string fieldToTypeStr(AField fieldstruct);
/// <summary> /// Computes the effect ogf "af" over the parameters and globals /// DIEGO-TODO: I need to improve this part since it is very slow and repeitive /// </summary> /// <param name="af"></param> /// <returns></returns> public Set<VariableEffect> EffectsInVariables(AField af) { Set<VariableEffect> variableEffects = new Set<VariableEffect>(); // Builds a sort of tree with all nodes backward reacheacle from the node IPTAnalysisNode affectectNode = af.Src; Edges tree = this.pointsToGraph.EdgesReachableFrom(affectectNode, null, false, true, true); foreach (Parameter p in this.Parameters) { CheckAndAddEffect(af, variableEffects, tree, p); } CheckAndAddEffect(af, variableEffects, tree, PTGraph.GlobalScope); return variableEffects; }
/// <summary> /// Add all the effects of "af" over the given variable /// </summary> /// <param name="af"></param> /// <param name="variableEffects"></param> /// <param name="tree"></param> /// <param name="p"></param> private void CheckAndAddEffect(AField af, Set<VariableEffect> variableEffects, Edges tree, Variable p) { IPTAnalysisNode from = this.Address(p); // Compute all paths from the variable to the affected node // DIEGO-TODO: this is terribly slow. I have to make it much more faster. IEnumerable<IEnumerable<Edge>> paths = PointsToGraph.DFSPathFromTo(from, af.Src, tree); foreach (List<Edge> currentPath in paths) { IPTAnalysisNode rootNode = null; if (currentPath.Count > 0) rootNode = currentPath[0].Src; else rootNode = af.Src; if (rootNode.IsVariableReference) { IVarRefNode vrNode = rootNode as IVarRefNode; Variable v = vrNode.ReferencedVariable; if (v != null) { VariableEffect vEffect = ComputeOneEffectPath(af, currentPath, v); variableEffects.Add(vEffect); } } } }
public void AddEffect(IPTAnalysisNode n, Field f, Label lb,bool wasNull) { AField af = new AField(n, f, lb,wasNull); AddWriteEffect(af); }
/// <summary> /// This method is called when at the end of method dataflow analysis. /// We add an special treatment from methods that created closures. /// If an effect is over a field that corresponds to a variable of the enclosing /// method we add the effect also in the enclosing method. /// DIEGO-TODO: EffectsInVariables is VERY SLOW. Try to improve it /// </summary> /// <param name="m"></param> protected override void ComputeAfterDataflow(Method m) { // OJO!: I should also record read effects if (exitState != null) { PointsToAndWriteEffects ptwe = (PointsToAndWriteEffects)exitState; // If it is a closure method... if (PointsToAnalysis.IsCompilerGenerated(m)) { // Get enclosing method PointsToAndWriteEffects enclosingState = (PointsToAndWriteEffects)this.pointsToStateAnalysys.EnclosingState(m.DeclaringType); if (enclosingState != null) { // For each write effect foreach (AField af in ptwe.WriteEffects) { // Get the associated write effect in proram variables Set<VariableEffect> writeEffectsInVariables = ptwe.EffectsInVariables(af); foreach (VariableEffect vEffect in writeEffectsInVariables) { // If the effect is over a this.field (this.f.g => |vEffec|>=2) // Or directly this.? (meaning all reacheacle) if (m.ThisParameter != null && vEffect.Variable.Equals(m.ThisParameter) && vEffect.FieldChain.Count >= 2 || (vEffect.FieldChain.Count >= 1 && vEffect.FieldChain[0].Equals(PTGraph.allFields))) { // Get the field to see if it is actually a variable in the enclosing method Field f = vEffect.FieldChain[0]; Variable enclosingMethodVar = enclosingState.GetVariableByName(f.Name.Name); if (enclosingMethodVar != null) { // Set the write effect in the enclosing method foreach (IPTAnalysisNode n in enclosingState.Values(enclosingMethodVar)) { Label lb = enclosingState.MethodLabel; lb.Statement.SourceContext = enclosingState.Method.SourceContext; AField newEffect = new AField(n, vEffect.FieldChain[1], af.Label); enclosingState.WriteEffects.AddWriteEffect(newEffect); enclosingState.allWriteEffects.AddWriteEffect(newEffect); } } } } } } } } isPure = this.VerifyPurity(); base.ComputeAfterDataflow(m); }
public void AddWriteEffect(AField af) { modifies.Add(af); }
private static IPTAnalysisNode getSrc(AField a) { return a.Src; }
/// <summary> /// Compute one Effects using one path from a variable an effect in /// an abstract heap location /// </summary> /// <param name="af"></param> /// <param name="currentPath"></param> /// <param name="v"></param> /// <returns></returns> private static VariableEffect ComputeOneEffectPath(AField af, List<Edge> currentPath, Variable v) { if (WeakPurityAndWriteEffectsAnalysis.debug) { if (v == null) System.Diagnostics.Debugger.Break(); } VariableEffect vEffect = new VariableEffect(v, af.Label); foreach (Edge e in currentPath) { if (!e.Field.Equals(PTGraph.asterisk)) { vEffect.AddField(e.Field); // lastField = e.Field; // DIEGO-CHECK: If I have an effect on a omega node i can reach all nodes if (e.Src.IsOmega && (e.Field.Equals(PTGraph.allFields) || e.Field.Equals(PTGraph.allFieldsNotOwned))) break; } } if (!af.Field.Equals(PTGraph.asterisk) || vEffect.FieldChain.Count == 0) vEffect.AddField(af.Field,af.WasNull); return vEffect; }
/// <summary> /// Retrieve data for table viewer /// </summary> /// <param name="cont">The cont.Context on which to display errors</param> /// <param name="table">table Name of table</param> /// <param name="where">The where.Where clause for filter</param> /// <param name="order">The order.Order if data sorted (by clicking on title)</param> /// <param name="offset">The offset.Offset if paging</param> /// <param name="limit">limit Page size</param> /// <param name="view">indication of view (with out on update trigger) </param> /// <param name="fieldNames">The field names.</param> /// <returns>a list of Records</returns> public Record[] getTableDataWithWhere(Context cont, string table, string where, string order, int offset, int limit, bool view, string[] fieldNames) { string sql = ""; if (view) { sql = "Select "; } else { sql = "Select typeof(rowid), rowid As rowid, "; } if (where.Trim().Equals("")) { where = ""; } else { where = " Where " + where + " "; } //String[] fieldNames = getFieldsNames(table); for (int i = 0; i < fieldNames.Length; i++) { sql += "typeof([" + fieldNames[i] + "]), [" + fieldNames[i] + "]"; if (i < fieldNames.Length - 1) { sql += ", "; } } sql += " From [" + table + "] " + where + order + " limit " + limit + " offset " + offset; //Record[] recs = null; Stack <Record> recs = new Stack <Record>(); using (SqliteDataReader cursor = ExecuteReader(sql)) { int columns = cursor.FieldCount / 2; //Utils.logD("Columns: " + columns, logging); //int rows = cursor.Depth; //Utils.logD("Rows = " + rows, logging); //recs = new Record[rows]; //int i = 0; while (cursor.Read()) { //recs[i] = new Record(); recs.Push(new Record()); AField[] fields = new AField[columns]; for (int j = 0; j < columns; j++) { AField fld = new AField(); //Get the field type due to SQLites flexible handling of field types the type from //the table definition can't be used try { string fldType = cursor.GetString(j * 2); //TODO still problems here with BLOB fields!?!?!?! fld.setFieldType(getFieldType(fldType)); } catch (Exception) { fld.setFieldType(AField.FieldType.UNRESOLVED); } if (fld.getFieldType() == AField.FieldType.NULL) { fld.setFieldData(""); } else if (fld.getFieldType() == AField.FieldType.UNRESOLVED) { fld.setFieldData("Unknown field"); } else { fld.setFieldData(cursor.GetValue(j * 2 + 1).ToString()); } fields[j] = fld; } //recs[i++].setFields(fields); recs.Peek().setFields(fields); } } return(recs.ToArray()); }
/// <summary> /// Writes the field into a PDF document from a dataTable. /// </summary> /// <param name="record">The index of the record.</param> /// <param name="fieldType">Type of the field.</param> /// <param name="topAdd">The Y coordnate (should be a running total).</param> /// <param name="fieldKey">The keyname of the field.</param> /// <param name="stamp">PDf stamp object to stamp with.</param> /// <param name="docFields">Collection of fields that may go onto the document.</param> /// <param name="currentPage">The current page.</param> /// <param name="totalPages">The total number of pages.</param> /// <param name="dt">The SQL dataTable.</param> /// <param name="queryArguments">Collection to replace AField values (from docFields) with.</param> private static void WriteField(int record, int fieldType, float topAdd, string fieldKey, ref PdfStamper stamp, ref Dictionary<string, AField> docFields, int currentPage, int totalPages, DataTable dt, Dictionary<string, object> queryArguments) { string pattern1 = @"(^)(>)(.*$)"; string pattern2 = @"(.*)>([^;]+);(.*)"; string rplPat2 = ">$2;"; string rplPat1 = "$1$3"; //Never used -> string colPat="$2"; if(fieldType == 1) { pattern1 = @"(^)(>>)(.*$)"; pattern2 = @"(.*)>>([^;]+);(.*)"; rplPat2 = ">>$2;"; } foreach(AcroFields.FieldPosition pos in stamp.AcroFields.GetFieldPositions(fieldKey)) { AField f = new AField(); f.PDFKey = fieldKey; Rectangle rect = new Rectangle(pos.position); AcroFields.Item item = stamp.AcroFields.GetFieldItem(fieldKey); rect = new Rectangle(pos.position); if(fieldType == 1) { rect.Top += topAdd; rect.Bottom += topAdd; } f.Rect = new Rectangle(rect); f.Page = pos.page; if(fieldKey.StartsWith("_pages")) { f.Value = "Page " + currentPage.ToString() + " of " + totalPages.ToString(); } else if(fieldKey.StartsWith(">image") || fieldKey.StartsWith(">>image")) { string v = ""; if(Regex.IsMatch(fieldKey, pattern2) && dt != null) { string col = RequestReplace(Regex.Replace(fieldKey, pattern2, "$2"), queryArguments); v = fieldKey.Replace(Regex.Replace(fieldKey, pattern2, rplPat2), dt.Rows[record][col].ToString().Trim()); } else { v = fieldKey; } f.Value = RequestReplace(v, queryArguments); f.IsImage = true; } else if(fieldType != 2) { PRAcroForm.FieldInformation info = stamp.Reader.AcroForm.GetField(fieldKey); PdfDictionary dic = info.Info; if(dic.Contains(PdfName.DA)) { PdfString pdfs = dic.Get(PdfName.DA) as PdfString; string s = pdfs.ToString(); string[] vals = s.Split(' '); f.FontFamily = vals[0]; f.FontSize = (float)Convert.ToInt32(vals[1]); if(vals.Length > 6) { f.R = (float)Convert.ToDouble(vals[3]); f.G = (float)Convert.ToDouble(vals[4]); f.B = (float)Convert.ToDouble(vals[5]); } } double int_alignment = 0; if(dic.Contains(PdfName.Q)) { int_alignment = ((iTextSharp.text.pdf.PdfNumber)(dic.Get(PdfName.Q))).DoubleValue; } f.Alignment = int_alignment; string v = Regex.Replace(fieldKey, pattern1, rplPat1); f.Value = dt.Rows[record][v].ToString(); } f.Record = 0; Guid g = Guid.NewGuid(); if(pos.page == 1) { docFields.Add(Convert.ToBase64String(g.ToByteArray()) + fieldKey, f); } } }