[antlr-interest] Error when my C++ project since updating antlr
Anthony Brenelière
abreneliere at telys.com
Thu Sep 11 06:53:40 PDT 2003
Ok,
I just downloaded the file
http://wwwhome.cs.utwente.nl/~klaren/antlr/antlr-20030911.tar.gz
I re-generated all the grammar files, i compiled the project.
..but the problem is still there:
CIAOParser.hpp(330) : error C2555: 'CIAOParser::getAST': overriding
virtual function return type differs and is not covariant from
'antlr::Parser::getAST'
antlr\antlr\Parser.hpp(103) : see declaration of
'antlr::Parser::getAST'
The problem in not the 2.7.2 01/03 version, it dos just appear when i
upgrade to the new version.
I send to you my iCAIOGrammar.g file, and the 'Main' function that call
the parser.
Cordially,
Anthony
Ric Klaren wrote:
>Hi,
>
>On Fri, Sep 05, 2003 at 08:02:38PM +0200, Anthony Breneli?re wrote:
>
>
>>error C2555: 'CIAOParser::getAST': overriding virtual function return
>>type differs and is not covariant from 'antlr::Parser::getAST'
>> antlr\antlr\Parser.hpp(103) : see declaration of
>>'antlr::Parser::getAST'
>>
>>i didnt have that error before, and methods getAST are the same in the
>>last version
>>
>>I've set "CommonAST" as the AST node of the grammar.
>>
>>What's behind this error message ?
>>Anyone has an idea about how to solve this problem ?
>>
>>
>>
>
>New snapshot is up, I think it should fix this.
>
>Note: RPM's are not updated yet (they are the previous snapshot version).
>
>Cheers,
>
>Ric
>
>
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
-------------- next part --------------
//*********************************************************************************
// THE CIAO GRAMMAR FILE
// author : Anthony Brenelière
//
// Description : this files is composed of two parts,
//
// 1. The grammar, the grammar validates the syntax of the
// file, the grammar part gets tokens from the lexer and products a tree node for
// the tree walker
//
// 2. The Lexer, the lexer reads caracters from the input stream and creates a
// a stream of tokens, that are sent to the parser (to the functions of the grammar).
//
// These lines are added to the lexer/parser header files
//
header {
#include "antlr.extended/ASTFactoryExt.hpp"
#include "antlr.extended/ASTPNode.hpp"
#include "world/WWorld.hpp"
#include "debugger/CIAODebugReport.hpp"
using namespace std;
using namespace ciao;
using namespace world;
using namespace antlr;
}
// These lines are added to the lexer/parser cpp files
//
header "post_include_cpp" {
#include <iostream>
#include "world/WPropertiesTypes.hpp"
void CIAOParser::reportError(const RecognitionException& ex)
{
CObjectList * objs;
CObjectList * objs2;
CObject * _templ;
CObject * _text;
int nLine = 0, nTLine = 0;
char buffer[30];
_templ = new CObject();
_templ->aP(p_CATEGORY, "CIAOText");
objs = new CObjectList();
world->findObjectsWProp( objs, world->content, _templ );
// objs.sort( "BufferLine" );
for ( CObjectList::iterator ir = objs->begin();
ir != objs->end();
ir++ )
{
nTLine = atoi( (*ir)->getValue(p_BUFFERLINE).c_str() );
if ( nTLine <= ex.getLine() && nTLine > nLine ) nLine = nTLine;
}
_templ->clear();
_templ->aP( p_BUFFERLINE, itoa( nLine, buffer, 10) );
objs2 = new CObjectList();
world->findObjectsWProp( objs2, objs, _templ );
if (objs2->size() == 1)
{
_text = objs2->front();
cout << endl << endl << "fichier " << _text->getValue( p_FILENAME )
<< " page " << _text->getValue( p_PAGENUMBER )
<< " ligne " << _text->getValue( p_LINENUMBER )
<< endl << "------------------------------"
<< endl << "ID : " << _text->getValue(p_IDENTIFIER)
<< endl << _text->getValue(p_CONTENT)
<< endl << "------------------------------"
<< endl << "Erreur : " << ex.toString() << endl;
}
else
cout << endl << "Unknown error : the corresponding Text has not been found"
<< " by the debugger" << endl;
delete objs;
delete objs2;
delete _templ;
}
}
options {
language="Cpp";
}
//***************************************************
// THE CIAO PARSER
//
class CIAOParser extends Parser;
options {
k = 3; // k tokens are used to determine the choice between the different
// alternatives of a rule
buildAST = true;
importVocab = CIAOLex;
exportVocab = CIAOPar;
ASTLabelType = "RefPNode";
defaultErrorHandler = true;
}
tokens { // those tokens are declared because they are used as root nodes
// for the tree node creation
// used by the grammar and the walkers:
R_DAT="[data types]"; // [data types]
R_ENS="[entity stat]"; // [entity stat]
R_ENI="[id]"; // [id]
R_ATS="[attributes]"; // [attributes]
R_MES="[methods]"; // [methods]
R_INH="[inherits]"; // [inherits]
R_ASS="[association]"; // [association]
R_CAR="[cardinality]"; // [cardinality]
R_ACS="[action]"; // [action]
R_USS="[use]"; // [use]
R_FUS="[function]"; // [function]
R_FRS="[free]"; // [free]
R_INV="[invariant]"; // [invariant]
R_COS="[condition]"; // [condition]
R_DAL="[decl aliases]"; // [decl aliases]
R_ALI="[aliases]"; // [aliases]
R_IHM="[ihm]"; // [ihm]
R_ATL="[attributeList]"; // [attributeList]
R_ENT="[entity]"; // [entity]
R_ENC="[entityComponent]"; // [entityComponent]
R_SET="[set]"; // [set]
R_SEC="[setComponent]"; // [setComponent]
R_CLA="[clause]"; // [clause]
R_CAT="[clause attribute]"; // [clause attribute]
R_ATT="[attribute]"; // [attribute]
R_STA="[statement]"; // [statement]
R_PRP="[properties]"; // [properties]
R_IDE="[identifier]"; // [identifier]
R_MOP="[mod properties]"; // [mod properties]
R_MVE="[mod version]"; // [mod version]
R_MNA="[mod name]"; // [mod name]
R_MDA="[mod date]"; // [mod date]
R_SST="[state]"; // [state]
R_REQ="[requirement]"; // [requirement]
R_EQU="[equivalence]"; // [equivalence]
R_PRO="[protection]"; // [protection]
R_SIL="[protectors]"; // [protectors]
R_FNC="[function_call]"; // [function_call]
}
{
private:
CWorld * world;
CDebugReport * debugR;
string sCurrentStat;
public:
ASTFactoryExt * astFactoryExt;
CIAOParser(TokenStream& lexer, CWorld * _world )
: LLkParser(lexer,3), world( _world )
{
debugR = new CDebugReport( &cerr );
}
~CIAOParser()
{
delete debugR;
}
void reportError(const RecognitionException& ex);
}
// Root rule for the grammar:
ciaoDocument
: ( DELIMITER! statementA DELIMITER! )*
;
exception
catch [ RecognitionException & ex ]
{
reportError( ex );
consume();
consumeUntil(_tokenSet_0);
}
statementA!
{ sCurrentStat = ""; }
: ( b:staStateA )? a:statId c:statement
{ #statementA = #( #[R_STA, "[statement]"], #a, #b, #c ); }
;
statement
: { sCurrentStat == "EXIG" }? requirement
| { sCurrentStat == "FREE" }? statFree
| { sCurrentStat == "ENTITY" }? statEntity
| { sCurrentStat == "ACTION" }? action
| { sCurrentStat == "ASSOCIATION" }? statAssociation
| { sCurrentStat == "CONDITION" }? statCondition
| { sCurrentStat == "USE" }? use
| { sCurrentStat == "AFFECTATION" }? statAssignment
| { sCurrentStat == "DATATYPES" }? statDataTypes
| { sCurrentStat == "IHM" }? ihm
| { sCurrentStat == "FUNCTION" }? function
| { sCurrentStat == "DOC_PROPERTIES" }? moduleProperties
| { sCurrentStat == "INVARIANT" }? invariant
| { sCurrentStat == "PROTECTION" }? protection
| REQU! equivalence
;
staStateA!
: a:staState
{ #staStateA = #( #[R_SST, "[state]"], #a ); }
;
staState
: "NEW"
| "CANCELED"
| "CHANGED"
| "VALID"
| staStateSymbol
;
staStateSymbol
: PLUS
| MINUS
| LNOT
| CROSS
;
statId!
: a:ID_EXIG
{ sCurrentStat = "EXIG";
#statId = #( #[R_IDE, "[identifier]"], #a );
}
| b:ID_FREE
{ sCurrentStat = "FREE";
#statId = #( #[R_IDE, "[identifier]"], #b );
}
| c:ID_ENTITY
{ sCurrentStat = "ENTITY";
#statId = #( #[R_IDE, "[identifier]"], #c );
}
| d:ID_ACTION
{ sCurrentStat = "ACTION";
#statId = #( #[R_IDE, "[identifier]"], #d );
}
| e:ID_ASSOCIATION
{ sCurrentStat = "ASSOCIATION";
#statId = #( #[R_IDE, "[identifier]"], #e );
}
| f:ID_CONDITION
{ sCurrentStat = "CONDITION";
#statId = #( #[R_IDE, "[identifier]"], #f );
}
| g:ID_USE
{ sCurrentStat = "USE";
#statId = #( #[R_IDE, "[identifier]"], #g );
}
| h:ID_AFFECTATION
{ sCurrentStat = "AFFECTATION";
#statId = #( #[R_IDE, "[identifier]"], #h );
}
| i:ID_DATATYPES
{ sCurrentStat = "DATATYPES";
#statId = #( #[R_IDE, "[identifier]"], #i );
}
| j:ID_IHM
{ sCurrentStat = "IHM";
#statId = #( #[R_IDE, "[identifier]"], #j );
}
| k:ID_FUNCTION
{ sCurrentStat = "FUNCTION";
#statId = #( #[R_IDE, "[identifier]"], #k );
}
| l:ID_DOC_PROPERTIES
{ sCurrentStat = "DOC_PROPERTIES";
#statId = #( #[R_IDE, "[identifier]"], #l );
}
| m:ID_INVARIANT
{ sCurrentStat = "INVARIANT";
#statId = #( #[R_IDE, "[identifier]"], #m );
}
| n:ID_PROTECTION
{ sCurrentStat = "PROTECTION";
#statId = #( #[R_IDE, "[identifier]"], #n );
}
;
// protection rules {
protection!
: COLON a:statIdProtectorList BSR b:ID_INVARIANT
{
#protection =
#( #[R_PRO, "[protection]"],
#( #[R_SIL, "[protectors]"], #a ), #b );
}
;
statIdProtectorList
: statIdProtector (COMMA! statIdProtector)*
;
statIdProtector
: ( ID_FREE | ID_EXIG | ID_CONDITION | ID_INVARIANT )
;
// }
equivalence
: a:statId
{ #equivalence = #( #[R_EQU, "[equivalence]"], #a ); }
;
// protection rules {
moduleProperties!
: a:modulePropertyList
{ #moduleProperties = #( #[R_MOP, "[mod properties]"], #a ); }
;
modulePropertyList
: ( moduleProperty )*
;
moduleProperty!
: "NAME" EQUAL a:STRING
{ #moduleProperty = #( #[R_MNA, "[module name]"], #a ); }
| "VERSION" EQUAL b:STRING
{ #moduleProperty = #( #[R_MVE, "[module version]"], #b ); }
| "DATE" EQUAL c:STRING
{ #moduleProperty = #( #[R_MDA, "[module date]"], #c ); }
;
// }
// END Root
// I - Declaration of entities
statDataTypes!
: a:statDataTypeList
{ #statDataTypes = #( #[R_DAT, "[data types]"], #a ); }
;
statDataTypeList
: (CODE_ID (DOT CODE_ID)*)+
;
statEntity!
: CODE_ID (a:inheritance)? (b:attMetList)?
{
#statEntity = #( #[R_ENS, "[entity stat]"],
( #[R_ENI, "[id]"], #CODE_ID ), #a, #b );
}
;
attMetList
: ( attMet )+
;
attMet!
: "ATTRIBUTES"! a:statAttributeList
{
#attMet = #( #[R_ATS, "[attributes]"], #a );
}
| "METHODS"! b:statMethodList
{
#attMet = #( #[R_MES, "[methods]"], #b );
}
;
inheritance!
: "INHERITS" a:identifierList
{
#inheritance = #( #[R_INH, "[inherits]"], #a );
}
;
statAttributeList
: ( statAttribute )+
;
statMethodList
: ( statMethod )+
;
statAttribute!
: a:CODE_ID b:CODE_ID (DOT CODE_ID)*
{
#statAttribute = #( #a, #b );
}
;
statMethod
: a:CODE_ID b:CODE_ID
{
#statMethod = #( #a, #b );
}
;
// END I
// II - Declaration of associations
statAssociation
: association
;
association!
: a:entity b:STRING c:cardinality d:entityOrSet //! use of 'entity', 'entityOrSet' !
{
#association = #( #[R_ASS, "[association]"], #a, #b, #c, #d );
}
;
cardinality!
: a:INTEGER COMMA b:INTEGER
{ #cardinality = #( #[R_CAR, "[cardinality]"], #a, #b ); }
| c:INTEGER COMMA d:"n"
{ #cardinality = #( #[R_CAR, "[cardinality]"], #c, #d ); }
| e:"n" COMMA f:INTEGER
{ #cardinality = #( #[R_CAR, "[cardinality]"], #e, #f ); }
;
// END II
// III - Declaration of actions
action!
: a:actionCommand b:entSetAttList //! use of 'entSetAttList' !
{
#action = #( #[R_ACS, "[action]"], #a, #b );
}
;
actionCommand
: "CREATE"
| "READ"
| "UPDATE"
| "DELETE"
| "FIND"
| "PRINT"
| "LIST"
;
// actionState
// : "POSSIBLE"!
// | "NOT"! "POSSIBLE"!
// | "POSSIBLE"! "ONLY"! "WHEN"! conditionalExpression //! use of 'conditionalExpression' !
// ;
// END of III
// IV - Declaration of assignments
statAssignment
: ifAssignment
| assignmentExpression
;
ifAssignment
: "IF"! conditionalExpression //! use of 'conditionalExpression' !
"THEN"! assignmentExpression //! use of 'conditionalExpression' !
("ELSE"! assignmentExpression)? //! use of 'assignmentExpression' !
;
// END of IV
// V - Declaration of uses
use
: a:entSetAttList // use of 'entSetAttList'
{
#use = #( #[R_USS, "[use]"], #a );
}
;
// END of V
// VI - Declaration of functions
function!
: STRING functionOperator a:conditionalExpression // use of 'conditionalExpression'
{ #function = #( #[R_FUS, "[function]"], #a ); }
| STRING functionActionCommand b:assignmentExpression // use of 'assignmentExpression'
{ #function = #( #[R_FUS, "[function]"], #b ); }
;
functionActionCommand
: "PRE"
| "POST"
;
functionOperator
: "POSSIBLE" "ONLY" "WHEN"
;
// END of VI
// VII - Declaration of types
// END of VII
// VIII - Declaration of free constraints
statFree! // FREE "This is a free constraint !"
: a:INFORMAL_TEXT ( optionalError )?
{ #statFree = #( #[R_FRS, "[free]"], #a); }
;
// END of VIII
// VIII - Declaration of requirements
requirement! // EXIG "This is an exigeance !"
: a:INFORMAL_TEXT ( optionalError )?
{ #requirement = #( #[R_REQ, "[requirement]"], #a); }
;
// END of VIII
// VI - Declaration of condition
invariant
: ( association )=> a:association ( optionalError )? // use of '(II) association'
{ #invariant = #( #[R_INV, "[invariant]"], #a ); }
| ( b:statAliasList )? c:conditionalExpression ( optionalError )? // use of 'conditionalExpression'
{ #invariant = #( #[R_INV, "[invariant]"], #b, #c ); }
;
statCondition
: statConditionA
;
statConditionA!
: ( association )=> a:association ( optionalError )? // use of '(II) association'
{ #statConditionA = #( #[R_COS, "[condition]"], #a ); }
| ( b:statAliasList )? c:conditionalExpression ( optionalError )? // use of 'conditionalExpression'
{ #statConditionA = #( #[R_COS, "[condition]"], #b, #c ); }
;
statAliasList
: (statAlias)+
;
statAlias!
: a:identifierList "AS" ("DISTINCT")? b:component
// --TODO: restrict 'entity', there should be only one entity
{ #statAlias = #( #[R_DAL, "[decl_aliases]"], #b, ( #[R_ALI, "[aliases]"], #a ) ); }
;
// END of VI
// VII - Declaration of ihm
ihm!
: (target)+
| a:conditionalExpression ( optionalError )?
{ #ihm = #( #[R_IHM, "[ihm]"], #a ); }
;
target!
: "LINK" STRING "TARGET" STRING
;
// END of VII
// VIII - Error handling syntax
optionalError!
: "OTHERWISE" "ERROR" INTEGER
| "OTHERWISE" "ERROR" STRING
;
// END of VIII
// IX - Entities & Attributes
attributeSetList // ::customer(.firstname, .lastname)
: set simpleAttRowInp
;
attributeEntList // customer(.firstname, .lastname)
: entity simpleAttRowInp
;
attributeList! // customer(.firstname, .lastname)
: ( setPredicate )=> c:set d:simpleAttRowInp
{ #attributeList = #( #[R_ATL, "[attributeList]"], #c, #d ); }
| a:entity b:simpleAttRowInp
{ #attributeList = #( #[R_ATL, "[attributeList]"], #a, #b ); }
;
simpleAttRowInp // (.firstname, .lastname)
: LPAREN! simpleAttRow RPAREN!
;
simpleAttRow // .firstname, .lastname
: simpleAttribute (COMMA! simpleAttribute)*
;
attributeRow // ::customer(.firstname, .lastname), supplier.name
:
( ( attribute )=> attribute
| ( attributeList )=> attributeList )
( COMMA! (
( attribute )=> attribute
| ( attributeList )=> attributeList
) )*
;
entityOrSet
: ( setPredicate )=> set
| entity
;
entity! // (supplier WHERE name="Telys"):client
: a:entityComponentList
{ #entity = #( #[R_ENT, "[entity]"], #a ); }
;
entityComponentList
: firstEntityComponent ( entityComponent )*
| ( entityComponent )+
;
firstEntityComponent! // (supplier WHERE name="Telys")
: a:component
{ #firstEntityComponent = #( #[R_ENC, "[entityComponent]"], #a ); }
;
entityComponent! // ( :(supplier WHERE name="Telys") )
: COLON a:component
{ #entityComponent = #( #[R_ENC, "[entityComponent]"], #a ); }
;
component
: LPAREN! CODE_ID clause RPAREN!
| CODE_ID
;
set! // ( supplier WHERE name="Telys" ):client
: a:setComponentList
{ #set = #( #[R_SET, "[set]"], #a ); }
;
setComponentList
: ( firstEntityComponent )? ( setComponent | entityComponent )+
;
setPredicate
: ( firstEntityComponent )? ( entityComponent )* setComponent
;
setComponent! // (supplier WHERE name="Telys")
: DB_COLON a:component
{ #setComponent = #( #[R_SEC, "[setComponent]"], #a ); }
;
clause!
: a:"WHERE" b:conditionalExpression
{ #clause = #( #[R_CLA, "[clause]"], #a, #b ); }
;
entityRow // (supplier WHERE name="Telys"):client, service
: entity (COMMA! entity)*
;
entSetAttList // (supplier WHERE name="Telys"):client, service
: entSetAtt ( COMMA! entSetAtt )*
;
entSetAtt
:
( ( attributeList )=> attributeList
| ( attribute )=> attribute
| ( setPredicate )=> set
| entity
)
;
attributeEnt // (supplier WHERE name="Telys"):client.address
: entity simpleAttribute
;
attributeSet // (supplier WHERE name="Telys")::client.address
: set simpleAttribute
;
attribute! // ::supplier:client.address
: ( setPredicate )=> c:set d:simpleAttribute
{ #attribute = #( #[R_ATT, "[attribute]"], #c, #d ); }
| ( entity )=> a:entity b:simpleAttribute
{ #attribute = #( #[R_ATT, "[attribute]"], #a, #b ); }
| e:simpleAttribute
{ #attribute = #( #[R_CAT, "[clause attribute]"], #e ); }
;
simpleAttribute // .name
: DOT! CODE_ID
;
setOperation
: ( set "INTERSECT" )=> a:set "INTERSECT"! b:set
| ( set "UNION" )=> set "UNION"! set
| ( set "MINUS" )=> set "MINUS"! set
;
// END of IX
// X - Expressions
expression
: assignmentExpression
;
assignmentExpression
: conditionalExpression
ASSIGN! conditionalExpression
;
conditionalExpression
: inferenceExpression
;
inferenceExpression
: logicalOrExpression ( (LIN! | RIN! | REQU!) logicalOrExpression)*
;
logicalOrExpression
: logicalAndExpression ("OR"! logicalAndExpression)*
;
logicalAndExpression
: equalityExpressionOrBoolean
("AND"! equalityExpressionOrBoolean)*
;
equalityExpressionOrBoolean
: (attribute expBoolAttClause)=> attribute expBoolAttClause
| (attributeRow expBoolAttListClause)=> attributeRow expBoolAttListClause
| (equalityExpression setBooleanOperator)=>
value setBooleanOperator (attributeSet | valueListInb | interval)
| (interval)=> interval setBooleanOperator interval
| (set setBooleanOperator)=> set setBooleanOperator set
| (attributeEntList setBooleanOperator)=> attributeEntList setBooleanOperator attributeSetList
| ( "TRUE"! | "VRAI"! )
| ( "FALSE"! | "FAUX"! )
| equalityExpression
;
equalityExpression
: relationalExpression ((NOT_EQUAL! | EQUAL!) relationalExpression)*
;
relationalExpression
: additiveExpression
( ( LT_! | GT! | LE! | GE! ) additiveExpression )*
;
additiveExpression
: multiplicativeExpression ((PLUS! | MINUS! ) multiplicativeExpression)*
;
multiplicativeExpression
: unaryExpression ((STAR! | DIV! | MOD! ) unaryExpression)*
;
unaryExpression
: MINUS! unaryExpression
| PLUS! unaryExpression
| unaryExpressionNotPlusMinus
;
unaryExpressionNotPlusMinus
: BNOT! unaryExpression
| LNOT! unaryExpression
| primaryExpression
;
primaryExpression
: ( value )=> value
| LPAREN! conditionalExpression RPAREN!
;
// END of X
// X - Expressions
setBooleanOperator!
: "IN"
| "NOT" "IN"
;
expBoolAttClause!
: "IS" "MAX"
| "IS" "MIN"
| "IS" "NULL"
| "IS" "NOT" "NULL"
| "IS" "NUMERIC"
| "IS" "DATE"
| "IS" "PASSWORD"
| "IS" "TRUE"
| "IS" "FALSE"
| "EXIST"
| "EXIST" cardinality
;
expBoolAttListClause!
: "UNIQUE"
;
numberFunction!
: a:numberFunctionA { #numberFunction = #( #[R_FNC, "[function_call]"], #a ); }
| b:numberFunctionB { #numberFunction = #b; }
;
numberFunctionB
: "DATE"! LPAREN! ( value )? RPAREN!
| "SECOND"! LPAREN! ( value )? RPAREN!
| "MINUTE"! LPAREN! ( value )? RPAREN!
| "HOUR"! LPAREN! ( value )? RPAREN!
| "DAY"! LPAREN! ( value )? RPAREN!
| "MONTH"! LPAREN! ( value )? RPAREN!
| "YEAR"! LPAREN! ( value )? RPAREN!
;
numberFunctionA
: "SUM" LPAREN! ( attributeSet )? RPAREN!
| "AVERAGE" LPAREN! ( attributeSet )? RPAREN!
| "COUNT" LPAREN! set RPAREN!
| "MAX" LPAREN! attribute RPAREN!
| "MIN" LPAREN! attribute RPAREN!
;
number!
: INTEGER
| FLOAT
;
interval
: LBRACK! value COMMA! value RBRACK!
;
valueListInb
: LCURLY! value (COMMA! value )* RCURLY!
;
value // i replaced 'attribute' by 'simpleAttribute'
: numberFunction
| attribute
| number!
| STRING!
;
identifierListWOCA
: ( CODE_ID )+
;
identifierList
: CODE_ID ( COMMA! CODE_ID )*
;
-------------- next part --------------
//*********************************************************************************
// THE CIAO LEXER FILE
// author : Anthony Brenelière
//
// The Lexer, the lexer reads caracters from the input stream and creates a
// a stream of tokens, that are sent to the parser (to the functions of the grammar).
//
// These lines are added to the lexer header files
//
header {
#include <iostream>
#include "antlr.extended/ASTFactoryExt.hpp"
#include "antlr.extended/ASTPNode.hpp"
#include "world/WPropertiesTypes.hpp"
#include "world/WWorld.hpp"
#include "debugger/CIAODebugReport.hpp"
using namespace std;
using namespace ciao;
using namespace world;
using namespace antlr;
}
// These lines are added to the lexer/parser cpp files
//
header "post_include_cpp" {
void CIAOLexer::reportError(const RecognitionException& ex)
{
CObjectList * objs;
CObjectList * objs2;
CObject * _templ;
CObject * _text;
int nLine = 0, nTLine = 0;
char buffer[30];
_templ = new CObject();
_templ->aP(p_CATEGORY, "CIAOText");
objs = new CObjectList();
world->findObjectsWProp( objs, world->content, _templ );
// objs.sort( "BufferLine" );
for ( CObjectList::iterator ir = objs->begin();
ir != objs->end();
ir++ )
{
nTLine = atoi( (*ir)->getValue(p_BUFFERLINE).c_str() );
if ( nTLine <= ex.getLine() && nTLine > nLine ) nLine = nTLine;
}
_templ->clear();
_templ->aP( p_BUFFERLINE, itoa( nLine, buffer, 10) );
objs2 = new CObjectList();
world->findObjectsWProp( objs2, objs, _templ );
if ( objs2->size() == 1 )
{
_text = objs2->front();
cout << endl << endl << "fichier " << _text->getValue( p_FILENAME )
<< " page " << _text->getValue( p_PAGENUMBER )
<< " ligne " << _text->getValue( p_LINENUMBER )
<< endl << "------------------------------"
<< endl << "ID : " << _text->getValue(p_IDENTIFIER)
<< endl << _text->getValue(p_CONTENT)
<< endl << "------------------------------"
<< endl << "Erreur : " << ex.toString() << endl;
}
else
cout << endl << "Unknown error : the corresponding Text has not been found"
<< " by the debugger" << endl;
delete objs;
delete objs2;
delete _templ;
}
}
options {
language="Cpp";
}
//***************************************************
// THE CIAO LEXER
//
{
#include <string>
#include "antlr/SemanticException.hpp"
}
class CIAOLexer extends Lexer;
options {
// testLiterals=false;
exportVocab = CIAOLex;
importVocab = CIAOLitterals;
k=4;
// charVocabulary='\u0003'..'\u00FF';
charVocabulary='\3'..'\377';
testLiterals=false;
defaultErrorHandler = true;
// without inlining some bitset tests, couldn't do unicode;
// I need to make ANTLR generate smaller bitsets; see
// bottom of JavaLexer.java
// codeGenBitsetTestThreshold=20;
}
tokens {
ID_ENTITY;
ID_AFFECTATION;
ID_ASSOCIATION;
ID_DATATYPES;
ID_IHM;
ID_DOC_PROPERTIES;
ID_EXIG;
ID_FREE;
ID_ACTION;
ID_CONDITION;
ID_USE;
ID_FUNCTION;
ID_INVARIANT;
ID_PROTECTION;
}
{
private:
CWorld * world;
CDebugReport * debugR;
bool bOutOfCIAOContext;
bool bInformalLanguageContext;
bool bWaitForStatementNature;
bool bStatIsIdentified;
public:
CIAOLexer(ANTLR_USE_NAMESPACE(std)istream& in, CWorld * _world )
: CharScanner(new CharBuffer(in),true), world( _world ),
bOutOfCIAOContext( true ), bInformalLanguageContext( false ),
bWaitForStatementNature( false ), bStatIsIdentified( false )
{
initLiterals();
debugR = new CDebugReport( &cerr );
}
~CIAOLexer()
{
delete debugR;
}
void reportError( const RecognitionException& ex );
}
// CIAO DELIMITER
DELIMITER
: '\244'
{
if ( bOutOfCIAOContext )
bOutOfCIAOContext = false;
else
bOutOfCIAOContext = true;
bInformalLanguageContext = false;
bStatIsIdentified = false;
}
;
IGNORE_TEXT
: { bOutOfCIAOContext }? ( options { generateAmbigWarnings=false; } : ENDOFLINE | ~( '\244' ) )+
{
$setType(Token::SKIP);
}
;
INFORMAL_TEXT
: { bInformalLanguageContext }? ( options { generateAmbigWarnings=false; } : ENDOFLINE | ~( '\244' ) )+
;
// Operators
//
QUESTION : '?' ;
LPAREN : '(' ;
RPAREN : ')' ;
LBRACK : '[' ;
RBRACK : ']' ;
LCURLY : '{' ;
RCURLY : '}' ;
COLON : ':' ;
DB_COLON : "::" ;
COMMA : ',' ;
DOT : '.' ;
ASSIGN : ":=" ;
EQUAL : "=" ;
LNOT : '!' ;
BNOT : '~' ;
NOT_EQUAL : "<>" ;
DIV : '/' ;
DIV_ASSIGN : "/=" ;
PLUS : '+' ;
PLUS_ASSIGN : "+=" ;
INC : "++" ;
MINUS : '-' ;
MINUS_ASSIGN : "-=" ;
DEC : "--" ;
STAR : '*' ;
STAR_ASSIGN : "*=" ;
MOD : '%' ;
MOD_ASSIGN : "%=" ;
SR : ">>" ;
SR_ASSIGN : ">>=" ;
BSR : ">>>" ;
BSR_ASSIGN : ">>>=" ;
GE : ">=" ;
GT : ">" ;
SL : "<<" ;
SL_ASSIGN : "<<=" ;
LE : "<=" ;
LT_ : '<' ;
BXOR : '^' ;
BXOR_ASSIGN : "^=" ;
BOR : '|' ;
BOR_ASSIGN : "|=" ;
LOR : "||" ;
BAND : '&' ;
BAND_ASSIGN : "&=" ;
LAND : "&&" ;
SEMI : ';' ;
LIN : "==>" ;
RIN : "<==" ;
AT : '@' ;
// UNDERSCORE : '_' ;
AP : '`' ;
RAP : ('\221' | '\222'); // '
CROSS : ('\327');
REQU : "<==>" ;
// Whitespace and new lines characters are ignored
// only in CIAO Formal context language
WS
: ( ' ' | '\t' | '\f' | ENDOFLINE )+
{ $setType(Token::SKIP); }
;
STRING
: '"' ( options { generateAmbigWarnings = false; } : ENDOFLINE | ~('"' | '\244'))* '"'
| '\'' ( options { generateAmbigWarnings = false; } : ENDOFLINE | ~('\'' | '\244'))* '\''
;
FLOAT_OR_INTEGER
: ( FLOAT ) => FLOAT { $setType(FLOAT); }
| ( INTEGER ) => INTEGER { $setType(INTEGER); }
;
IDENTIFIER
options { testLiterals=true; }
: (
( CODE_WDOT '/' "ENTITY" )=>
CODE_WDOT '/' "ENTITY" { $setType( ID_ENTITY ); }
| ( CODE_WDOT '/' "AFFECTATION" )=>
CODE_WDOT '/' "AFFECTATION" { $setType( ID_AFFECTATION ); }
| ( CODE_WDOT '/' "ASSOCIATION" )=>
CODE_WDOT '/' "ASSOCIATION" { $setType( ID_ASSOCIATION ); }
| ( CODE_WDOT '/' "DATATYPES" )=>
CODE_WDOT '/' "DATATYPES" { $setType( ID_DATATYPES ); }
| ( CODE_WDOT '/' "IHM" )=>
CODE_WDOT '/' "IHM" { $setType( ID_IHM ); }
| ( CODE_WDOT '/' "DOC_PROPERTIES" )=>
CODE_WDOT '/' "DOC_PROPERTIES" { $setType( ID_DOC_PROPERTIES ); }
| ( CODE_WDOT '/' 'E' )=>
CODE_WDOT '/' 'E' { $setType( ID_EXIG ); if ( ! bStatIsIdentified ) bInformalLanguageContext = true; }
| ( CODE_WDOT '/' 'F' )=>
CODE_WDOT '/' 'F' { $setType( ID_FREE ); if ( ! bStatIsIdentified ) bInformalLanguageContext = true; }
| ( CODE_WDOT '/' 'A' )=>
CODE_WDOT '/' 'A' { $setType( ID_ACTION ); }
| ( CODE_WDOT '/' 'R' )=>
CODE_WDOT '/' 'R' { $setType( ID_CONDITION ); }
| ( CODE_WDOT '/' 'U' )=>
CODE_WDOT '/' 'U' { $setType( ID_USE ); }
| ( CODE_WDOT '/' 'F' )=>
CODE_WDOT '/' 'F' { $setType( ID_FUNCTION ); }
| ( CODE_WDOT '/' 'I' )=>
CODE_WDOT '/' 'I' { $setType( ID_INVARIANT ); }
| ( CODE_WDOT '/' 'P' )=>
CODE_WDOT '/' 'P' { $setType( ID_PROTECTION ); }
| ( CODE_ID ) => CODE_ID { $setType(CODE_ID); }
)
{
bStatIsIdentified = true;
}
;
UNKNOWN_CHAR
: ( ( '\241'..'\243' ) | ('\245'..'\326') | ('\330'..'\377') )
;
protected
CODE_ID
: LETTER (LETTER | NUMBER)*
;
protected
CODE_WDOT
: LETTER (LETTER | NUMBER | '.')*
;
protected
FLOAT
: (NUMBER)+ '.' (NUMBER)+
;
protected
INTEGER
: (NUMBER)+
;
protected
NUMBER
: ('0'..'9')
;
protected
LETTER
: ('a'..'z'|'A'..'Z' |'_')
;
protected
ENDOFLINE
: ( options { generateAmbigWarnings=false; } : "\r\n" | '\r' | '\n' ) { newline(); }
;
-------------- next part --------------
//***************************************************************
// File : CIAOMain.cpp
// Projet : iCIAO
// Auteur : Anthony Brenelière
// Version : 1.0
// include the antlr-generated files
// CIAO grammar
#include <antlr.generated/CIAOLexer.hpp>
#include <antlr.generated/CIAOParser.hpp>
#include <antlr.generated/CIAOWalker.hpp>
#include <antlr.generated/CIAOAdvWalker.hpp>
// CIAO debugger
#include <debugger/CIAODebugLexer.hpp>
#include <debugger/CIAODebugParser.hpp>
// CIAO commandline
#include "CmdLine/cmdLineLexer.hpp"
#include "CmdLine/cmdLineParser.hpp"
// include the needed antlr source files
#include <antlr/BaseAST.hpp>
#include <antlr/TokenBuffer.hpp>
#include <antlr/CharStreamException.hpp>
#include <antlr/TokenStreamIOException.hpp>
#include <antlr/TokenStreamRecognitionException.hpp>
#include <antlr/TokenStreamRetryException.hpp>
#include <antlr/RecognitionException.hpp>
#include "antlr.extended/ASTFactoryExt.hpp"
// include the models used to store datas
#include "ciao.elements/CIAOWorkTable.hpp"
#include "ciao.elements/CIAOProject.hpp"
#include "world/WWorld.hpp"
#include "CIAOMain.hpp"
#include "CIAOReport.hpp"
#include "debugger/CIAODebugReport.hpp"
#include <conio.h>
#ifdef _WINDOWS
#include "win32/_Win_Start.hpp"
#endif
#include "managed.code/ConverterDoc.hpp"
#ifdef USE_MANAGED_EXTENSIONS
#define NONET
#include "managed.code/ConverterXmi.hpp"
#endif
using namespace std;
using namespace world;
using namespace Win32System;
namespace ciao
{
CMainApp::CMainApp()
{
// # change the version number here ! #
sVersion = "v0.920 build 034";
}
CMainApp::~CMainApp()
{
char buf;
if ( this->Options.DestinationFile == "" )
{
cout << endl << "Press a key to exit..." << endl;
buf = getch();
}
}
int CMainApp::Main(string &sCmdLine)
{
ifstream fileIn, fileIn_;
string sCIAOfn;
strstream clinebuf;
//
// I - parse the command line and assign the application properties
//
try
{
clinebuf << sCmdLine;
cmdLineLexer lexer( clinebuf );
cmdLineParser parser( lexer );
// read the program parameters and sets the corresponding application attributes
parser.parameter_list( this->Options );
}
catch(ANTLR_USE_NAMESPACE(antlr)ANTLRException & e)
{
DisplayHelp();
return -1;
}
/*if(this->Options.iniFile == "")
{
this->Options.iniFile = _getCurrentDir();
this->Options.iniFile.append("\\iCIAO.ini");
}*/
//
// Read the INI File
//
/*if(this->Options.iniFile != "")
{
string source = _getINIValue( this->Options.iniFile,
"Parameters",
"Source");
if(source == "1")
{
this->Options.source = true;
}
else
{
this->Options.source = false;
}
}*/
// redirect the results to a file if an output file is specified
if ( this->Options.DestinationFile != "" )
if ( -1 == RedirectCout2File( cout, true, this->Options.DestinationFile ) ) return -1;
// redirect the errors to a file if an output file is specified
Win32System::_getCurrentDir( Options.DebugFile );
Options.DebugFile += "\\debug.log";
if ( -1 == RedirectCout2File( cerr, true, Options.DebugFile ) ) return -1;
//
// II - display and checking the chosen attributes to standard output stream
//
{
// check the source filed existance, and replace the
string sFNtoCheck;
bool allFilesFound = true;
for ( vector<string>::iterator ir = Options.SourceFiles.begin();
ir != this->Options.SourceFiles.end();
ir++ )
{
_searchPath( sFNtoCheck, *ir );
if ( sFNtoCheck == "" )
{
cerr << endl << "The file " << *ir << " has not been found.";
allFilesFound = false;
}
else
*ir = sFNtoCheck;
}
if ( ! allFilesFound ) return (-1);
cerr << "-=================( Command Parameters )=================-" << endl;
cerr << endl;
for ( vector<string>::iterator ir = Options.SourceFiles.begin();
ir != this->Options.SourceFiles.end();
ir++ )
{
cerr << "* Source file : " + *ir << endl;
}
cerr << "* Destination file : " + this->Options.DestinationFile << endl;
cerr << "* " << endl;
}
if ( this->Options.SourceFiles.size() == 0 )
{
DisplayHelp();
return -1;
}
if ( this->Options.displayHelp )
{
DisplayHelp();
return 0;
}
#ifdef _WINDOWS
//
// III - generate the text documents from XMI or Word documents
//
ConvertDocuments();
#endif
//
// IV - concatenates source file to consolidate all ciao text files into one
// the result text file is sCIAOfn
//
ConcatenateSourceFiles( sCIAOfn );
fileIn.open( sCIAOfn.c_str() );
fileIn_.open( sCIAOfn.c_str() );
// The antlr extended factory is used to create a tree of CIAO elements
// that are exploited, it is used in the parser, and created here :
ANTLR_USE_NAMESPACE(antlr)ASTFactoryExt ast_factory( "PNode", antlr::PNode::factory );
// The world for storing all the datas is created there :
CWorld * world = new CWorld();
// The ciao data object that check document consistency is created here:
CProject * project = new CProject();
CWorkTable * workTable = new CWorkTable( project );
if ( fileIn.fail() || fileIn_.fail() )
{
cerr << endl << "The file '" << sCIAOfn << "' could not be opened." << endl;
return -1;
}
else
{
// the main text document to analyse has been successfully opened
//
// V - pre-parsing the document,
// for debugging purpose
CIAODebugLexer debuglexer( fileIn, false );
CIAODebugParser debugparser( debuglexer, world );
try
{
debugparser.document();
}
catch(ANTLR_USE_NAMESPACE(antlr)ANTLRException& e)
{
cerr << "Debugger Exception: " << e.toString() << endl;
return -1;
}
fileIn.close();
fileIn.open( sCIAOfn.c_str() );
//
// VI - parsing the document,
// the parser's ciaoDocument function is called, and the file is read
CIAOLexer lexer( fileIn_, world );
CIAOParser parser( lexer, world );
try
{
parser.initializeASTFactory( ast_factory );
parser.setASTFactory( &ast_factory );
parser.ciaoDocument();
}
catch(ANTLR_USE_NAMESPACE(antlr)CharStreamException& e)
{
cerr << "CIAOMain: CharStreamException: " << e.toString() << endl;
return -1;
}
catch(ANTLR_USE_NAMESPACE(antlr)RecognitionException& e)
{
cerr << "CIAOMain: RecognitionException: " << e.toString() << endl;
return -1;
}
catch(ANTLR_USE_NAMESPACE(antlr)TokenStreamIOException& e)
{
cerr << "CIAOMain: TokenStreamIOException: " << e.toString() << endl;
return -1;
}
catch(ANTLR_USE_NAMESPACE(antlr)TokenStreamRecognitionException& e)
{
cerr << "CIAOMain: TokenStreamRecognitionException: " << e.toString() << endl;
return -1;
}
catch(ANTLR_USE_NAMESPACE(antlr)TokenStreamRetryException& e)
{
cerr << "CIAOMain: TokenStreamRetryException: " << e.toString() << endl;
return -1;
}
catch(ANTLR_USE_NAMESPACE(antlr)TokenStreamException& e)
{
cerr << "CIAOMain: TokenStreamException: " << e.toString() << endl;
return -1;
}
//
// VIb - display the resulting tree
//
if ( this->Options.displayTree )
cout << GetTreeString ( static_cast<antlr::RefAST>( parser.getAST() ), 0 ) << endl;
if ( this->Options.checkSyntaxOnly ) {
cout << "Syntax is OK";
return 0;
}
//
// VII - walking the parser's resulting tree,
// the consistency's functions are called
CIAOWalker walker ( workTable );
CIAOAdvWalker advWalker ( world );
// walker.initializeASTFactory(ast_factory);
// walker.setASTFactory(&ast_factory);
// walk tree
walker.ciaoTreeDocument( static_cast<antlr::RefAST> (parser.getAST()) );
// walk advanced tree : pass 1
advWalker.ciaoTreeDocument( static_cast<antlr::RefAST> (parser.getAST()), 1 );
// creating the world->statementList and world->ciaoTextList lists
world->statementList = new CObjectList();
CObject * oTemplate = new CObject();
oTemplate->aP( p_CATEGORY, "Statement" );
world->findObjectsWProp( world->statementList, world->content, oTemplate);
delete oTemplate;
world->ciaoTextList = new CObjectList();
oTemplate = new CObject();
oTemplate->aP( p_CATEGORY, "CIAOText" );
world->findObjectsWProp( world->ciaoTextList, world->content, oTemplate);
delete oTemplate;
// walk advanced tree : pass 2
advWalker.ciaoTreeDocument( static_cast<antlr::RefAST> (parser.getAST()), 2 );
fileIn.close();
fileIn_.close();
}
//
// VIIb - display the world's content
//
// create the report objects to configure it according to the options
CDebugReport * debugR = new CDebugReport( &cerr );
if ( this->Options.displayTree )
debugR->displayObjectList( world->content );
delete debugR;
// delete the source file if it's a temp file
if ( ! Options.doNotDeleteTempFiles )
{
bool bFileFound = false;
vector<string>::iterator ir = this->Options.SourceFiles.begin();
while ( ir != this->Options.SourceFiles.end() )
{
if ( sCIAOfn == *ir ) bFileFound = true;
ir++;
}
if ( ! bFileFound )
{
if ( ! _deleteFile( sCIAOfn ) )
{ cerr << "Warning, the file " << sCIAOfn << " could not be deleted"; }
}
}
//
// VIII - here are performed the post-reading consistency checks on the project
//
workTable->performDataAnalysis();
//
// IX - display the results,
// to a file, a graphic interface or the console
DisplayResults( world, workTable );
delete world;
delete project;
delete workTable;
// reinitialize the standard output stream, that has been kept as static value
//
if ( this->Options.DestinationFile != "" ) RedirectCout2File( cout, false, "" );
return (0);
}
int CMainApp::RedirectCout2File( ostream & _ostr, bool _toFile, const string & _sFileN )
{
static streambuf * ostr_sbuf; // remember the cout buffer to reinitialize
static ofstream * FOutput;
if ( _toFile ) // redirect to file or reinitialize
{
FOutput = new ofstream;
(*FOutput).open( _sFileN.c_str(), ios_base::out);
if ( ! (*FOutput).fail() )
{
ostr_sbuf = _ostr.rdbuf();
_ostr.rdbuf( (*FOutput).rdbuf() );
}
else
{
// exit !
cout << "The specified file " << _sFileN
<< " could not be opened for writing.";
// delete FOutput;
return -1;
}
}
else
{
if ( this->Options.DestinationFile != "" )
{
_ostr.rdbuf( ostr_sbuf );
(*FOutput).close();
}
}
return 0;
}
void CMainApp::ConcatenateSourceFiles(string & sCIAOfn)
{
ifstream fileIn;
ofstream fileOut;
char * fbuffer;
long size;
if ( this->Options.SourceCIAOFiles.size() > 1 )
{
// concatenate source files into one unique file
{
sCIAOfn = "___temp.ciao";
fileOut.open( sCIAOfn.c_str(), ofstream::binary | ofstream::trunc );
if ( ! (fileIn.fail()) )
{
for ( vector<string>::iterator ir = Options.SourceCIAOFiles.begin();
ir != this->Options.SourceCIAOFiles.end();
ir++ )
{
if ( ! (fileIn.fail()) )
{
fileIn.open( (*ir).c_str(), ifstream::binary);
// get size of file
fileIn.seekg(0, ifstream::end);
size = fileIn.tellg();
fileIn.seekg(0);
// allocate memory for file content
fbuffer = new char [size];
// read content of infile
fileIn.read (fbuffer, size);
// write to outfile
fileOut.write (fbuffer, size);
// release dynamically-allocated memory
delete[] fbuffer;
fileIn.close();
fileIn.clear();
// delete the source file if it's a temp file
if ( ! Options.doNotDeleteTempFiles )
{
bool bFileFound = false;
vector<string>::iterator ir2 = this->Options.SourceFiles.begin();
while ( ir2 != this->Options.SourceFiles.end() )
{
if ( *ir == *ir2 ) bFileFound = true;
ir2++;
}
if ( ! bFileFound )
{
if ( ! _deleteFile( *ir ) )
{ cerr << "Warning, the file " << *ir << " could not be deleted"; }
}
}
}
else
{
cout << "The source file '" + (*ir) + "' could not be opened." << endl;
return;
}
}
}
else
{
cout << "The destination file '" + sCIAOfn + "' could not be opened." << endl;
}
fileOut.close();
}
}
else
{
sCIAOfn = this->Options.SourceCIAOFiles[0];
}
}
void CMainApp::DisplayHelp(void)
{
cout << endl << "----------------------------------------------------------------------"
<< endl << "iCIAO.exe ";
if ( Options.dispVersion ) cout << sVersion;
cout << " : CIAO (c) Telys"
<< endl << "----------------------------------------------------------------------" << endl
<< endl << "To use iCIAO you have to type the following command :" << endl
<< endl << " Simple usage : iCIAO.exe (source 1)..(source n) /ouput:(destination) [options]" << endl
<< endl << " source : the path of one or more sources files,"
<< endl << " may be \"\\specifications\\survey application.ciao\""
<< endl << " destination : the path of a destination file,"
<< endl << " may be \"\\temp\\spec results.txt\"" << endl
<< endl << " /help : display that help message"
<< endl << " /tree : display the resulting AST data tree" << endl
<< endl << " /checksyntaxonly : just check the syntax, do not check the document consistency" << endl;
}
string CMainApp::GetTreeString(antlr::RefAST T, int level)
{
string ts="";
int i;
if ( T == NULL ) return ts;
if ( T->getFirstChild() )
{
ts += "\n";
for ( i=1; i<=level; i++ ) ts += ". ";
ts += T->toString();
ts += GetTreeString( T->getFirstChild(), level + 1 );
}
else
{
ts += "\n";
for ( i=1; i<=level; i++ ) ts += ". ";
ts += T->toString();
}
if ( T->getNextSibling() )
ts += GetTreeString( T->getNextSibling(), level );
return ts;
}
void CMainApp::DisplayResults( CWorld * _world, CWorkTable * _workTable )
{
string sCounterFile;
CReportCreator * Report = new CReportCreator();
Report->setLanguage ( this->Options.language );
Report->setLinesOn ( false );
Report->setDetailsOn ( true );
Report->setWorld( _world );
Report->setWorkTable( _workTable );
if (this->Options.language == "french")
cout << endl << " -= Rapport d'analyse iCIAO =-" << endl;
if (this->Options.language == "english")
cout << endl << " -= Analysis CIAO report =-" << endl;
cout << "________________________________________________________________________________" << endl << endl;
if (this->Options.language == "french")
cout << endl << "Document(s) source(s) : " << endl;
if (this->Options.language == "english")
cout << endl << "Source(s) document(s) : " << endl;
for ( vector<string>::iterator ir = Options.SourceFiles.begin();
ir != this->Options.SourceFiles.end();
ir++ )
{
cout << " - " + *ir << endl;
}
if (this->Options.language == "french")
cout << endl << endl << " [ [ Cohérence des règles ] ]" << endl << endl;
if (this->Options.language == "english")
cout << endl << endl << " [ [ Rules's consistency ] ]" << endl << endl;
cout << "Anomalies de niveau 1 : ";
Report->displayNoErrorNotification();
Report->displayEntitiesToUser( (elementState) (tused | tnotdeclared) );
Report->displayEntitiesToUser( (elementState) (tdeclared | tnotused) );
Report->displayAttributesToUser( (elementState) (tused | tnotdeclared) );
Report->displayAttributesToUser( (elementState) (tdeclared | tnotused) );
Report->displayAssociationsToUser( (elementState) (tused | tnotdeclared) );
Report->displayAssociationsToUser( (elementState) (tdeclared | tnotused) );
Report->displayEntitiesWithoutAttribute();
Report->displayAssociationsWithoutCardinality();
// Report->displayEntitiesWMissingAction();
Report->displayEntitiesWMissingActionDetailed();
cout << "Anomalies de niveau 2 : ";
Report->displayInvariantIncoherence();
if (this->Options.DestinationFile != "")
{
cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
<< "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
}
cout << "_____________________________________________________" << endl << endl;
if (this->Options.language == "french")
cout << endl << " [ [ Informations sur les entités/associations ] ]" << endl << endl;
if (this->Options.language == "english")
cout << endl << " [ [ Entity/Associations informations ] ]" << endl << endl;
Report->displayEntitiesToUser( tused );
Report->displayEntitiesToUser( tdeclared );
Report->displayAttributesToUser( tused );
Report->displayAttributesToUser( tdeclared );
Report->displayAssociationsToUser( tused );
Report->displayAssociationsToUser( tdeclared );
if (this->Options.language == "french")
cout << endl << " [ [ Compteurs ] ]" << endl << endl;
if (this->Options.language == "english")
cout << endl << " [ [ Counters ] ]" << endl << endl;
Report->displayCounters();
if ( this->Options.DestinationFile != "" )
{
int sSlashPos = Options.DestinationFile.rfind('\\');
if ( sSlashPos != -1 )
sCounterFile = Options.DestinationFile.substr( 0, sSlashPos + 1 );
sCounterFile = sCounterFile + ( (Options.language == "english") ? "counter.txt" : "" );
sCounterFile = sCounterFile + ( (Options.language == "french") ? "compteur.txt" : "" );
RedirectCout2File( cout, true, sCounterFile );
}
Report->displayStatementStatusCounters();
delete Report;
}
#ifdef _WINDOWS
void CMainApp::ConvertDocuments()
{
string sExt; // used to store the extension of source files for anslysis
string sCIAOfn; // used to store the name of the generated text ciao file
string sDOCInitfn; // used to store the name of the .doc/.xmi file as entered by the user
string sDOCfn; // used to store the name of the .doc/.xmi file with the full path
for ( vector<string>::iterator ir = Options.SourceFiles.begin();
ir != this->Options.SourceFiles.end();
ir++ )
{
sDOCInitfn = *ir;
if ( sDOCInitfn.length() >= 4 ) sExt.assign(sDOCInitfn.substr(sDOCInitfn.length() - 4, 4));
sDOCfn = _getAbsolutePathName( sDOCfn, sDOCInitfn );
sCIAOfn.assign(sDOCfn, 0, sDOCfn.length() - 3);
sCIAOfn.append("ciao", 4);
if ( ( sExt == ".doc" ) || ( sExt == ".rtf" ) )
{
// strings sCIAOfn et sDOCfn are defined
if ( ( sExt == ".doc" )
|| ( sExt == ".rtf" ) )
{
CConverterDoc * convDoc = new CConverterDoc();
convDoc->ConvertFromDOC( sCIAOfn.c_str(), sDOCfn.c_str(), this->Options.debugDocLines );
}
}
#ifdef USE_MANAGED_EXTENSIONS
// that functionality is only available using managed extensions
else
if ( ( sExt == ".xmi" ) || ( sExt == ".xml" ) )
{
if ( ( sExt == ".xmi" )
|| ( sExt == ".xml" ) )
{
CConverterXmi * convXmi = new CConverterXmi();
convXmi->ConvertFromXMI( sCIAOfn.c_str(), sDOCfn.c_str() );
}
}
#endif // USE_MANAGED_EXTENSIONS
else sCIAOfn = sDOCInitfn;
// add the converted (or not) source file to the CIAO source file list
Options.SourceCIAOFiles.push_back( sCIAOfn );
}
}
} // end of namespace ciao
#endif // _WINDOWS
-------------- next part --------------
//***************************************************************
// File : CIAOMain.hpp
// Project : iCIAO
// Author : Anthony Breneliere
// Version : 1.0
#ifndef _CIAOMain_hpp_
#define _CIAOMain_hpp_
#include <string>
#include <iostream>
#include <strstream>
#include <fstream>
#include <vector>
#include <antlr/ASTRefCount.hpp>
#include "CIAOConfig.hpp"
#include "world/WWorld.hpp"
#include "ciao.elements/CIAOWorkTable.hpp"
namespace ciao {
// options of the source file
class CAppOptions
{
public:
CAppOptions()
{
displayHelp = false;
displayTree = false;
checkSyntaxOnly = false;
language = "french";
dispVersion = false;
debugDocLines = false;
doNotDeleteTempFiles = false;
source = false;
iniFile = "";
}
// List of source files to analyze
std::vector<std::string> SourceFiles;
// List of CIAO source files to analyze
std::vector<std::string> SourceCIAOFiles;
// the name of the destination file
std::string DestinationFile;
// this is the name of the debug file
std::string DebugFile;
// language to use with the program
std::string language;
// user asked to display the help message if true
bool displayHelp;
// display also the tree resulting from the parsing
bool displayTree;
// just check the syntax
bool checkSyntaxOnly;
// just check the syntax
bool dispVersion;
// option to detch the lines & pages from the original document
bool debugDocLines;
// option used to preserve intermediary files when the analys id done
// from an xml file or a word document
bool doNotDeleteTempFiles;
// option used to display the source file of a ciao error
bool source;
// the INI file name
std::string iniFile;
};
class CMainApp
{
std::string sVersion;
public:
CAppOptions Options;
CMainApp();
~CMainApp();
/*
* the platform generic main function, called by the program run-time or another
* main's function (specific to the platform)
*/
int Main (std::string &sCmdLine);
/*
* display the parser's resulting tree
*/
std::string GetTreeString(antlr::RefAST T, int level);
/*
* Display the resulting data after the ciao document's consistency
* has been performed
*/
void DisplayResults( world::CWorld * _world, CWorkTable * _workTable );
/*
* Display the command-line help
*/
void DisplayHelp(void);
/*
* Windows Specific function.
* Converts all XMI and Word documents to ciao text files
*/
void ConvertDocuments();
/*
* read the source files names from the app's options, concatenate all these files
* into one, which name is sent has parameter
*/
void ConcatenateSourceFiles(std::string & sCIAOfn);
/*
* Redirect the standard ouput to a file
* - use a static variable to store the cout's buffer
*/
// int RedirectCout2File( bool toFile, const string & _sFileN );
int RedirectCout2File( ostream & _ostr, bool _toFile, const string & _sFileN );
};
} // end of ciao namespace
#endif
More information about the antlr-interest
mailing list