A Simple Confirmation

43 views
Skip to first unread message

John Savino

unread,
Apr 18, 2014, 3:03:13 PM4/18/14
to boa-...@googlegroups.com
I'm looking to analyze how project size has changed over the years for the projects in the forge. Currently, I'm using: 


p: Project = input;
NOA: output sum[string][int] of int;

visit(p, visitor {
before n: Revision -> {
   visit(n , visitor {
       before node: Declaration -> 
           if (node.kind == TypeKind.CLASS) 
               NOA[p.id][yearof(n.commit_date)] << len(node.fields);
   });
}
});

So my thought is that I visit each project, get the revision, for these revisions, check the number of of fields. Then I sum these by year of commit and project ID. Am I using the visitor correctly?

Thanks!

Robert Dyer

unread,
Apr 18, 2014, 3:15:07 PM4/18/14
to boa-...@googlegroups.com
Hi John,

Based on the description of what you want, I believe that yes your code should provide what you want!  There is another way to write this:

p: Project = input;
NOA
: output sum[string][int] of int;


year
: int;

visit
(p, visitor {
  before n
: Revision -> year = yearof(n.commit_date);
  before n
: Declaration ->
   
if (n.kind == TypeKind.CLASS)
      NOA
[p.id][year] << len(n.fields);
});

Basically, the only reason to use a sub-visitor (as you did) was to avoid declaring a global (to access the Revision).

Note however that I believe while both produce the same results, this version will be much faster.  It seems you found a bug in one of my optimization routines! ;-)

- Robert
Reply all
Reply to author
Forward
0 new messages