I have a helper function where I'd like to be able to pass in a decl or a 
type, and get back standard information about it.

This involves a rather unpleasant series of statements:

function allowedOnStack(t) {
   if (t.typedef) {
     // dispatch typedef code
   } else if (t.isPointer or type.isReference) {
     // dispatch pointer/reference code
   } else if (t.isArray) {
      // dispatch array code
   } else if (t.kind) {
     switch (t.kind) {
     case "class":
     case "struct":
       // dispatch struct/class code
       break;
     case "union":
       // dispatch union code
       break;
     }
   }
   else if (t.precision) {
     // this is a primitive
   }
   else if (t.name == 'void') {
     // this is the meta 'void' type
   }
   else if (t.parameters) {
     // this must be a function type... but maybe it's a function decl...
     // how do I tell the difference?
   }
   else {
     // this must be a decl, because it isn't anything else
     // this seems rather fragile
   }
}

What I would really like is to make every type or decl object have a .kind, e.g.

switch (t.kind) {
case "void":
   // ...
case "typedef":
   // ...
case "array":
   // ...
case "class":
case "struct":
   // ...
case "union":
   // ...
case "primitive":
   // ...
case "function":
   // ...
case "decl":
   // I have really thought about whether I want a single "decl" kind or
   // separate "member", "local", "functiondecl" and "global" kinds.
};

I think I can implement my proposal, but I'd like to make sure others think 
it's a good idea, and have any thoughts on how decls should be presented, 
especially the difference between a function type and a function decl.

--BDS
_______________________________________________
Dev-static-analysis mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-static-analysis

Reply via email to