Get the set of instruction of all method separately - listener

There is my grammar of JCA File :
methodBody : stackMethod localMethod descriptorMethod* instructionMethod* ;
stackMethod : '.stack' NUMBER ';' ;
localMethod : '.locals' NUMBER ';' ;
descriptorMethod : '.descriptor' typeJCA ';' qualifiedNumber ';';
instructionMethod :
('L' NUMBER ':')? op=instruction+
;
instruction :
qualifiedID ('L'? NUMBER)* ';'
|'.'qualifiedID '{' (('L' NUMBER) | NUMBER)* ';' '}'
;
I wish to get the instruction of all methods (instructionMethod*) separately. With listeners or visitors
Example :
#Override
public void enterInstructionMethod(InstructionMethodContext ctx) {
//Print all instruction+ (one by one in a loop or any way)
}

It's ok, I found a solution (Trivial solution)
First you have to listen to
#Override
public void enterInstruction(InstructionContext ctx) {
}
And secondly you have to listen to
#Override
public void exitMethodBody(MethodBodyContext ctx) {
// Here you will have the trigger that say : hi, the instructionS that you have just read before are mine
//And the same think for all exitMethodBody
}

Related

FileHelpers quoted fields contains single quote?

How to read FileHelpers quoted fields contains single quote?
Below is my csv records
"1","7" Screen","Mobile"
Model:
[DelimitedRecord(",")]
public class LineModel
{
[FieldQuoted('"', QuoteMode.OptionalForBoth)]
public string Id;
[FieldQuoted('"', QuoteMode.OptionalForBoth)]
public string Details;
[FieldQuoted('"', QuoteMode.OptionalForBoth)]
public string Device;
}
Getting error for above record:-The field Details is quoted but the quoted char: " not is just before the separator (You can use [FieldTrim] to avoid this error)
QuoteMode does not work very well when you have ambiguous quotes in your input file. Instead, you can remove the [FieldQuoted] attributes and handle the quotes in a custom converter.
[DelimitedRecord(",")]
public class LineModel
{
[FieldConverter(typeof(MyQuotedFieldConverter))]
public string Id;
[FieldConverter(typeof(MyQuotedFieldConverter))]
public string Details;
[FieldConverter(typeof(MyQuotedFieldConverter))]
public string Device;
}
public class MyQuotedFieldConverter : ConverterBase
{
public override object StringToField(string from)
{
// If the field starts and ends with a double quote
if (from.StartsWith("\"") && from.EndsWith("\""))
{
// Remove the first and last character
return from.Substring(1, from.Length - 1);
}
return from;
}
}
Of course then you'll have trouble if you have "," within your fields.
"1","7, Screen","Mobile"
In which case, you have to pre-parse the record line to clean up the input by implementing the INotifyRead interface. Something like:
[DelimitedRecord(",")]
public class LineModel : INotifyRead
{
//... fields as before
public void BeforeRead(BeforeReadEventArgs e)
{
if (e.RecordLine.Count(x => x == ',') > 3)
{
e.RecordLine = DetectAndReplaceEmbeddedDelimiters(e.RecordLine);
}
}
public void AfterRead(AfterReadEventArgs e)
{
}
}
Another approach to consider the reverse: use the custom converter to add quotes to every field and remove/replace embedded quotes. Then use QuoteMode.AlwaysQuoted.

runAction not excuted when invoked from CCNode (not onEnter )

I have Class that is CCNode extended from one of its methods i want to excute actions
but none of then are running :
from this class :
class GameController : public CCNode
where i have also this:
void GameController::onEnter()
{
CCNode::onEnter();
}
this is the code i have :
bool GameController::removeFinalGems(CCArray* gemsToRemove)
{
onGemScaleInAnim = CCCallFuncND::create(this,
callfuncND_selector(GameController::OnGemScaleInAnim),gemsToRemove);
onRemoveGemScaleInAnim = CCCallFuncND::create(this,
callfuncND_selector(GameController::OnRemoveGemScaleInAnim),gemsToRemove);
CCSequence* selectedGemScaleInAndRemove = CCSequence::create(onGemScaleInAnim,
onRemoveGemScaleInAnim,
NULL);
bool b = this->isRunning();
CCAction *action = this->runAction(selectedGemScaleInAndRemove);
return true;
}
void GameController::OnGemScaleInAnim(CCNode* sender,void* data)
{
CCArray *gemsToRemove = (CCArray*) data;
}
void GameController::OnRemoveGemScaleInAnim(CCNode* sender,void* data)
{
CCArray *gemsToRemove = (CCArray*) data;
}
also i added check to see if there is actions running before and after
and its look like before its equal 0 and after it is equal 1
int na = this->numberOfRunningActions(); //equal 0
CCAction *action = this->runAction(selectedGemScaleInAndRemove);
int na0 = this->numberOfRunningActions();//equal 1 so there is action
it never gets to the OnRemoveGemScaleInAnim and OnGemScaleInAnim methods
I ran into this problem on cocos2d-x when porting an iOS cocos2d app.
After your "runAction" call, add the following line of code to check to see if paused target(s) is the culprit:
CCDirector::sharedDirector()->getActionManager()->resumeTarget( this );
In my case, this was the reason why actions were not being run. It seems that CCTransitionFade's (from screen transitions) resulted in pauses. It might be due to construction of nodes done during init, although I have not tested that theory.

