summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-06-06 21:15:59 +0300
committerAndrei Karas <akaras@inbox.ru>2015-06-06 21:15:59 +0300
commit2f24687e069abfc82383171d4e05d06487f69a06 (patch)
treedf8954b218b8ccc44dbc52295f86f0ea191883d9 /scripts
parent51096a574a96d741fe875d5bd954f9fea382aacb (diff)
downloadparanucker-2f24687e069abfc82383171d4e05d06487f69a06.tar.gz
paranucker-2f24687e069abfc82383171d4e05d06487f69a06.tar.bz2
paranucker-2f24687e069abfc82383171d4e05d06487f69a06.tar.xz
paranucker-2f24687e069abfc82383171d4e05d06487f69a06.zip
Add script for autogenerate node and parsers based on dir and name.
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/addfile.py80
-rw-r--r--scripts/tpl/node.tpl35
-rw-r--r--scripts/tpl/parser.tpl36
3 files changed, 151 insertions, 0 deletions
diff --git a/scripts/addfile.py b/scripts/addfile.py
new file mode 100755
index 0000000..ab1b937
--- /dev/null
+++ b/scripts/addfile.py
@@ -0,0 +1,80 @@
+#! /usr/bin/env python2
+# -*- coding: utf8 -*-
+#
+# Copyright (C) 2015 Andrei Karas
+
+import sys
+
+
+def readFile(path):
+ with open(path, "r") as f:
+ return f.read()
+def writeFile(fileName, data):
+ with open(fileName, "w") as w:
+ w.write(data)
+def firstBigLetter(text):
+ return text[0].upper() + text[1:]
+
+
+if len(sys.argv) < 2 or len(sys.argv) > 3:
+ print "Usage:"
+ print " addfile.py [dir] nodename"
+ exit(1)
+
+nodeTemplate = readFile("tpl/node.tpl")
+parserTemplate = readFile("tpl/parser.tpl")
+if len(sys.argv) == 2:
+ dirName = ""
+ nodeName = sys.argv[1].lower()
+else:
+ dirName = sys.argv[1].lower()
+ nodeName = sys.argv[2].lower()
+suffixSize = 0
+parserAdditionalCode1 = ""
+parserAdditionalCode2 = ""
+parserBaseInclude = ""
+
+if nodeName[-4:] == "decl":
+ suffixSize = 4
+ parserAdditionalCode1 = " fillLocation(node);\n fillDeclLabel(node);\n"
+ parserAdditionalCode2 = "\n fillDeclAutoGenerated(node);\n fillDeclAttributes(node);\n"
+ parserBaseInclude = "#include \"parsers/base/decl.h\"\n"
+elif nodeName[-4:] == "type":
+ suffixSize = 4
+ parserAdditionalCode2 = "\n fillTypeName(node);\n fillTypeAttributes(node);\n"
+ parserBaseInclude = "#include \"parsers/base/type.h\"\n"
+elif nodeName[-3:] == "cst":
+ suffixSize = 3
+elif nodeName[-4:] == "expr":
+ suffixSize = 4
+ parserAdditionalCode2 = "\n fillExprOperands(node);\n"
+ parserBaseInclude = "#include \"parsers/base/expr.h\"\n"
+elif nodeName[-4:] == "list":
+ suffixSize = 4
+else:
+ print "unknown nodename"
+ exit(1)
+
+word1 = nodeName[0 : len(nodeName) - suffixSize]
+word2 = nodeName[- suffixSize:]
+typeName = firstBigLetter(word1) + firstBigLetter(word2)
+fileName = word1 + "_" + word2
+nodeInclude = ""
+if dirName != "":
+ guardHeader = (dirName + "_" + nodeName).upper()
+ baseName = dirName
+ baseTypeName = firstBigLetter(dirName)
+ nodeInclude = dirName + "/" + fileName
+else:
+ guardHeader = nodeName.upper()
+ baseName = "node"
+ baseTypeName = "Node"
+ nodeInclude = fileName
+
+writeFile("../src/nodes/{0}/{1}.h".format(dirName, fileName),
+ nodeTemplate.format(guardHeader, baseName, typeName, baseTypeName))
+writeFile("../src/parsers/{0}/{1}.cpp".format(dirName, fileName),
+ parserTemplate.format(typeName, nodeInclude, parserBaseInclude, parserAdditionalCode1, parserAdditionalCode2))
+
+#print nodeTemplate.format(guardHeader, baseName, typeName, baseTypeName)
+#print parserTemplate.format(typeName, nodeInclude, parserBaseInclude, parserAdditionalCode1, parserAdditionalCode2)
diff --git a/scripts/tpl/node.tpl b/scripts/tpl/node.tpl
new file mode 100644
index 0000000..30783a5
--- /dev/null
+++ b/scripts/tpl/node.tpl
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2015 Andrei Karas
+ *
+ * This file is part of AstDumper.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef NODES_{0}NODE_H
+#define NODES_{0}NODE_H
+
+#include "nodes/base/{1}.h"
+
+#include <string>
+
+struct {2}Node : public {3}Node
+{{
+ {2}Node() :
+ {3}Node()
+ {{
+ }}
+}};
+
+#endif // NODES_{0}NODE_H
diff --git a/scripts/tpl/parser.tpl b/scripts/tpl/parser.tpl
new file mode 100644
index 0000000..b5fb927
--- /dev/null
+++ b/scripts/tpl/parser.tpl
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2015 Andrei Karas
+ *
+ * This file is part of AstDumper.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "parsers/parserincludes.h"
+
+parserDefine({0});
+
+{2}
+#include "nodes/{1}.h"
+
+namespace Generic
+{{
+
+void parse{0}Node({0}Node *node)
+{{
+ fillType(node);
+{3} Log::log(node);
+{4}}}
+
+}}