예제 #1
0
 public void CalcInjectionPoints(CPClassLayout cpInjPoints, CPTraceVar traceVar)
 {
     foreach (var inclStmt in vcCodeModel.Includes)
     {
         VCCodeInclude vcinclStmt = (VCCodeInclude)inclStmt;
         CPInclude     incl       = null;
         string        fname      = Path.GetFileName(vcinclStmt.File);
         if (!cpInjPoints.includesPos.TryGetValue(new Tuple <string, string>(vcinclStmt.Name, fname), out incl))
         {
             if (vcinclStmt.Name == traceVar.defPos.fileName)
             {
                 // define include placement
                 FilePosText inclPos = new FilePosText()
                 {
                     fileName = fname,
                     pos      = { lineNum = vcinclStmt.StartPoint.Line - 1, linePos = vcinclStmt.StartPoint.LineCharOffset },
                     posEnd   = { lineNum = vcinclStmt.EndPoint.Line - 1, linePos = vcinclStmt.EndPoint.LineCharOffset }
                 };
                 incl = new CPInclude()
                 {
                     inclOrig    = vcinclStmt.Name,
                     inclReplace = "__cp__." + vcinclStmt.Name,
                     pos         = inclPos
                 };
                 cpInjPoints.includesPos.Add(new Tuple <string, string>(vcinclStmt.Name, incl.pos.fileName), incl);
             }
         }
     }
 }
예제 #2
0
            public CPTraceVar CalcInjectionPoints(CPClassLayout cpClassLayout, string className, string _fname, ITextPosition pos, out bool needDeclare)
            {
                CPTraceVar traceVar = null;

                if (!cpClassLayout.traceVarPos.TryGetValue(name, out traceVar))
                {
                    needDeclare = true;
                    // add trace pos data
                    traceVar = new CPTraceVar()
                    {
                        name       = name,
                        uniqueName = uniqueName,
                        type       = type,
                        className  = className
                    };
                    cpClassLayout.traceVarPos.Add(traceVar.name, traceVar);
                    // define trace var definition placement
                    traceVar.defPos.fileName    = ent.ProjectItem.Name;
                    traceVar.defPos.pos.lineNum = ent.EndPoint.Line;           // - 1;
                    traceVar.defPos.pos.linePos = ent.EndPoint.LineCharOffset; // - 1;
                }
                else
                {
                    needDeclare = false;
                }
                // add trace pos
                traceVar.traceVarTracePos.Add(new FilePosPnt()
                {
                    fileName = _fname,
                    pos      = { lineNum = pos.lineNum, linePos = pos.linePos }
                });
                // check and add if need file containing original variable declaration
                TextPos traceInclPos = null;

                if (!cpClassLayout.traceInclPos.TryGetValue(ent.ProjectItem.Name, out traceInclPos))
                {
                    cpClassLayout.traceInclPos.Add(ent.ProjectItem.Name, new TextPos()
                    {
                        lineNum = 0, linePos = 0
                    });
                }

                return(traceVar);
            }
예제 #3
0
 public void CalcInjectionPoints(CPClassLayout cpClassLayout, CPTraceVar traceVar, bool needDeclare)
 {
     if (needDeclare)
     {
         // find all places, where this file included
         CodeElement theFunc = null;
         // find & store all constructors init points of this class
         foreach (CodeElement _func in ent.Functions)
         {
             if (_func.Name == ent.Name)
             {
                 theFunc = _func;
                 VCCodeFunction vcFunc = (VCCodeFunction)_func;
                 EditPoint      pnt    = _func.StartPoint.CreateEditPoint();
                 if (pnt.FindPattern("{"))
                 {
                     traceVar.traceVarInitPos.Add(new FilePosPnt()
                     {
                         fileName = _func.ProjectItem.Name,
                         pos      = { lineNum = pnt.Line - 1, linePos = pnt.LineCharOffset }
                     });
                 }
             }
         }
         // if no constructor found add default one
         if (traceVar.traceVarInitPos.Count == 0)
         {
             EditPoint pnt = ent.StartPoint.CreateEditPoint();
             if (pnt.FindPattern("{"))
             {
                 traceVar.injConstructorPos = new FilePosPnt()
                 {
                     fileName = ent.ProjectItem.Name,
                     pos      = { lineNum = pnt.Line - 1, linePos = pnt.LineCharOffset }
                 };
             }
         }
     }
 }
예제 #4
0
        public override bool Execute()
        {
            try
            {
                TaskLogger.Log = Log;
                NetNamedPipeBinding binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None);
                //int colon_pos = ProjectFullName.IndexOf(":");
                //string address = "net.pipe://localhost/ChartPoints/IPCChartPoint"; //!!!!!!!!!! move to vcxproj !!!!!!!!!!!!
                string          address = "net.pipe://localhost/IPCChartPoint/" + System.IO.Path.GetFullPath(ProjectFullName).ToLower();
                EndpointAddress ep      = new EndpointAddress(address);
                ipcChartPnt = ChannelFactory <IIPCChartPoint> .CreateChannel(binding, ep);

                CPClassLayout cpClassLayout = ipcChartPnt.GetInjectionData(ProjectName);
                if (cpClassLayout == null)
                {
                    //!!! Add log message
                    return(true);
                }
                filesOrchestrator = new SortedDictionary <string, CPFileCodeOrchestrator>();
                CPFileCodeOrchestrator fileCPOrk = null;
                foreach (CPTraceVar traceVar in cpClassLayout.traceVarPos.Values)
                {
                    //string traceVarName = "__cp_trace_" + traceVar.name;
                    foreach (var tracePos in traceVar.traceVarTracePos)
                    {
                        fileCPOrk = GetFileOrchestrator(tracePos.fileName);
                        //fileCPOrk.AddTransform(tracePos.pos.lineNum - 1, tracePos.pos.linePos - 1, traceVarName + ".trace();");
                        fileCPOrk.AddTransform(tracePos.pos.lineNum - 1, tracePos.pos.linePos - 1, "cptracer::tracer::pub_trace(" + traceVar.name + ");");
                    }
                    fileCPOrk = GetFileOrchestrator(traceVar.defPos.fileName);
                    //fileCPOrk.AddTransform(traceVar.defPos.pos.lineNum - 1, traceVar.defPos.pos.linePos - 1,
                    //  "cptracer::tracer_elem_impl<" + traceVar.type + "> " + traceVarName + ";");
                    if (traceVar.traceVarInitPos.Count == 0 && traceVar.injConstructorPos != null)
                    {
                        CPFileCodeOrchestrator fileConstrOrk = GetFileOrchestrator(traceVar.injConstructorPos.fileName);
                        fileConstrOrk.AddTransform(traceVar.injConstructorPos.pos.lineNum, traceVar.injConstructorPos.pos.linePos
                                                   ,
                                                   //"public:\n" + traceVar.className + "(){\n" + traceVarName + ".reg((uint64_t) &" + traceVar.name + ", \"" +
                                                   //traceVar.uniqueName + "\", cptracer::type_id<" + traceVar.type + ">::id);\n" + "}");
                                                   "public:\n" + traceVar.className + "(){\n" + "cptracer::tracer::pub_reg_elem(\"" +
                                                   traceVar.uniqueName + "\"," + traceVar.name + ");\n" + "}");
                    }
                    else
                    {
                        foreach (var varInitPos in traceVar.traceVarInitPos)
                        {
                            fileCPOrk = GetFileOrchestrator(varInitPos.fileName);
                            fileCPOrk.AddTransform(varInitPos.pos.lineNum, varInitPos.pos.linePos
                                                   ,
                                                   //traceVarName + ".reg((uint64_t) &" + traceVar.name + ", \"" + traceVar.uniqueName + "\", cptracer::type_id<" +
                                                   //traceVar.type + ">::id);");
                                                   "cptracer::tracer::pub_reg_elem(\"" + traceVar.uniqueName + "\"," + traceVar.name + ");\n");
                        }
                    }
                }
                // resource files
                string tempPath = System.IO.Path.GetTempPath();
                //bool res = CreateFileFromResource("CPInstrBuildTask.Resources.CPTracer_i.h", tempPath + "__cp__.CPTracer_i.h");
                bool   res            = CreateFileFromResource("CPInstrBuildTask.Resources.__cp__.tracer.h", tempPath + "__cp__.tracer.h");
                string tracerCppFName = tempPath + "__cp__.tracer.cpp";
                res = CreateFileFromResource("CPInstrBuildTask.Resources.__cp__.tracer.cpp", tracerCppFName);//!!! read, orchestrate & write instead of CreateFileFromResource !!!
                string content     = File.ReadAllText(tracerCppFName);
                string vsixExtPath = System.IO.Path.GetFullPath(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)).ToLower();
                vsixExtPath = vsixExtPath.Replace(@"\", @"\\");
                string orcContent = content.Replace("#define PATH2DLL \"\"", "#define PATH2DLL \"" + vsixExtPath + "\"");
                File.WriteAllText(tracerCppFName, orcContent);
                //
                foreach (var traceInclPos in cpClassLayout.traceInclPos)
                {
                    fileCPOrk = GetFileOrchestrator(traceInclPos.Key);
                    fileCPOrk.AddTransform(traceInclPos.Value.lineNum, traceInclPos.Value.linePos, "#include \"__cp__.tracer.h\"");// "#include \"..\\tracer\\tracer.h\"");
                }
                foreach (var inclFilePos in cpClassLayout.includesPos)
                {
                    fileCPOrk = GetFileOrchestrator(inclFilePos.Value.pos.fileName);
                    ITextTransform inclTrans = new TextTransformReplace(inclFilePos.Value.inclOrig, inclFilePos.Value.inclReplace);
                    fileCPOrk.AddTransform(inclFilePos.Value.pos.pos.lineNum, inclFilePos.Value.pos.pos.linePos, inclTrans);
                }
                foreach (var fileOrk in filesOrchestrator)
                {
                    fileOrk.Value.Orchestrate(fileOrk.Key);
                }
                ArrayList items = new ArrayList();
                foreach (ITaskItem item in InputSrcFiles)
                {
                    CPFileCodeOrchestrator cpCodeOrk = null;
                    if (filesOrchestrator.TryGetValue(item.ItemSpec, out cpCodeOrk))
                    {
                        ITaskItem replacedItem = new TaskItem(tempPath + "__cp__." + item.ItemSpec);
                        items.Add(replacedItem);
                    }
                    else
                    {
                        items.Add(item);
                    }
                }
                ITaskItem tracerItem = new TaskItem(tempPath + "__cp__.tracer.cpp");// "..\\tracer\\tracer.cpp");
                items.Add(tracerItem);
                if (items.Count > 0)
                {
                    OutputSrcFiles  = (ITaskItem[])items.ToArray(typeof(ITaskItem));
                    SrcFilesChanged = true;
                }
                items.Clear();
                foreach (ITaskItem item in InputHeaderFiles)
                {
                    CPFileCodeOrchestrator cpCodeOrk = null;
                    if (filesOrchestrator.TryGetValue(item.ItemSpec, out cpCodeOrk))
                    {
                        ITaskItem replacedItem = new TaskItem(System.IO.Path.GetTempPath() + "__cp__." + item.ItemSpec);
                        items.Add(replacedItem);
                    }
                    else
                    {
                        items.Add(item);
                    }
                }
                if (items.Count > 0)
                {
                    OutputHeaderFiles  = (ITaskItem[])items.ToArray(typeof(ITaskItem));
                    HeaderFilesChanged = true;
                }
            }
            catch (Exception /*ex*/)
            {
                SrcFilesChanged    = false;
                HeaderFilesChanged = false;
            }

            return(true);
        }