Sophie

Sophie

distrib > Fedora > 14 > x86_64 > media > updates > by-pkgid > ffa1e6f5ad04360808fe8840fe3ba036 > files > 286

vrq-devel-1.0.88-1.fc14.i686.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>vrq: Example Plugin</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
  <table border="0" cellspacing="0" cellpadding="0" width="100%">
   <tr>
    <td width="180"><a href="index.html"><img src="vrq.png" width="150" height="100" border="0" alt="vrq"></a></td>
    <td background="top_bg.png" align="right" width="100%">
      <img src="glyth.png" width="500" height="100" border="0" alt="">
    </td>
   </tr>
   <tr>
    <td background="#FFFFFF" align="right" width="50" height="4"></td>
   </tr>
  </table>
</head><body>
<!-- Generated by Doxygen 1.7.1 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
      <li class="current"><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
</div>
<div class="header">
  <div class="headertitle">
<h1>Example Plugin </h1>  </div>
</div>
<div class="contents">
<p>This example plugin converts all procedural if statements to case statements.</p>
<p>The makefile for building the plugin (for linux based systems) follows (Makefile-example2): </p>
<div class="fragment"><pre class="fragment">#/*-----------------------------------------------------------------------------
# * 	Copyright (c) 1997-2009 Mark Hummel DBA Raquette Software.
# *		All rights reserved
# *
# *    This file contains source code written by Raquette Software, 
# *    68 Stewart Street, Franklin MA 02038. It may not be used without 
# *    express written permission. The expression of the information 
# *    contained herein is protected under federal copyright laws and 
# *    all copying without permission is prohibited and may be subject 
# *    to criminal penalties. The Author assumes no responsibility for 
# *    errors, omissions, or damages caused by the use of these programs 
# *    or from use of the information contained herein.
# *
# *-----------------------------------------------------------------------------
# */

#
# Extract installation flags and paths for vrq
#
VRQ_VERSION = $(shell vrq --version|head -n 1|cut -c 5-|cut -d , -f1)
PLUGIN_DIR = $(shell vrq --pkglibdir)
INCLUDE_DIR = $(shell vrq --includedir)
CXXFLAGS = $(shell vrq --cflags)
LDFLAGS = $(shell vrq --ldflags)

#
# name of plugin
#
PLUGIN=example2

#
# Build object file
#
all:	$(PLUGIN).so

$(PLUGIN).o: $(PLUGIN).cc $(PLUGIN).h
	$(CXX) -I . -I $(INCLUDE_DIR) $(CXXFLAGS) \
		-DVRQ_VERSION=\"$(VRQ_VERSION)\" -c $&lt;  -fPIC -DPIC -o $@ 

#
# Build DLL
#
$(PLUGIN).so: $(PLUGIN).o
	$(CXX) $(LDFLAGS) -shared $&lt; -Wl,-soname -Wl,$@ -o $@

#
# Install plugin
#
install: $(PLUGIN).so
	install -c '$&lt;' $(PLUGIN_DIR)

#
# Print installation flags and paths
#
env:
	echo "VRQ_VERSION: $(VRQ_VERSION)"
	echo "PLUGIN_DIR: $(PLUGIN_DIR)"
	echo "INCLUDE_DIR: $(INCLUDE_DIR)"
	echo "CXXFLAGS: $(CXXFLAGS)"
	echo "LDFLAGS: $(LDFLAGS)"

#
# remove built files
#
clean:
	-rm $(PLUGIN).o $(PLUGIN).so


</pre></div><p>The header file for the plugin is below (example2.h): </p>
<div class="fragment"><pre class="fragment">/*-----------------------------------------------------------------------------
 * 	Copyright (c) 1997-2009 Mark Hummel DBA Raquette Software.
 *		All rights reserved
 *
 *    This file contains source code written by Raquette Software, 
 *    68 Stewart Street, Franklin MA 02038. It may not be used without 
 *    express written permission. The expression of the information 
 *    contained herein is protected under federal copyright laws and 
 *    all copying without permission is prohibited and may be subject 
 *    to criminal penalties. The Author assumes no responsibility for 
 *    errors, omissions, or damages caused by the use of these programs 
 *    or from use of the information contained herein.
 *
 *-----------------------------------------------------------------------------
 */
/******************************************************************************
 *
 *
 *	   example2.h
 *	   - example plugin
 *		- 
 *
 ******************************************************************************
 */

#ifndef EXAMPLE2_H 
#define EXAMPLE2_H 

/*
 * include vrq headers
 */
#include "plugin.h"
#include &lt;map&gt;

/*
 * Plugin tools implement a subclass of CBackend.
 */
class CExample2 : public CBackend 
{
public:
	/*
 	 * Methods
 	 */
	CExample2( void );
	virtual char* GetToolName( void );
	virtual char* GetToolDescription( void );
        virtual int AcceptAllPlusArgs( void );
        virtual int HideTool();
        virtual int IgnoreVrqComments();
	virtual int ResolveModules();
	virtual int ResolveInstance( CModule*, CInstance* );
	virtual void Activate();
	virtual void Process( list&lt;CElement&gt;&amp; inputList,
			      list&lt;CElement&gt;&amp; outputList );
};

