Xmipp  v3.23.11-Nereus
Public Member Functions | Public Attributes | List of all members
ParamDef Class Reference

#include <argsparser.h>

Inheritance diagram for ParamDef:
Inheritance graph
[legend]
Collaboration diagram for ParamDef:
Collaboration graph
[legend]

Public Member Functions

 ParamDef (ArgLexer *lexer, ASTNode *parent)
 
 ~ParamDef ()
 
bool parseParamList (ArgTokenType startToken, ProgramDef *prog, StringVector &paramList, bool addName)
 
bool parseArgumentList ()
 
virtual bool parse ()
 
bool checkRequires (std::stringstream &errors, ProgramDef *prog)
 
virtual void check (std::stringstream &errors)
 
bool containsArgument (const String &argName)
 
ArgumentDeffindArgument (const String &argName)
 
bool containsAlias (const String &alias)
 
- Public Member Functions inherited from ASTNode
 ASTNode (ArgLexer *lexer=NULL, ASTNode *parent=NULL)
 
virtual ~ASTNode ()
 
virtual bool consume (ArgTokenType type)
 
ArgTokenType lookahead () const
 
bool lookahead (ArgTokenType type) const
 
ArgTokencurrentToken () const
 
void nextToken ()
 
bool parseCommentList (CommentList &comments)
 
void error (String msg)
 
void unexpectedToken (String msg="")
 

Public Attributes

bool notOptional
 
bool orBefore
 
bool independent
 
std::vector< ArgumentDef * > arguments
 
std::vector< const char * > cmdArguments
 
std::vector< ParamDef * > * exclusiveGroup
 
int counter
 for count the number of times it appears in command line More...
 
CommentList comments
 
StringVector aliases
 
StringVector requires
 
- Public Attributes inherited from ASTNode
ASTNodeparent
 
ArgLexerpLexer
 
ArgToken token
 
String name
 
int visible
 

Detailed Description

Class representing the definition of an param An param definition is in the form:

Definition at line 192 of file argsparser.h.

Constructor & Destructor Documentation

◆ ParamDef()

ParamDef::ParamDef ( ArgLexer lexer,
ASTNode parent 
)

Definition at line 522 of file argsparser.cpp.

522  :
523  ASTNode(lexer, parent)
524 {
525  exclusiveGroup = NULL;
526  orBefore = false;
527 }
std::vector< ParamDef * > * exclusiveGroup
Definition: argsparser.h:200
ASTNode(ArgLexer *lexer=NULL, ASTNode *parent=NULL)
Definition: argsparser.cpp:349
bool orBefore
Definition: argsparser.h:196

◆ ~ParamDef()

ParamDef::~ParamDef ( )

Definition at line 529 of file argsparser.cpp.

530 {
531  for (size_t i = 0; i < arguments.size(); ++i)
532  delete arguments[i];
533  if (!orBefore)
534  delete exclusiveGroup;
535 }
std::vector< ParamDef * > * exclusiveGroup
Definition: argsparser.h:200
#define i
std::vector< ArgumentDef * > arguments
Definition: argsparser.h:198
bool orBefore
Definition: argsparser.h:196

Member Function Documentation

◆ check()

void ParamDef::check ( std::stringstream &  errors)
virtual

Implements ASTNode.

Definition at line 715 of file argsparser.cpp.

716 {
717  String aaa = name;
718 
720  if (counter > 1 )
721  {
722  errors << "Duplicated parameter: " << name << " (check alias)" << std::endl;
723  return;
724  }
725 
726  if (counter == 1)
727  {
728  //Check requires restrictions
729  checkRequires(errors, prog);
730 
731  //Check the number of arguments
732  if (arguments.empty()) //if not arguments
733  {
734  if (!cmdArguments.empty())
735  errors << "Parameter " << name << " doesn't take any argument, "
736  << cmdArguments.size() << " provided." << std::endl;
737  }
738  else
739  {
740  size_t argIndex = 0;
741 
742  for (size_t i = 0; i < arguments.size(); ++i)
743  if (!arguments[i]->acceptArguments(errors, argIndex, cmdArguments))
744  {
745  errors << " parameter: " << name << std::endl;
746  return;
747  }
748 
749  if (argIndex < cmdArguments.size() && !arguments[arguments.size()-1]->isList)
750  errors << "Too many arguments for parameter " << name << std::endl;
751  }
752  }
753  else
754  {
755  //Fill default arguments
756  for (size_t i = 0; i < arguments.size(); ++i)
757  if (arguments[i]->hasDefault)
758  cmdArguments.push_back(arguments[i]->argDefault.c_str());
759  }
760 }
String name
Definition: argsparser.h:152
ASTNode * parent
Definition: argsparser.h:147
bool checkRequires(std::stringstream &errors, ProgramDef *prog)
Definition: argsparser.cpp:699
#define i
ProgTransformDimRed * prog
if(fabs(c[*nmax+ *nmax *c_dim1])==0.e0)
std::vector< const char * > cmdArguments
Definition: argsparser.h:199
std::vector< ArgumentDef * > arguments
Definition: argsparser.h:198
std::string String
Definition: xmipp_strings.h:34
int counter
for count the number of times it appears in command line
Definition: argsparser.h:201

