aspect/src_compiler/FindSymbols.cc
// On each node visit, look out for function declaration & call
On each node visit, look out for function declaration & call
On each node visit look out for function declaration & call
void FindSymbols::visit( SgNode* astNode ) {
		switch( astNode->variantT() ) {
			case V_SgFunctionDeclaration: {
				SgFunctionDeclaration* functionDeclaration = isSgFunctionDeclaration( astNode );
				string functionName = functionDeclaration->get_name().str();
				if( functionName == "coAdviceImp" ) {
					SgFunctionType* functionType = functionDeclaration->get_type();
					ROSE_ASSERT( functionType != NULL );
					bool foundFunction = false;
					if( functionType->get_return_type()->unparseToString() == "void" ) {
						SgTypePtrList& argumentList = functionType->get_arguments();
						SgTypePtrList::iterator i = argumentList.begin();
						if( (*i++)->unparseToString() == "const char *" ) { 
							if( (*i++)->unparseToString() == "const char *" ) { 
								if( (*i++)->unparseToString() == "coJoinpointBinding" ) { 
									if( (*i++)->unparseToString() == "void *" ) { 
										if( (*i++)->unparseToString() == "void *" ) { 
											if( (*i++)->unparseToString() == "const char *" ) { Name
												if( (*i++)->unparseToString() == "const char *" ) { 
													if( (*i++)->unparseToString() == "unsigned int" ) { 
														if( (*i++)->unparseToString() == "coAdviceFunctions" ) { 
															if( (*i++)->unparseToString() == "int" ) { 
																if( (*i++)->unparseToString() == "void *" ) { 
																		foundFunction = true;
																}
															}
														}
													}
												}
											}
										}
									}
								}
							}
						}
					}
					if( foundFunction == true ) {
						SgScopeStatement* scope = functionDeclaration->get_scope();
						ROSE_ASSERT( scope != NULL );
						adviceSymbol = scope->lookup_function_symbol( functionName, functionType );
						cout << "Found function declaration \"" << functionName << "\", symbol \"" << adviceSymbol << "\"" << endl;
					}
				}
				else if( functionName == "coJoinpointNewImp" ) {
					SgFunctionType* functionType = functionDeclaration->get_type();
					ROSE_ASSERT( functionType != NULL );
					bool foundFunction = false;
					if( functionType->get_return_type()->unparseToString() == "coFuncJP *" ) {
						SgTypePtrList& argumentList = functionType->get_arguments();
						SgTypePtrList::iterator i = argumentList.begin();
						if( (*i++)->unparseToString() == "const char *" ) { 
							if( (*i++)->unparseToString() == "const char *" ) { 
								if( (*i++)->unparseToString() == "coJoinpointBinding" ) { 
									if( (*i++)->unparseToString() == "void *" ) { 
										if( (*i++)->unparseToString() == "const char *" ) { 
											if( (*i++)->unparseToString() == "unsigned int" ) { 
												foundFunction = true;
											}
										}
									}
								}
							}
						}
					}
					if( foundFunction == true ) {
						SgScopeStatement* scope = functionDeclaration->get_scope();
						ROSE_ASSERT( scope != NULL );
						pointcutSymbol = scope->lookup_function_symbol( functionName, functionType );
						cout << "Found function declaration \"" << functionName << "\", symbol \"" << pointcutSymbol << "\"" << endl;
					}
				}
				break;
			}
			default: {
			}
		}
	}