unterminated function-like macro invocation

bool HelloWorld::init()
{
bool bRet = false;
do {
CC_BREAK_IF(!CCLayerColor::initWithColor( ccc4(255,255,255,255));
} while (0);
}s
my cocos2d-x is the last versions, error at CC_BREAK_IF(!CCLayerColor::initWithColor( ccc4(255,255,255,255)); what can i do ? my ide is xcode6.2
in the older versions, code as above, i have a question: initWithColor is not static function why it can be called by CCLayerColor?
In HelloWorldScene.h
Change
class HelloWorld : public cocos2d::CCLayer
To
class HelloWorld : public cocos2d::CCLayerColor
Change this line from
CCSprite *bg1 = CCSprite::create("abc");
To
CCSprite *bg1 = CCSprite::create("abc.png");
Use do while loop(you have written "s" instead of while in the end)

Implementing a good C++0x error_condition?

I try to figure out how the new system_error together with error_code, error_category and not the least the (meant to implement portable error reporting) error_condition should be used.
I think by reading boost.system I understand how I should use error_codes and error_category. The description leaves out how this is used in conjunction when throwing an exception with ´system_error`, but from the interface from that class I can guess.
class system_error : public runtime_error {
public:
// [...]
system_error(error_code ec, const string& what_arg);
system_error(int ev, const error_category& ecat, const string& what_arg);
system_error(int ev, const error_category& ecat);
// [...]
So, I throw a system_error-exception with the right int+error_category or error_code with its error_category()-method.
But whats the way to provide the portable interface with error_condition?
Both error_code and error_category both have method default_error_condition:
class error_category {
public:
// [...]
virtual error_condition default_error_condition(int ev) const noexcept;
// [...]
class error_code {
public:
// [...]
error_condition default_error_condition(int ev) const noexcept;
// [...]
The error_category-Instances should be pre-created, for example (user-code):
struct AppCategory : public error_category {
const char *name() const noexcept override {
return "application"; }
string message(int ev) const override {
switch(ev) {
case 14: return "error message";
default: return "???";
}
}
error_condition default_error_condition(int ev) const noexcept override {
... ??? ...
}
};
My questions implementing this:
Should I implement default_error_condition in error_category, and how?
Or how do I connect error_codes to the proper error_conditions,
and should I pre-construct error_condition instances?
A class error_code is not supposed to be provided by the user (me), right?
Is there a good example where I can take a look at code how error_condition is supposed to be extended by the user, in conjunction with system_error-exceptions?
If the error codes for your error category can be mapped to one of the std::errc error codes then default_error_condition should do that mapping, and return a std::error_condition with a category of std::generic_category() and a value of the corresponding std::errc enum value. Otherwise it should return an error_condition referring to that category.

Getting a return value or exception from AspectJ?

I am able to get the signature and arguments from advised method calls, but I cannot figure out how to get the return values or exceptions. I'm kind of assuming that it can be done in some way using around and proceed.
You can use after() returning and after() throwing advices as in beginning of the following document. If you're using #AspectJ syntax please refer to #AfterReturning and #AfterThrowing annotations (you can find samples here).
You can also get return value using after returing advice.
package com.eos.poc.test;
public class AOPDemo {
public static void main(String[] args) {
AOPDemo demo = new AOPDemo();
String result= demo.append("Eclipse", " aspectJ");
}
public String append(String s1, String s2) {
System.out.println("Executing append method..");
return s1 + s2;
}
}
The defined aspect for getting return value:
public aspect DemoAspect {
pointcut callDemoAspectPointCut():
call(* com.eos.poc.test.AOPDemo.append(*,*));
after() returning(Object r) :callDemoAspectPointCut(){
System.out.println("Return value: "+r.toString()); // getting return value
}
Using an around() advice, you can get the return value of the intercepted method call by using proceed(). You can even change the value returned by the method if you want to.
For instance, suppose you have a method m() inside class MyClass:
public class MyClass {
int m() {
return 2;
}
}
Suppose you have the following aspect in its own .aj file:
public aspect mAspect {
pointcut mexec() : execution(* m(..));
int around() : mexec() {
// use proceed() to do the computation of the original method
int original_return_value = proceed();
// change the return value of m()
return original_return_value * 100;
}
}