Code Monkey home page Code Monkey logo

Comments (9)

federicobond avatar federicobond commented on May 29, 2024 1

The node for function MyContract {} has a name key with "MyContract" as value, whereas in constructor() {}, name is null.

Please try different sources and review the full generated AST. You should be able to get most of your answers from there.

from solidity-parser-antlr.

federicobond avatar federicobond commented on May 29, 2024

HI @obernardovieira, without looking at the whole AST it's hard to know what's going on. I think you should see a parent node FunctionCall with name onERC721Received that takes that function call as expression, but I could be wrong. Let me know if that helps.

from solidity-parser-antlr.

obernardovieira avatar obernardovieira commented on May 29, 2024

Hi @federicobond thanks for the quick answer, and thanks for this package btw.
You right, I was not clear.
So I put everything together and I realized I was doing one thing wrong, which was fDef.body.statements.forEach((fLink) => { because I actually don't need it, so I removed and updated parser.visit(fLink, { to parser.visit(fDef, { and it still catches IERC721Receiver again.

parser.visit(ast, {
    FunctionDefinition: (fDef) => {
        fDef.body.statements.forEach((fLink) => {
            parser.visit(fLink, {
                FunctionCall: (functionCallNode) => {
                    if (functionCallNode.expression.name === 'IERC721Receiver') {
                        console.log(functionCallNode);
                    }
                },
            });
        });
    },
});

What I want to do here it to map the function being called in a function's body. And ast is the complete file.

from solidity-parser-antlr.

federicobond avatar federicobond commented on May 29, 2024

Not sure I understand you correctly. Examining the full contract AST in the console should help you understand where to look for. If the piece you are looking for it's not there, please describe the AST output you are getting and what you would have expected to see.

from solidity-parser-antlr.

obernardovieira avatar obernardovieira commented on May 29, 2024

Hi, I can confirm, I miss one thing. Thanks.
On the other hand, the ConstructorDefinition returns nothing and the constructor is actually returned as FunctionDefinition with an "isConstructor" variable as true. Is it a known problem?

from solidity-parser-antlr.

federicobond avatar federicobond commented on May 29, 2024

Where did you see this ConstructorDefinition?

from solidity-parser-antlr.

obernardovieira avatar obernardovieira commented on May 29, 2024

Well, here https://github.com/solidityj/solidity-antlr4/blob/edce5c44d2d681e32bb23034d822bf0fcf1cb43e/Solidity.g4#L65
I assumed it would have the same names. Bad assumption I guess 😁

from solidity-parser-antlr.

federicobond avatar federicobond commented on May 29, 2024

Ahh right, AST names are different from ANTLR parser rules. You can have a function MyContract {} which would be a FunctionDefinition according to ANTLR but is another form of constructor.

from solidity-parser-antlr.

obernardovieira avatar obernardovieira commented on May 29, 2024

I know, but what about constructor() {}? How can I catch it?

from solidity-parser-antlr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.