#endif // EXAMPLE2_H
</pre></div><p>The source for the plugin follows (example2.cc): </p>
<div class="fragment"><pre class="fragment">/*-----------------------------------------------------------------------------
 * 	Copyright (c) 1997-2009 Mark Hummel DBA Raquette Software.
 *		All rights reserved
 *
 *    This file contains source code written by Raquette Software, 
 *    68 Stewart Street, Franklin MA 02038. It may not be used without 
 *    express written permission. The expression of the information 
 *    contained herein is protected under federal copyright laws and 
 *    all copying without permission is prohibited and may be subject 
 *    to criminal penalties. The Author assumes no responsibility for 
 *    errors, omissions, or damages caused by the use of these programs 
 *    or from use of the information contained herein.
 *
 *-----------------------------------------------------------------------------
 */
/******************************************************************************
 *
 *
 *	   example2.cc
 *	   - methods for example plugin
 *
 ******************************************************************************
 */
						

#include "example2.h"

/************************************************
 	CreateToolInstance
	- entry point for dll. Vrq will 
	  call this entry point (must be C code)
	  to create and initialize the tool.
	  If tool creation fails, return NULL and
	  vrq will ignore DLL.
 ************************************************/
extern "C" {
    CBackend* CreateToolInstance()
    {
	/*
 	 * Only initialize the tool if it was built for
 	 * the running version of vrq.
 	 */
        if( strcmp( VRQ_VERSION, VrqVersionString() ) ) {
    	    return NULL;
        }
	/*
 	 * Create tool and return it.
 	 */
        return new CExample2();
    }
}

/************************************************
 	Constructor
	- Initialize tool
 ************************************************/
CExample2::CExample2( ) 
{
}

/************************************************
	AcceptAllPlusArgs
 	- return TRUE if tool accepts arbitrary
	  plusargs.
 ************************************************/
int CExample2::AcceptAllPlusArgs( void ) 
{ 
    /*
     * Tool does not support arbitary plusargs
     */
    return FALSE; 
}

/************************************************
	HideTool
	- return TRUE if tool should be hidden
	  from help system. This allows a tool
	  to be functional and hidden.
 ***********************************************/
int CExample2::HideTool() 
{ 
    return FALSE;
}

/************************************************
	IgnoreVrqComments
	- return TRUE if tool requires lexer to
	  treat vrq translate_on/off pragmas
	  as pure comments.
 ***********************************************/
int CExample2::IgnoreVrqComments() 
{ 
    return FALSE; 
}

/************************************************
	ResolveModules
	- return TRUE if tool requires all
	  module references to be resolved.
	  This is done by search specified
	  library search paths.
 ***********************************************/
int CExample2::ResolveModules() 
{ 
    return FALSE;
}

/************************************************
	ResolveInstance
	- return TRUE if tool requires the
	  given module reference to be resolved.
	  This is allows a tool to implement a
	  fine grain filter on what must be resolved.
	  Note this only called if ResolvedModules
	  returns TRUE.
 ***********************************************/
int CExample2::ResolveInstance( CModule*, CInstance* ) 
{
    return FALSE;
}

/************************************************
	Activate
	- This routine is called before a tool
	  is invoked. It is only called once
	  and will only be called if the tool
	  will be used in a pipeline.
 ***********************************************/
void CExample2::Activate() 
{
}


/************************************************
	GetToolName
 	- return name of tool
 ************************************************/
char* CExample2::GetToolName( void )
{
    static char	toolName[] = "example2";

    return toolName;
}

/************************************************
	GetToolDescription
 	- return description of tool. This
	  text is used in vrq help text, man pages, etc.
 ************************************************/
char* CExample2::GetToolDescription( void )
{
    static char	toolDescription[] = "Example plugin that converts if statements"
				    " to case statements";

    return toolDescription;
}

/************************************************
	ProcessIfStatements
	- callback routine used to convert if
	  statements to case statements. 
 ***********************************************/
CNode* ProcessIfStatements( CNode* n, void* arg )
{
    switch( n-&gt;GetOp() ) {
    }

    return n;
}


/************************************************
	Process
	- process a compilation unit 
 ************************************************/
void CExample2::Process( list&lt;CElement&gt;&amp; inputList,
		       list&lt;CElement&gt;&amp; outputList )
{
    /*
     * process each compilation unit, pass on modified trees to next filter.
     */
    list&lt;CElement&gt;::iterator ptr;
    for( ptr = inputList.begin(); ptr != inputList.end(); ++ptr ) {
	/*
 	 * Transverse the entire code tree for the given compilation
 	 * unit. For each node ProcessIfStatements will be called to 
 	 * convert if to case
 	 */
        CNode* code = ptr-&gt;Code(); 
	code = code-&gt;PostSubVisit1( ProcessIfStatements, NULL );
        outputList.push_back( CElement( ptr-&gt;Filename(), !ptr-&gt;Filename(), code ) );
    }

}


</pre></div> </div>
<hr class="footer"/><address class="footer"><small>Generated by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.1 </small></address>
</body>
</html>