void FindSymbols :: visit ( SgNode * astNode ) { switch ( astNode -> variantT ( ) ) { case V_SgFunctionDeclaration : { SgFunctionDeclaration * functionDeclaration = isSgFunctionDeclaration ( astNode ) ; string functionName = functionDeclaration -> get_name ( ) . str ( ) ; if ( functionName == " " ) { SgFunctionType * functionType = functionDeclaration -> get_type ( ) ; ROSE_ASSERT ( functionType != NULL ) ; bool foundFunction = false ; if ( functionType -> get_return_type ( ) -> unparseToString ( ) == " " ) { SgTypePtrList & argumentList = functionType -> get_arguments ( ) ; SgTypePtrList :: iterator i = argumentList . begin ( ) ; if ( ( * i ++ ) -> unparseToString ( ) == " " ) { if ( ( * i ++ ) -> unparseToString ( ) == " " ) { if ( ( * i ++ ) -> unparseToString ( ) == " " ) { if ( ( * i ++ ) -> unparseToString ( ) == " " ) { if ( ( * i ++ ) -> unparseToString ( ) == " " ) { if ( ( * i ++ ) -> unparseToString ( ) == " " ) { if ( ( * i ++ ) -> unparseToString ( ) == " " ) { if ( ( * i ++ ) -> unparseToString ( ) == " " ) { if ( ( * i ++ ) -> unparseToString ( ) == " " ) { if ( ( * i ++ ) -> unparseToString ( ) == " " ) { if ( ( * i ++ ) -> unparseToString ( ) == " " ) { foundFunction = true ; } } } } } } } } } } } } if ( foundFunction == true ) { SgScopeStatement * scope = functionDeclaration -> get_scope ( ) ; ROSE_ASSERT ( scope != NULL ) ; adviceSymbol = scope -> lookup_function_symbol ( functionName , functionType ) ; cout << " \" " << functionName << " \" \" " << adviceSymbol << " \" " << endl ; } } else if ( functionName == " " ) { SgFunctionType * functionType = functionDeclaration -> get_type ( ) ; ROSE_ASSERT ( functionType != NULL ) ; bool foundFunction = false ; if ( functionType -> get_return_type ( ) -> unparseToString ( ) == " " ) { SgTypePtrList & argumentList = functionType -> get_arguments ( ) ; SgTypePtrList :: iterator i = argumentList . begin ( ) ; if ( ( * i ++ ) -> unparseToString ( ) == " " ) { if ( ( * i ++ ) -> unparseToString ( ) == " " ) { if ( ( * i ++ ) -> unparseToString ( ) == " " ) { if ( ( * i ++ ) -> unparseToString ( ) == " " ) { if ( ( * i ++ ) -> unparseToString ( ) == " " ) { if ( ( * i ++ ) -> unparseToString ( ) == " " ) { foundFunction = true ; } } } } } } } if ( foundFunction == true ) { SgScopeStatement * scope = functionDeclaration -> get_scope ( ) ; ROSE_ASSERT ( scope != NULL ) ; pointcutSymbol = scope -> lookup_function_symbol ( functionName , functionType ) ; cout << " \" " << functionName << " \" \" " << pointcutSymbol << " \" " << endl ; } } break ; } default : { } } }
On each node visit, look out for function declaration & call
On each node visit look out for function declaration & call
// On function declarations... /* If this is an "advice", we'll see ...
					void coAdviceImp(
						const char* pointcutFuncName,
						const char* prototypeName,
						coJoinpointBinding binding,
						void* id,
						void* func,
						const char* funcName,
						const char* calledByFuncName,
						unsigned int calledByLine,
						coAdviceFunctions adviceFunc,
						int hasAspect,
						void* aspect );
				*/ // And if this function has the right prototype... // pointcutFuncName // prototypeName // binding // id // func // funcName // calledByFuncName // calledByLine // adviceFunc // hasAspect // aspect // Once we've found the function declaration, keep track of the function symbol... // Now get the sysmbol using functionType /* If this is a "pointcut", we'll see within a block, ...
				 *
				 * coFuncJP* coJoinpointNewImp(
				 *  	const char* pointcutFuncName,
				 *  	const char* prototypeName,
				 *  	coJoinpointBinding binding,
				 *  	void* id,
				 *  	const char* calledByFuncName,
				 *  	unsigned int calledByLine );
				 *
				 * Then when USE_PROFILE is not defined...
				 * {
				 *	unsigned int _coFuncJP_i;
				 *	for( _coFuncJP_i = 0; _coFuncJP_i < funcJP->_funcMetas->count; _coFuncJP_i++ ) {
				 *		proto* _coFuncJP_p = funcJP->_funcs[_coFuncJP_i];
				 *		_coFuncJP_p( __VA_ARGS__ );
				 *	}
				 * }
				 *
				 * Remove the block if this is compiled-time weaved!
				 */ // And if this function has the right prototype... // pointcutFuncName // prototypeName // binding // id // calledByFuncName // calledByLine // TODO: check that the "run" is there!!!  And that the block isn't any greater than this! // Once we've found the function declaration, keep track of the function symbol... // BIG TODO: remove the parent block IF its to be compiled-time optimised // OR CHEAT and make a "pointcut_o" for now (calls a dummy run func)! // Now get the symbol using functionType // No other special cases