Minor green refactoring
This commit is contained in:
parent
1fe45d659a
commit
9a06ad1380
1 changed files with 21 additions and 25 deletions
|
|
@ -13,13 +13,10 @@ typedef std::vector <GroupInfo> GroupList;
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
gives the string parameter for given
|
|
||||||
Assignment
|
|
||||||
|
|
||||||
Finds the given line in the given source code text, and
|
Finds the given line in the given source code text, and
|
||||||
extracts the comment (excluding the "//" prefix)
|
extracts the comment (excluding the "//" prefix)
|
||||||
*/
|
*/
|
||||||
static std::string getParameter(std::string fulltext, int line)
|
static std::string getComment(const std::string &fulltext, int line)
|
||||||
{
|
{
|
||||||
if (line < 1) return "";
|
if (line < 1) return "";
|
||||||
|
|
||||||
|
|
@ -54,18 +51,17 @@ static std::string getParameter(std::string fulltext, int line)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Gives the string of Description for given
|
Extracts a parameter description from comment on the given line.
|
||||||
Assignment
|
Returns description, without any "//"
|
||||||
*/
|
*/
|
||||||
|
static std::string getDescription(const std::string &fulltext, int line)
|
||||||
static std::string getDescription(std::string fulltext, int loc)
|
|
||||||
{
|
{
|
||||||
if (loc < 1) return "";
|
if (line < 1) return "";
|
||||||
|
|
||||||
unsigned int start = 0;
|
unsigned int start = 0;
|
||||||
for (; start<fulltext.length() ; start++) {
|
for (; start<fulltext.length() ; start++) {
|
||||||
if (loc <= 1) break;
|
if (line <= 1) break;
|
||||||
if (fulltext[start] == '\n') loc--;
|
if (fulltext[start] == '\n') line--;
|
||||||
}
|
}
|
||||||
|
|
||||||
// not a valid description
|
// not a valid description
|
||||||
|
|
@ -93,10 +89,10 @@ static std::string getDescription(std::string fulltext, int loc)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
This function collect the list of groups of Parameter decsibred in
|
This function collect all groups of parameters described in the
|
||||||
scad file
|
scad file.
|
||||||
*/
|
*/
|
||||||
static GroupList collectGroups(std::string fulltext)
|
static GroupList collectGroups(const std::string &fulltext)
|
||||||
{
|
{
|
||||||
GroupList groupList; //container of all group names
|
GroupList groupList; //container of all group names
|
||||||
int lineNo = 1; // tracks line number
|
int lineNo = 1; // tracks line number
|
||||||
|
|
@ -117,7 +113,7 @@ static GroupList collectGroups(std::string fulltext)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fulltext.compare(i, 2, "//") == 0) {
|
if (fulltext.compare(i, 2, "//") == 0) {
|
||||||
i++;
|
i+=2;
|
||||||
while (fulltext[i] != '\n') i++;
|
while (fulltext[i] != '\n') i++;
|
||||||
lineNo++;
|
lineNo++;
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -181,9 +177,10 @@ static GroupList collectGroups(std::string fulltext)
|
||||||
*/
|
*/
|
||||||
void CommentParser::addParameter(const char *fulltext, FileModule *root_module)
|
void CommentParser::addParameter(const char *fulltext, FileModule *root_module)
|
||||||
{
|
{
|
||||||
// Getting list of all group names in the file
|
// Get all groups of parameters
|
||||||
GroupList groupList = collectGroups(std::string(fulltext));
|
GroupList groupList = collectGroups(std::string(fulltext));
|
||||||
|
|
||||||
|
// Extract parameters for all literal assignments
|
||||||
for (auto &assignment : root_module->scope.assignments) {
|
for (auto &assignment : root_module->scope.assignments) {
|
||||||
if (!assignment.expr.get()->isLiteral()) continue; // Only consider literals
|
if (!assignment.expr.get()->isLiteral()) continue; // Only consider literals
|
||||||
|
|
||||||
|
|
@ -193,28 +190,27 @@ void CommentParser::addParameter(const char *fulltext, FileModule *root_module)
|
||||||
// making list to add annotations
|
// making list to add annotations
|
||||||
AnnotationList *annotationList = new AnnotationList();
|
AnnotationList *annotationList = new AnnotationList();
|
||||||
|
|
||||||
// extracting the parameter
|
// Extracting the parameter comment
|
||||||
std::string name = getParameter(std::string(fulltext), firstLine);
|
std::string comment = getComment(std::string(fulltext), firstLine);
|
||||||
// getting the node for parameter annnotataion
|
// getting the node for parameter annnotataion
|
||||||
AssignmentList *assignmentList = CommentParser::parser(name.c_str());
|
AssignmentList *assignmentList = CommentParser::parser(comment.c_str());
|
||||||
if (assignmentList == NULL) {
|
if (assignmentList == NULL) {
|
||||||
assignmentList = new AssignmentList();
|
assignmentList = new AssignmentList();
|
||||||
Expression *expr = new Literal(ValuePtr(std::string("")));
|
Expression *expr = new Literal(ValuePtr(std::string("")));
|
||||||
Assignment *assignment = new Assignment("", shared_ptr<Expression>(expr));
|
Assignment *assignment = new Assignment("", shared_ptr<Expression>(expr));
|
||||||
assignmentList->push_back(*assignment);
|
assignmentList->push_back(*assignment);
|
||||||
}
|
}
|
||||||
const Annotation *parameter = Annotation::create("Parameter",*assignmentList);
|
const Annotation *parameter = Annotation::create("Parameter", *assignmentList);
|
||||||
|
|
||||||
// adding parameter to the list
|
// adding parameter to the list
|
||||||
annotationList->push_back(*parameter);
|
annotationList->push_back(*parameter);
|
||||||
|
|
||||||
|
|
||||||
//extracting the description
|
//extracting the description
|
||||||
name = getDescription(std::string(fulltext), firstLine-1);
|
std::string descr = getDescription(std::string(fulltext), firstLine - 1);
|
||||||
if (name != "") {
|
if (descr != "") {
|
||||||
//creating node for description
|
//creating node for description
|
||||||
assignmentList = new AssignmentList();
|
assignmentList = new AssignmentList();
|
||||||
Expression *expr = new Literal(ValuePtr(std::string(name.c_str())));
|
Expression *expr = new Literal(ValuePtr(std::string(descr.c_str())));
|
||||||
|
|
||||||
Assignment *assignment = new Assignment("", shared_ptr<Expression>(expr));
|
Assignment *assignment = new Assignment("", shared_ptr<Expression>(expr));
|
||||||
assignmentList->push_back(*assignment);
|
assignmentList->push_back(*assignment);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue