Forums

Code File Visitation What Class Catches What

General discussion about Cobra. Releases and general news will also be posted here.
Feel free to ask questions or just say "Hello".

Code File Visitation What Class Catches What

Postby RIGHT_THEN » Thu Mar 10, 2011 7:50 am

GentleMen,

above Topic is a place holder for similar questions
and here is the question.

use Namespace.Namespace

1)
what class would catch above statement i assumed it would be UsingStmt class
but is it?? when i move mouse over something it is telling what it is. i have captured
all members,statements and exprs classes through visitation moving over above statement
is not producing anything. something wrong with my code or it is another class

2)what would catch @args in the code file and similar @compiler instructions within the file.



Thanking_you
RIGHT_THEN
RIGHT_THEN
 
Posts: 99

Re: Code File Visitation What Class Catches What

Postby Charles » Fri Mar 11, 2011 2:26 am

1)
It's UseDirective found in CobraWorkspace/Source/NameSpace.cobra.

The UsingStmt is for the "using" statement found in code blocks:
class A

def foo
using tw = File.createText('foo.txt')
tw.writeLine('Hello')


2)
These are handled by "def compilerDirective" in CobraWorkspace/Source/CobraParser.cobra. You'll note that none of the handling for @foo creates a node. Instead the parser handles each directive with whatever specific actions the directive requires, right away.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Code File Visitation What Class Catches What

Postby RIGHT_THEN » Fri Mar 11, 2011 9:11 am

Thanks for the info charles

but what would cause Usedirective to be caught
declsinorder of namespace,box,class,cobramodule nothing seems to catch it
SyntaxNode never seems to be called , NamedNode does get called thou.

namespace has addusedirective() but none specific to retrieve it.

2) AsExpr the object that follows it what would catch it i mean directly
like in dotexpr left and right seem to work i mean there is nothing explicit about
AsExpr then!! one would have to calculate what is being As(ed) to what is it??



Thanking_You
RIGHT_THEN
RIGHT_THEN
 
Posts: 99

Re: Code File Visitation What Class Catches What

Postby Charles » Sat Mar 12, 2011 12:26 am

The following code would create two UseDirectives:

use System.Reflection
use System.Threading


I'm not sure if I understand your question about AsExpr. This code would create one AsExpr:
class A

def main
s as String = 'foo'
trace s


Note that AsExpr inherits NameExpr (as does IdentifierExpr) which provides a name and a definition. A doc string there about the definition says that the definiton may include:

* Class, Struct, Interface
* NameSpace, EnumDecl
* ClassVar, LocalVar, Param

In the case above, the definition would be a LocalVar.

HTH. Ask again if you need more information.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Code File Visitation What Class Catches What

Postby RIGHT_THEN » Sat Mar 12, 2011 6:44 am

Charles

use System.Reflection
use System.Threading


yes that is how i create use directive in code my Question is can it be caught while visitation
is it there is the nodes somewhere.so that i can record it like

class One
def classFunc
Console.writeline("In Func")


all of the above can be recorded while visitation when i loop the CobraModule
through various Visit Functions.

public virtual void Visit([CobraLangInternal.NotNull] UseDirective item)
{

System.Diagnostics.StackFrame gh = new System.Diagnostics.StackFrame();
/*writeToFile(gh.GetMethod().GetParameters()[0].ParameterType.Name);*/
if (item.ShallowString != null)
{
writeToFile(" UseDirective ---->" + item.ShallowString);
}

BgTok.Add(new BagOfVisitedNodes(_VisitedItem: item, _TypeOfVisitedItem: item.GetType()));

}


it is how i thought i would catch it and store it. it is never being called.if usedirective belongs to the namespace then this method should be called while visiting Namspace elements.
like "def classone" belongs to "class One" while visiting class members "def classone" would pop up i am catching it in Visit Methods() i think. how to get hold of usedirective or is it like
compiler directives stored somewhere but not in the node.

althou i see that it does not implement INamespacemember
so either i make
protected System.Collections.Generic.List<UseDirective> _useDirectives = null; to
public System.Collections.Generic.List<UseDirective> _useDirectives = null;
or write a method/prop in Namespace class that gets _useDirectives;

Thanking_You
RIGHT_THEN
RIGHT_THEN
 
Posts: 99

Re: Code File Visitation What Class Catches What

Postby Charles » Sat Mar 12, 2011 11:38 pm

I see now. The directives are stored by NameSpace, but in their own list rather than as a declaration. I have just now added a public property for this which exposes them in changset:2489. Where you are handling namespaces, you will want to invoke .dispatch on "ns.useDirectives".
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Code File Visitation What Class Catches What

Postby RIGHT_THEN » Sun Mar 13, 2011 10:21 pm

Thanks Charles it works now

Thanking_You
RIGHT_THEN
RIGHT_THEN
 
Posts: 99

Re: Code File Visitation What Class Catches What

Postby RIGHT_THEN » Wed Mar 16, 2011 1:22 pm

Charles

When one wants to navigate to the constructor of the Class. how does one find its location
i dont find it anywhere. I checked the deepstring of the PostCallExpr but couldn`t find.
For localVar and other stuff that i am Charting through i am able to find them in shallow or deepstring and then i can naviagte to there Location of defination.
But Constructor is becoming a problem.

Thanking_You
RIGHT_THEN
RIGHT_THEN
 
Posts: 99

Re: Code File Visitation What Class Catches What

Postby Charles » Fri Mar 18, 2011 2:16 am

Do you really need to see it in the deep string? Why not loop through the decls or something?
# untested
for decl in someClass.declsInOrder
trace decl
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Code File Visitation What Class Catches What

Postby RIGHT_THEN » Fri Mar 18, 2011 3:24 am

yes i am finding out about locations through visitation only
your for loop i will check too.

this is the senario

x = One() #<--- when user clicks GotoDefination the visitation expr happens to be
#PostCallExpr
#and when i dont find things i want, i print its deepString to see how to
#get hold of it. so the Deepstring of this PostCallExpr does not show its
#location of origin
that is to clarify that i am not parsing deepstring to get hold of things thankfully Yet!.

Thanking_You
RIGHT_THEN
c1.cobra
codefile
(476 Bytes) Downloaded 432 times
c1.jpg
senario
c1.jpg (88.47 KiB) Viewed 10203 times
RIGHT_THEN
 
Posts: 99

Next

Return to Discussion

Who is online

Users browsing this forum: No registered users and 27 guests