◆ checkRequires()

bool ParamDef::checkRequires ( std::stringstream &  errors,
ProgramDef prog 
)

Definition at line 699 of file argsparser.cpp.

700 {
701  ParamDef * param;
702  bool correct = true;
703  for (size_t i = 0; i < requires.size(); ++i)
704  {
705  param = prog->findParam(requires[i]);
706  if (param->counter < 1)
707  {
708  errors << "Parameter " << name << " requires " << requires[i] << std::endl;
709  correct = false;
710  }
711  }
712  return correct;
713 }
String name
Definition: argsparser.h:152
ParamDef * findParam(const String &param)
Definition: argsparser.cpp:905
#define i
StringVector requires
Definition: argsparser.h:205
struct _parameter * param
int counter
for count the number of times it appears in command line
Definition: argsparser.h:201

◆ containsAlias()

bool ParamDef::containsAlias ( const String alias)

Definition at line 550 of file argsparser.cpp.

551 {
552  for (size_t i = 0; i < aliases.size(); ++i)
553  if (alias == aliases[i])
554  return true;
555  return false;
556 }
#define i
StringVector aliases
Definition: argsparser.h:204

◆ containsArgument()

bool ParamDef::containsArgument ( const String argName)

Definition at line 537 of file argsparser.cpp.

538 {
539  return findArgument(argName) == NULL;
540 }
ArgumentDef * findArgument(const String &argName)
Definition: argsparser.cpp:542

◆ findArgument()

ArgumentDef * ParamDef::findArgument ( const String argName)

Definition at line 542 of file argsparser.cpp.

543 {
544  for (size_t i = 0; i < arguments.size(); ++i)
545  if (argName == arguments[i]->name)
546  return arguments[i];
547  return NULL;
548 }
String name
Definition: argsparser.h:152
#define i
std::vector< ArgumentDef * > arguments
Definition: argsparser.h:198

◆ parse()

bool ParamDef::parse ( )
virtual

Implements ASTNode.

Definition at line 558 of file argsparser.cpp.

559 {
561  notOptional = true;
562  orBefore = false;
563  independent = false;
564  counter = 0;
565 
566  //Param Definition(OD)
567  //OD -> OH CL
568  //Param Header(OH)
569  //OH -> O | [O] | OR O
570  //Param(O)
571  //O -> param AL
573  {
574  consume(TOK_LBRA);
575  notOptional = false;
576  }
577  else if (lookahead(TOK_OR))
578  {
579  consume(TOK_OR);
580  orBefore = true;
581  }
582  prog->addParamExclusiveGroup(this);
583 
584  consume(TOK_OPT);
585  name = token.lexeme;
588 
589  prog->addParamName(name, this);
590 
591  //Parse argument list
593 
594  if (notOptional == false)
595  consume(TOK_RBRA);
596 
597  //Parse comment list
599 
600  //WHERE section
601  while (lookahead(TOK_WHERE))
602  {
604  while (lookahead(TOK_LAN))
605  {
606  consume(TOK_LAN);
607  consume(TOK_ID);
609  if (pArg == NULL)
610  {
611  std::cerr << "ERROR; on WHERE definition.\n Param '" << name
612  << "' not contains argument '" << token.lexeme << "'"
613  << std::endl;
614  exit(1);
615  }
616  consume(TOK_RAN);
617 
618  while (lookahead(TOK_ID))
619  {
620  ParamDef * pOpt = new ParamDef(pLexer, this);
621  pOpt->consume(TOK_ID);
622 
623  pOpt->name = pOpt->token.lexeme;
624  pOpt->parseArgumentList();
625  pOpt->parseCommentList(pOpt->comments);
626  pOpt->parseParamList(TOK_REQUIRES, prog, pOpt->requires, false);
627  pArg->subParams.push_back(pOpt);
628  }
629 
630  }
631  }
632 
633  //ALIAS section
634  parseParamList(TOK_ALIAS, prog, aliases, true);
635 
636  //REQUIRES section
637  parseParamList(TOK_REQUIRES, prog, requires, false);
638 
639  return true;
640 }
virtual bool consume(ArgTokenType type)
Definition: argsparser.cpp:376
Reserved words.
Definition: argsparser.h:62
String name
Definition: argsparser.h:152
bool parseCommentList(CommentList &comments)
Definition: argsparser.cpp:392
bool notOptional
Definition: argsparser.h:195
ASTNode * parent
Definition: argsparser.h:147
int visibility
Definition: argsparser.h:83
CommentList comments
Definition: argsparser.h:203
bool starred
Some special mark to tokens.
Definition: argsparser.h:85
StringVector requires
Definition: argsparser.h:205
ProgTransformDimRed * prog
void addParamName(const String &name, ParamDef *param)
Definition: argsparser.cpp:912
ArgLexer * pLexer
Definition: argsparser.h:150
int visible
Definition: argsparser.h:153
if(fabs(c[*nmax+ *nmax *c_dim1])==0.e0)
ParamDef(ArgLexer *lexer, ASTNode *parent)
Definition: argsparser.cpp:522
std::vector< ParamDef * > subParams
Definition: argsparser.h:175
bool independent
Definition: argsparser.h:197
bool parseParamList(ArgTokenType startToken, ProgramDef *prog, StringVector &paramList, bool addName)
Definition: argsparser.cpp:668
void addParamExclusiveGroup(ParamDef *param)
Definition: argsparser.cpp:925
ArgToken token
Definition: argsparser.h:151
ArgumentDef * findArgument(const String &argName)
Definition: argsparser.cpp:542
int counter
for count the number of times it appears in command line
Definition: argsparser.h:201
bool orBefore
Definition: argsparser.h:196
String lexeme
the string literal value of the token
Definition: argsparser.h:76
bool parseArgumentList()
Definition: argsparser.cpp:642
ArgTokenType lookahead() const
Definition: argsparser.cpp:356
StringVector aliases
Definition: argsparser.h:204

