Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In the onNewStmt method, how to get the context? #117

Closed
YunFy26 opened this issue Sep 4, 2024 · 2 comments
Closed

In the onNewStmt method, how to get the context? #117

YunFy26 opened this issue Sep 4, 2024 · 2 comments

Comments

@YunFy26
Copy link

YunFy26 commented Sep 4, 2024

📝 Overall Description

Hello, I am using Tai-e's Plugin to process some stmts. In the onNewStmtmethod, I performed a new process on LoadField.

public void onNewStmt(Stmt stmt, JMethod container) {
        if(stmt instanceof LoadField loadField){
            JField field = loadField.getFieldRef().resolve();
            Collection<Annotation> annotations = field.getAnnotations();
            if (springUtils.isDependencyInjectionField(annotations)) {
                JClass jClass = springUtils.processInjectionField(loadField);
                if (jClass != null) {
                    Obj obj = heapModel.getMockObj(() -> "DependencyInjectionObj", field.getRef(), jClass.getType());
                    Var var = loadField.getLValue();
                    heapContext = contextSelector.selectHeapContext(container, obj);
                    solver.addVarPointsTo(context, var, heapContext, obj);
                }
            }
        }
    }

But the following two statements are incorrect

heapContext = contextSelector.selectHeapContext(container, obj);
solver.addVarPointsTo(context, var, heapContext, obj);

Because in the parameters of onNewStmt, the type of container is JMethod, not CSMethod, I can't get the context

Please how can I solve this problem?

🎯 Expected Behavior

None

🐛 Current Behavior

None

🔄 Reproducible Example

No response

⚙️ Tai-e Arguments

🔍 Click here to see Tai-e Options
{{The content of 'output/options.yml' file}}
🔍 Click here to see Tai-e Analysis Plan
{{The content of 'output/tai-e-plan.yml' file}}

📜 Tai-e Log

🔍 Click here to see Tai-e Log
{{The content of 'output/tai-e.log' file}}

ℹ️ Additional Information

No response

@zhangt2333
Copy link
Member

<pascal.taie.analysis.pta.plugin.Plugin: void onNewStmt(pascal.taie.ir.stmt.Stmt,pascal.taie.language.classes.JMethod)> is a convenient version of <pascal.taie.analysis.pta.plugin.Plugin: void onNewMethod(pascal.taie.language.classes.JMethod)>+jMethod.getIR().forEach(...).

What you may need is <pascal.taie.analysis.pta.plugin.Plugin: void onNewCSMethod(pascal.taie.analysis.pta.core.cs.element.CSMethod)>+csMethod.getContext()+csMethod.getMethod().getIR().forEach(...).

@YunFy26
Copy link
Author

YunFy26 commented Sep 4, 2024

Got it! Thank you.

@YunFy26 YunFy26 closed this as completed Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants