[cfe-dev] Get ObjC message parameter value in a Checker

DeepakRajHR hr.deepak at tcs.com
Wed Nov 6 06:46:56 PST 2013


I'm new to the clang. In a checker I'm trying to implement, I want to fetch
the value to the parameter 'attribute' passed ObjC message to NSFileManager.
Message is as following:

NSFileManager *fileManager = [NSFileManager defaultManager];
[fileManager createFileAtPath:filePath contents:dfltFileData
attributes:fileAttributes];

Once the *'fileAttributes'* is obtained which is of type NSDictionary, then
I need to get the value of the key 'NSFileProtectionKey'.  'fileAttributes'
is declared as following.

NSDictionary *fileAttributes = [NSDictionary
dictionaryWithObject:NSFileProtectionComplete
                                                            
forKey:NSFileProtectionKey];

By implementing the checker callback checkPostObjCMessag, I'm able to get
the parameter 'attributes' as Expr. Now I'm not able to get the pointer or
something to this object 'fileAttributes' using Expr so that I can goto the
declaration of 'fileAttributes' and check for interested key value. The
following is the code.

void FileManagerChecker::checkPreObjCMessage(const ObjCMethodCall &Msg,
                                               CheckerContext &C) const {
    const ObjCInterfaceDecl * recv = Msg.getReceiverInterface ();
    const StringRef name = recv->getIdentifier()->getName();
    Selector s = Msg.getSelector();
    StringRef first = s.getNameForSlot(0);
    
    if(name.equals("NSFileManager")) {
    	if(first.equals("createFileAtPath")) {
    		const Expr *en = Msg.getArgExpr(2);
    		QualType ArgTy = en->getType();
    		std::cout << "Qual type: " << ArgTy.getAsString() << std::endl;
    		std::cout << std::endl;
    		// find the variable having the attribute and check
    	} else if(first.equals("setAttributes")) {
    		// find the variable having the attribute and check
    	} else 
    		;	// should never get here
    }
}

I think, I'm in the right direction/way. If not, please guide me a the
better way of doing it.

Thanks a lot.



--
View this message in context: http://clang-developers.42468.n3.nabble.com/Get-ObjC-message-parameter-value-in-a-Checker-tp4035655.html
Sent from the Clang Developers mailing list archive at Nabble.com.



More information about the cfe-dev mailing list