We need you!

We're working hard on the next version of Developer Fusion. Let us know what you think we should be up to!

Members

Technology Zones

Articles

Hosted By

MaximumASP

Info

This resource has not currently been approved, and is not currently linked to from our directory of resources. It is being displayed here for preview by the author and moderators only.
Rated
Read 239 times

Contents

Related Categories

The use of the code analysis library OpenC++: modifications, improvements, error corrections - 10. Detection of Ptree position in the program text.

AndreyKarpov

10. Detection of Ptree position in the program text.

In some cases it is necessary to know in what places of the program text there is the code from which a particular Ptree object was built.

The function given below returns the address of the beginning and the end of memory space with the text of the program from which the mentioned Ptree object was created.

void GetPtreePos(const Ptree *p, const char *&begin,
                 const char *&end) {
  if (p == NULL)
    return;
  if (p->IsLeaf()) {
    const char *pos = p->GetLeafPosition();
    if (begin == NULL) {
      begin = pos;
    } else {
      begin = min(begin, pos);
    }
    end = max(end, pos);
  }
  else {
    GetPtreePos(p->Car(), begin, end);
    GetPtreePos(p->Cdr(), begin, end);
  }
}

Comments