◆ parseArgumentList()

bool ParamDef::parseArgumentList ( )

Definition at line 642 of file argsparser.cpp.

643 {
644  bool previousList = false; // to check only one list and at end of arguments
645  bool previousDefault = false; // to check that default values only can be at end
646  //Argument List (AL)
647  //AL -> argument AL | e
648  while (lookahead(TOK_LAN))
649  {
650  ArgumentDef * arg = new ArgumentDef(pLexer, this);
651  arg->parse();
652  token = arg->token;
653 
654  if (previousList)
655  error("A list <...> has found not at the end of argument list");
656 
657  if (previousDefault && !arg->hasDefault)
658  error("A non default argument was found before a default one");
659 
660  previousList = arg->isList;
661  previousDefault = arg->hasDefault;
662 
663  arguments.push_back(arg);
664  }
665  return true;
666 }
bool hasDefault
Definition: argsparser.h:176
ArgLexer * pLexer
Definition: argsparser.h:150
void error(String msg)
Definition: argsparser.cpp:406
std::vector< ArgumentDef * > arguments
Definition: argsparser.h:198
virtual bool parse()
Definition: argsparser.cpp:434
ArgToken token
Definition: argsparser.h:151
ArgTokenType lookahead() const
Definition: argsparser.cpp:356

◆ parseParamList()

bool ParamDef::parseParamList ( ArgTokenType  startToken,
ProgramDef prog,
StringVector paramList,
bool  addName 
)

Definition at line 668 of file argsparser.cpp.

670 {
671  paramList.clear();
672  if (lookahead(startToken))
673  {
674  consume(startToken);
675  consume(TOK_OPT);
676  paramList.push_back(token.lexeme);
677 
678  if (isAlias)
679  prog->addParamName(token.lexeme, this);
680  else
682 
683  while (lookahead(TOK_COMMA))
684  {
686  consume(TOK_OPT);
687  paramList.push_back(token.lexeme);
688  if (isAlias)
689  prog->addParamName(token.lexeme, this);
690  else
692  }
693  consume(TOK_SEMI);
694  }
695 
696  return true;
697 }
void addParamRequires(const String &name)
Definition: argsparser.cpp:920
virtual bool consume(ArgTokenType type)
Definition: argsparser.cpp:376
void addParamName(const String &name, ParamDef *param)
Definition: argsparser.cpp:912
ArgToken token
Definition: argsparser.h:151
String lexeme
the string literal value of the token
Definition: argsparser.h:76
ArgTokenType lookahead() const
Definition: argsparser.cpp:356

Member Data Documentation

◆ aliases

StringVector ParamDef::aliases

Definition at line 204 of file argsparser.h.

◆ arguments

std::vector<ArgumentDef*> ParamDef::arguments

Definition at line 198 of file argsparser.h.

◆ cmdArguments

std::vector<const char *> ParamDef::cmdArguments

Definition at line 199 of file argsparser.h.

◆ comments

CommentList ParamDef::comments

Definition at line 203 of file argsparser.h.

◆ counter

int ParamDef::counter

for count the number of times it appears in command line

Definition at line 201 of file argsparser.h.

◆ exclusiveGroup

std::vector<ParamDef*>* ParamDef::exclusiveGroup

Definition at line 200 of file argsparser.h.

◆ independent

bool ParamDef::independent

Definition at line 197 of file argsparser.h.

◆ notOptional

bool ParamDef::notOptional

Definition at line 195 of file argsparser.h.

◆ orBefore

bool ParamDef::orBefore

Definition at line 196 of file argsparser.h.

◆ requires

StringVector ParamDef::requires

Definition at line 205 of file argsparser.h.


The documentation for this class was generated from the following files: