From: Konrad Rosenbaum Date: Mon, 2 Jan 2017 12:14:23 +0000 (+0100) Subject: pattern prototype X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2Fpatternwip;p=web%2Fkonrad%2Fpack.git pattern prototype --- diff --git a/.gitignore b/.gitignore index 512b7db..5c1d289 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,10 @@ vinfo .ptmp qtbase/Makefile* woc/Makefile* +woc/tclbase.qrc +woc/tclbasegen/Makefile +woc/tclbasegen/tbg +woc/tclbasegen/tbg.exe doc/*base doc/woc *.tag @@ -27,3 +31,5 @@ examples/clock/qtc/clock examples/clock/qts/clockserv examples/clock/qtc/clock.exe examples/clock/qts/clockserv.exe +woc/qrcgen/Makefile +woc/qrcgen/qrcgen diff --git a/Makefile b/Makefile index f4ab98c..c293ef1 100644 --- a/Makefile +++ b/Makefile @@ -23,12 +23,15 @@ all: prewoc woc qtbase doc .PHONY: prewoc woc qtbase doc clean install install-woc install-qtbase install-phpbase install-doc -vinfo/staticVersion.h prewoc: +woc/tclbase.qrc woc/patterns.qrc: + cd woc/qrcgen && $(QMAKE) && $(MAKE) && $(abspath woc/qrcgen/qrcgen) ../tclbase:tclbase:tclbase.qrc pattern:pattern:patterns.qrc + +vinfo/staticVersion.h prewoc: woc/patterns.qrc cd woc && $(QMAKE) -o Makefile.prewoc CONFIG+=prewoc $(MAKE) -C woc -f Makefile.prewoc cd woc && $(abspath woc/prewoc) :/version.wolf -woc: vinfo/staticVersion.h +woc: vinfo/staticVersion.h woc/tclbase.qrc woc/patterns.qrc cd woc && $(QMAKE) CONFIG+=woc $(MAKE) -C woc diff --git a/tclbase/wobbase.tcl b/tclbase/wobbase.tcl new file mode 100644 index 0000000..b8ae046 --- /dev/null +++ b/tclbase/wobbase.tcl @@ -0,0 +1 @@ +#!/bin/tclsh diff --git a/woc/generic/generic.pri b/woc/generic/generic.pri new file mode 100644 index 0000000..931e2b1 --- /dev/null +++ b/woc/generic/generic.pri @@ -0,0 +1,11 @@ +SOURCES+= \ + generic/genproc.cpp \ + generic/genout.cpp \ + generic/genfile.cpp + +HEADERS+= \ + generic/genproc.h \ + generic/genout.h \ + generic/genfile.h + +INCLUDEPATH += generic diff --git a/woc/generic/genfile.cpp b/woc/generic/genfile.cpp new file mode 100644 index 0000000..0678131 --- /dev/null +++ b/woc/generic/genfile.cpp @@ -0,0 +1,76 @@ +// Copyright (C) 2016 by Konrad Rosenbaum +// protected under the GNU GPL version 3 or at your option any newer. +// See COPYING.GPL file that comes with this distribution. +// + +#include "genfile.h" +#include "genout.h" + +WocGenericVariables::~WocGenericVariables(){} + +static const QRegExp validVarName("[a-zA-Z_](([a-zA-Z0-9_:.-]*[a-zA-Z0-9_])?)"); + +bool WocSimpleVariables::isValidName(QString name) +{ + return validVarName.exactMatch(name); +} + + + +WocGenericFile::WocGenericFile(WocGenericFile::FileType type, QString pattern, WocGenericVariables*globalvars) + : QObject(), mfiletype(type), mfilepattern(pattern), mglobalvars(globalvars) +{ +} + +WocGenericFile::~WocGenericFile() +{ + closeFile(); +} + +void WocGenericFile::closeFile() +{ + if(mcurrentfile){ + mcurrentfile->close(); + delete mcurrentfile; + mcurrentfile=nullptr; + } +} + +void WocGenericFile::setPatternFile(QString patternfilename) +{ + QFile fd(patternfilename); + //TODO: error handling + fd.open(QIODevice::ReadOnly); + + //get split comment + + //parse file + ...parse +} + +void WocGenericFile::createNewFile(QString basename) +{ + closeFile(); + QString fn=mfilepattern; + fn.replace('*',basename); + mcurrentfile=new MFile(fn); + //TODO: error handling! + mcurrentfile->open(QIODevice::WriteOnly|QIODevice::Truncate); +} + +void WocGenericFile::startProject() +{ + if(mfiletype!=FileType::Global)return; + WocSimpleVariables vars(mglobalvars); + createNewFile(QString()); +} + +void WocGenericFile::endProject() +{ + closeFile(); +} + +void WocGenericFile::newClass() +{ + +} diff --git a/woc/generic/genfile.h b/woc/generic/genfile.h new file mode 100644 index 0000000..5985099 --- /dev/null +++ b/woc/generic/genfile.h @@ -0,0 +1,90 @@ +// Copyright (C) 2016 by Konrad Rosenbaum +// protected under the GNU GPL version 3 or at your option any newer. +// See COPYING.GPL file that comes with this distribution. +// + +#ifndef WOC_GENERICFILE_H +#define WOC_GENERICFILE_H + +#include +#include "../mfile.h" + +class WocGenericOut; +class WocGenericVariables +{ +public: + explicit WocGenericVariables(WocGenericVariables*parent=nullptr):mparent(parent){} + virtual ~WocGenericVariables(); + + virtual QString getVariable(QString name)=0; + virtual bool setVariable(QString name,QString value) + { + Q_UNUSED(name);Q_UNUSED(value); + return false; + } + +protected: + WocGenericVariables*mparent=nullptr; +}; + +class WocGenericFile:public QObject +{ + Q_OBJECT +public: + enum class FileType{ + Global, + Class, + Transaction, + Table + }; + WocGenericFile(FileType type,QString namepattern,WocGenericVariables*globalvars); + virtual ~WocGenericFile(); +public slots: + void setPatternFile(QString patternfilename); + void startProject(); + void endProject(); + void newClass(); +private: + MFile*mcurrentfile=nullptr; + FileType mfiletype; + QString mfilepattern; + WocGenericVariables*mglobalvars; + QMapmsections; + + void createNewFile(QString basename); + void closeFile(); +}; + +class WocProjectVariables:public WocGenericVariables +{ +public: + explicit WocProjectVariables(WocGenericOut*); + + QString getVariable(QString)override; +}; + +class WocSimpleVariables:public WocGenericVariables +{ +public: + explicit WocSimpleVariables(WocGenericVariables*parent):WocGenericVariables(parent){} + + QString getVariable(QString name)override + { + if(mvars.contains(name))return mvars[name]; + else return mparent->getVariable(name); + } + + bool setVariable(QString name,QString value)override + { + if(!isValidName(name))return false; + mvars.insert(name,value); + return true; + } +private: + QMapmvars; + + static bool isValidName(QString); +}; + + +#endif diff --git a/woc/generic/genout.cpp b/woc/generic/genout.cpp new file mode 100644 index 0000000..c2176e6 --- /dev/null +++ b/woc/generic/genout.cpp @@ -0,0 +1,74 @@ +// Copyright (C) 2016 by Konrad Rosenbaum +// protected under the GNU GPL version 3 or at your option any newer. +// See COPYING.GPL file that comes with this distribution. +// + +#include "genout.h" + +#include +#include + +#define QT_OUT_NO_WRAP +#include "doxyout.h" + +WocGenericOut::WocGenericOut(PatternDir pattern, const QDomElement&el) +{ + qDebug("Info: creating %s Generator.",el.tagName().toLatin1().data()); + m_basedir=WocProcessor::instance()->baseDir()+"/"+el.attribute("sourceDir","."); + m_subdir=el.attribute("subDir","wob"); + m_clean=str2bool(el.attribute("clean","0")); + m_transbase=el.attribute("transactionBase","::wob::WTransaction"); + m_namespace=el.attribute("namespace","::"); + if(!m_namespace.startsWith("::"))m_namespace="::"+m_namespace; + //get/create directory + QDir d(m_basedir+"/"+m_subdir); + if(!d.exists())QDir(".").mkpath(m_basedir+"/"+m_subdir); +} + +WocGenericOut::~WocGenericOut(){} + +void WocGenericOut::finalize() +{ + //finish sub-classes +// if(tclass)tclass->finalize(); +// if(ttrans)ttrans->finalize(); + //generate versionInfo + initVersion(); +} + +void WocGenericOut::newClass(const WocClass&cls) +{ +// if(tclass)tclass->newClass(cls); +} + +void WocGenericOut::newTransaction(const WocTransaction&trn) +{ +// if(ttrans)ttrans->newTransaction(trn); +} + +void WocGenericOut::addFile(QString fn) +{ + QString code=QString("source [file join [file dirname [info script]] %1\n").arg(fn); + m_hdr.write(code.toLatin1()); +} + + + + +#ifndef NO_PACK_VERSION_H +#include "../../vinfo/staticVersion.h" +#endif + +static inline QString escapeStr(QString s) +{ + return s.replace("\\","\\\\").replace("\"","\\\"").replace("\n","\\n"); +} + +void WocGenericOut::initVersion() +{ +} + +void WocGenericOut::addIfaceImpl ( const QString& s ) +{ +} + diff --git a/woc/generic/genout.h b/woc/generic/genout.h new file mode 100644 index 0000000..db6b109 --- /dev/null +++ b/woc/generic/genout.h @@ -0,0 +1,79 @@ +// Copyright (C) 2016 by Konrad Rosenbaum +// protected under the GNU GPL version 3 or at your option any newer. +// See COPYING.GPL file that comes with this distribution. +// + +#ifndef WOC_GENERICOUT_H +#define WOC_GENERICOUT_H + +#include + +#include "processor.h" + +#include "mfile.h" + +#include "genproc.h" + +class QDomElement; + +class WocGenericOut; + +///Abstract base class for Generic client and server output. +///This class controls the main include files and uses helpers to generate +///transactions, classes and tables. +/// +///It generates the interface class, a .pri-file and an include-all file. +class WocGenericOut:public WocOutput +{ + public: + ///creates a Generic output object from the corresponding XML tag + ///that specifies what kind of output is desired. + explicit WocGenericOut(PatternDir pattern,const QDomElement&); + ///deletes the output object + ~WocGenericOut(); + + ///adds code to the implementation file of the interface class + void addIfaceImpl(const QString&); + + protected: + ///overloaded slot, called when parsing is finished + virtual void finalize()override; + ///overloaded slot, called for each new class + virtual void newClass(const WocClass&)override; + ///overloaded slot, called for each new transaction + virtual void newTransaction(const WocTransaction&)override; + ///overloaded slot, dummy + virtual void newTable(const WocTable&)override{} + + public: + /**helper: adds a file to the project file + \param basename the file name to add*/ + void addFile(QString basename); + + ///returns the language output spec + inline QString languageSpec()const{return m_lang;} + ///returns the base directory of the project + inline QString baseDir()const{return m_basedir;} + ///returns the sub directory relative to the project where to store files + inline QString subDir()const{return m_subdir;} + ///returns the complete path for files, baseDir()+subDir() + inline QString destinationPath()const{return m_basedir+"/"+m_subdir;} + ///returns the base class of all transactions + inline QString transactionBase()const{return m_transbase;} + ///returns the namespace + inline QString nameSpace()const{return m_namespace;} + + private: + ///internal: generate the static header for version info + void initVersion(); + + private: + QString m_basedir,m_subdir,m_transbase,m_postiface,m_scriptcode,m_namespace; + mutable QString m_exportsym; + bool m_clean; + MFile m_iface,m_hdr; + protected: + QString m_lang; +}; + +#endif diff --git a/woc/generic/genproc.cpp b/woc/generic/genproc.cpp new file mode 100644 index 0000000..df6ce1f --- /dev/null +++ b/woc/generic/genproc.cpp @@ -0,0 +1,69 @@ +// Copyright (C) 2016 by Konrad Rosenbaum +// protected under the GNU GPL version 3 or at your option any newer. +// See COPYING.GPL file that comes with this distribution. +// + +#include "genproc.h" +#include "genout.h" + +#include +#include +#include + +// pattern map: tag => pattern +static QMap genmap; + +void WalkPattern(QString dir,QString tname=QString()) +{ + // recurse into sub-dirs + for(auto entry:QDir(dir).entryInfoList(QDir::AllDirs)){ + if(entry.fileName()=="." || entry.fileName()=="..")continue; + if(entry.isDir()) + WalkPattern(entry.absoluteFilePath(),tname+"/"+entry.fileName()); + } + + // check whether this is a pattern dir + QFileInfo info(dir+"/meta.txt"); + if(!info.exists() || !info.isFile() || !info.isReadable())return; + PatternDir pat; + pat.patterntype=tname; + pat.dirname=dir; + //parse meta and find tag name + QFile fd(info.absoluteFilePath()); + if(!fd.open(QIODevice::ReadOnly)){ + qDebug()<<"Error: cannot read pattern meta file"< +// protected under the GNU GPL version 3 or at your option any newer. +// See COPYING.GPL file that comes with this distribution. +// + +#ifndef WOC_GENPROC_H +#define WOC_GENPROC_H + +#include "processor.h" +#include + +class QDomElement; + +//pattern descriptions +struct PatternDir{ + QString tagname,patterntype,dirname; +}; + + + +///Scans a directory and looks for valid patterns. +void InitializeGeneric(QString dirs=QString()); + +///Creates the generic pattern based output object based on a tag name. +bool CreateGenericOutput(QString tagname,const QDomElement&); + +#endif diff --git a/woc/pattern/qt5/client/class-include b/woc/pattern/qt5/client/class-include new file mode 100644 index 0000000..4dad7c2 --- /dev/null +++ b/woc/pattern/qt5/client/class-include @@ -0,0 +1,2 @@ +//-- prolog +#include "src${filename}.h" diff --git a/woc/pattern/qt5/client/export b/woc/pattern/qt5/client/export new file mode 100644 index 0000000..749b084 --- /dev/null +++ b/woc/pattern/qt5/client/export @@ -0,0 +1,25 @@ +//=============================== +//== defines the export Macro +//=============================== +//-- prolog +//BEGIN OF AUTOMATICALLY GENERATED FILE +//DO NOT EDIT THIS FILE DIRECTLY, USE THE XML SOURCE! +#ifndef ${includeGuard} +#define ${includeGuard} + +//=============================== +//-- epilog + +//END OF AUTOMATICALLY GENERATED FILE +#endif +//=============================== +//-- post-prolog?enableExport + +#ifndef ${exportmacro} +#define ${exportmacro} Q_DECL_IMPORT +#endif + +//-- post-prolog?!enableExport +#ifndef ${exportmacro} +#define ${exportmacro} +#endif diff --git a/woc/pattern/qt5/client/includeAll b/woc/pattern/qt5/client/includeAll new file mode 100644 index 0000000..9690ee0 --- /dev/null +++ b/woc/pattern/qt5/client/includeAll @@ -0,0 +1,22 @@ +//=============================== +//== general include file +//=============================== +//-- prolog +//BEGIN OF AUTOMATICALLY GENERATED FILE +//DO NOT EDIT THIS FILE DIRECTLY, USE THE XML SOURCE! +#ifndef ${includeGuard} +#define ${includeGuard} + +#include "src${allClassPrefix}${interfaceName}.h" + +//=============================== +//-- epilog + +//END OF AUTOMATICALLY GENERATED FILE +#endif +//=============================== +//-- class:prolog +#include "src${classname}.h" +//=============================== +//-- transaction:prolog +#include "src${classname}.h" diff --git a/woc/pattern/qt5/client/interface-header b/woc/pattern/qt5/client/interface-header new file mode 100644 index 0000000..dcf7115 --- /dev/null +++ b/woc/pattern/qt5/client/interface-header @@ -0,0 +1,22 @@ +//=============================== +//== +//=============================== +//-- prolog +//BEGIN OF AUTOMATICALLY GENERATED FILE +//DO NOT EDIT THIS FILE DIRECTLY, USE THE XML SOURCE! +#ifndef ${includeGuard} +#define ${includeGuard} + +#include "exportdef.h" + +class ${exportmacro} ${classname} : public ${interfaceBase} +{ + +//=============================== +//-- epilog + +}; + +//END OF AUTOMATICALLY GENERATED FILE +#endif +//=============================== diff --git a/woc/pattern/qt5/client/interface-include b/woc/pattern/qt5/client/interface-include new file mode 100644 index 0000000..4dad7c2 --- /dev/null +++ b/woc/pattern/qt5/client/interface-include @@ -0,0 +1,2 @@ +//-- prolog +#include "src${filename}.h" diff --git a/woc/pattern/qt5/client/meta.txt b/woc/pattern/qt5/client/meta.txt new file mode 100644 index 0000000..375c993 --- /dev/null +++ b/woc/pattern/qt5/client/meta.txt @@ -0,0 +1,45 @@ +#basic infos +#inherit qt5/none +generator qt5/client +tag Qt5ClientOutput + +#syntax +comment //== +doc-comment /// +out-comment //WOC: +section-start //-- +variable-marker ${ } + +#standard features (token, default, configurable) +feature allClassPrefix C yes +feature classPrefix Obj yes +feature transactionPrefix Trn yes +#feature tablePrefix Tbl +feature interfaceName Interface yes + +#additional configurable features (name, type, default) +addFeature scriptable boolean no +addFeature enableExport boolean yes + +#standard files (type token pattern) [use * for class name pattern] +file class include * +file class header src*.h +file class source src*.cpp +file transaction include * +file transaction header src*.h +file transaction source src*.cpp +#file table include * +#file table header src*.h +#file table source src*.cpp +file interface include * +file interface header src*.h +file interface source src*.cpp +file version header staticVersion.h + +#additional files (token, pattern, configurable, called-for) +addFile pri wob.pri yes all +addFile includeAll {classPrefix}IncludeAll yes all +addFile export exportdef.h no none + +#pre-defined variables (name initial-value|optional-conversion) +variable exportmacro WOBGEN_{Project:name|toUpper}_EXPORT diff --git a/woc/pattern/qt5/client/transaction-include b/woc/pattern/qt5/client/transaction-include new file mode 100644 index 0000000..4dad7c2 --- /dev/null +++ b/woc/pattern/qt5/client/transaction-include @@ -0,0 +1,2 @@ +//-- prolog +#include "src${filename}.h" diff --git a/woc/patterns.qrc b/woc/patterns.qrc new file mode 100644 index 0000000..182d22d --- /dev/null +++ b/woc/patterns.qrc @@ -0,0 +1,12 @@ + + + + +pattern/qt5/client/class-include +pattern/qt5/client/export +pattern/qt5/client/includeAll +pattern/qt5/client/interface-header +pattern/qt5/client/interface-include +pattern/qt5/client/meta.txt +pattern/qt5/client/transaction-include + diff --git a/woc/proc/procclass.cpp b/woc/proc/procclass.cpp index 22a65e9..60bf515 100644 --- a/woc/proc/procclass.cpp +++ b/woc/proc/procclass.cpp @@ -5,9 +5,11 @@ #include "processor.h" -#include "phpout.h" #include "qtout.h" +#ifndef COMPILE_PREWOC +#include "phpout.h" #include "htmlout.h" +#endif #include "domquery.h" diff --git a/woc/proc/processor.cpp b/woc/proc/processor.cpp index f7c6b23..50c50c6 100644 --- a/woc/proc/processor.cpp +++ b/woc/proc/processor.cpp @@ -5,11 +5,14 @@ #include "processor.h" -#include "phpout.h" #include "qtout.h" +#ifndef COMPILE_PREWOC +#include "phpout.h" #include "htmlout.h" #include "schemaout.h" #include "soapout.h" +#include "genproc.h" +#endif #include "domquery.h" @@ -178,6 +181,7 @@ bool WocProcessor::processFile(QString fn) new WocQtClientOut(el); if(m_error)return false; }else +#ifndef COMPILE_PREWOC if(tn=="QtServerOutput"){ new WocQtServerOut(el); if(m_error)return false; @@ -202,6 +206,7 @@ bool WocProcessor::processFile(QString fn) new WocSoapOut(el); if(m_error)return false; }else +#endif if(tn=="Version"){ if(el.hasAttribute("system")) m_verSys=el.attribute("system").split(" ",QString::SkipEmptyParts); @@ -239,8 +244,8 @@ bool WocProcessor::processFile(QString fn) if(tn=="Doc"){ QString s=el.text().trimmed(); if(s!="")m_docstrings< +#include +#include + +#define PROLOG "\n\ +\n\ +\n\n" + +#define EPILOG "\n" + +void writeOut(QFile&out,QString source,QString target) +{ + QDir dir(source); + qDebug()<<"Scanning directory"<%2/%1\n").arg(fn).arg(source).arg(target).toLatin1()); + } +} + +int main(int ac,char**av) +{ + QCoreApplication app(ac,av); + QDir::setCurrent(app.applicationDirPath()+"/.."); + qDebug()<<"Generatin QRCs from"<::", pathspec.toLatin1().data()); + return 1; + } + if(!pathes[2].endsWith(".qrc")){ + qFatal("Pathspec %s is invalid - resource file name must end in .qrc", pathspec.toLatin1().data()); + return 1; + } + QFile out(app.applicationDirPath()+"/../../woc/"+pathes[2]); + if(!out.open(QIODevice::WriteOnly|QIODevice::Truncate)){ + qFatal("Unable to create %s - giving up.", pathes[2].toLatin1().data()); + return 1; + } + out.write(PROLOG); + writeOut(out,pathes[0],pathes[1]); + out.write(EPILOG); + out.close(); + } + return 0; +} diff --git a/woc/qrcgen/qrcgen.pro b/woc/qrcgen/qrcgen.pro new file mode 100644 index 0000000..80f57fd --- /dev/null +++ b/woc/qrcgen/qrcgen.pro @@ -0,0 +1,7 @@ +TEMPLATE = app +TARGET = qrcgen +SOURCES += qrcgen.cpp +DESTDIR = ../qrcgen +QT -= gui +CONFIG += console +CONFIG -= app_bundle diff --git a/woc/woc.cpp b/woc/woc.cpp index 5194b7d..88fdab1 100644 --- a/woc/woc.cpp +++ b/woc/woc.cpp @@ -17,24 +17,32 @@ The Qt back-end is in the "qt" directory with WocQtOut, WocQtClientOut, and WocQ The PHP back-end is in the "php" directory with WocPHPOut, WocPHPClientOut, and WocPHPServerOut as the main output classes. +The generic pattern based back-end is in the "generic" directory with default patterns in the "pattern directory. */ #include #include +#include #include "processor.h" +#include "genproc.h" int main(int argc,char**argv) { QCoreApplication app(argc,argv); + //Initializations + InitializeGeneric(); //get arguments QStringList args=app.arguments(); args.removeFirst(); //process files WocProcessor proc; - for(int i=0;i