Eneboo - Documentación para desarrolladores
src/qsa/src/engine/qscheck.h
Ir a la documentación de este archivo.
00001 /****************************************************************************
00002 ** $Id: qscheck.h  1.1.5   edited 2006-02-23T15:39:57$
00003 **
00004 ** Copyright (C) 2001-2006 Trolltech AS.  All rights reserved.
00005 **
00006 ** This file is part of the Qt Script for Applications framework (QSA).
00007 **
00008 ** This file may be distributed and/or modified under the terms of the
00009 ** GNU General Public License version 2 as published by the Free Software
00010 ** Foundation and appearing in the file LICENSE.GPL included in the
00011 ** packaging of this file.
00012 **
00013 ** Licensees holding a valid Qt Script for Applications license may use
00014 ** this file in accordance with the Qt Script for Applications License
00015 ** Agreement provided with the Software.
00016 **
00017 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00018 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00019 **
00020 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
00021 **   information about QSA Commercial License Agreements.
00022 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00023 **
00024 ** Contact info@trolltech.com if any conditions of this licensing are
00025 ** not clear to you.
00026 **
00027 *****************************************************************************/
00028 
00029 #ifndef QSCHECK_H
00030 #define QSCHECK_H
00031 
00032 #include "qsclass.h"
00033 #include "qserrors.h"
00034 #include <qstringlist.h>
00035 #include <qvaluelist.h>
00036 #include <qmap.h>
00037 
00038 class QSNode;
00039 class QSScopeResolution;
00040 class QSFuncDeclNode;
00041 
00042 typedef QMap<QString, QSClass*> QSTypeMap;
00043 typedef QValueList<QSScopeResolution> QSScopeResolutionList;
00044 
00045 class QSScopeResolution
00046 {
00047 public:
00048     enum ScopeType { PackageScope,
00049                      ClassScope,
00050                      FunctionScope,
00051                      BlockScope,
00052                      GlobalScope,
00053                      EvalScope,
00054                      UndefinedScope };
00055 
00056     QSScopeResolution() : type( UndefinedScope ), cl( 0 ) { }
00057     QSScopeResolution( QSClass * c ) : type( ClassScope ), cl( c ) { }
00058     QSScopeResolution( QSFunctionScopeClass * f ) : type( FunctionScope ), cl( f ) { }
00059     QSScopeResolution( QSGlobalClass * g ) : type( GlobalScope ), cl( g ) { }
00060     QSScopeResolution( QSBlockScopeClass *b ) : type( BlockScope ), cl( b ) { }
00061     QSScopeResolution( QSEvalScopeClass * c ) : type( EvalScope ), cl( c ) { }
00062 
00063 
00064     QString name() const { return cl->identifier(); }
00065     bool isPackageScope() const { return type==PackageScope; }
00066     bool isClassScope() const { return type==ClassScope; }
00067     bool isFunctionScope() const { return type==FunctionScope; }
00068     bool isGlobalScope() const { return type==GlobalScope; }
00069     bool isBlockScope() const { return type==BlockScope; }
00070 
00071     ScopeType type;
00072     QSClass * cl;
00073 
00074 };
00075 
00076 class QSCheckData {
00077 public:
00078     QSCheckData( QSEnv *e, QSGlobalClass *g = 0 );
00079     ~QSCheckData();
00080 
00081     QSEnv *env() const { return currenv; }
00082 
00083     void enterEval( QSEvalScopeClass * c ) { scopeStack.push_front( c ); }
00084     void leaveEval() { scopeStack.pop_front(); }
00085 
00086     void enterClass( QSClass *c );
00087     void leaveClass();
00088     bool insideClass( const QString &name ) const;
00089     void registerType( QSClass *c );
00090     QSClass *typeInfo( const QString &name ) const;
00091 
00092     void enterFunction( QSFunctionScopeClass * c );
00093     void leaveFunction();
00094 
00095     void pushLabel( const QString &label ) { lablist.push_front( label ); }
00096     void popLabel() { lablist.pop_front(); }
00097     void setLabel( const QString &label );
00098     QString currentLabel() const;
00099     bool seenLabel( const QString &label ) const;
00100     void clearLabel();
00101 
00102     void enterBlock( QSBlockScopeClass * cl );
00103     void leaveBlock();
00104 
00105     void enterLoop( const QString &label = QString::null );
00106     void leaveLoop();
00107 
00108     void enterSwitch();
00109     void leaveSwitch();
00110 
00111     void enterPackage( const QString &name );
00112     void leavePackage();
00113 
00114     bool inGlobal() const;
00115     bool inClass() const;
00116     bool inFunction() const;
00117     bool inLoop() const;
00118     bool inSwitch() const;
00119     bool inPackage() const;
00120     bool canReturn() const;
00121 
00122     QSClass * innermostClass() const;
00123 
00124     QSClass * currentClass() const;
00125     QSFunctionScopeClass * currentFunction() const;
00126     QSClass * currentScope() const;
00127 
00128     void addError( const QSNode *node,
00129                    QSErrorCode code, const QString &msg );
00130     void addError( const QSNode *node, const QString &msg );
00131     void addWarning( const QSNode *node,
00132                      QSErrorCode code, const QString &msg );
00133     void addWarning( const QSNode *node, const QString &msg );
00134 
00135     bool hasError() const;
00136     QSErrorCode errorCode() const;
00137     QValueList<uint> errorLines() const;
00138     QStringList errorMessages() const;
00139 
00140     int lastAttributes() const { return lattrs; }
00141     void setLastAttributes( int a ) { lattrs = a; }
00142 
00143     QSClass *lastType() const { return ltype; }
00144     void setLastType( QSClass *t ) { ltype = t; }
00145 
00146     // configuration options
00147     bool globalStatementsForbidden() const { return (bool)noGlobStatements; }
00148     void setGlobalStatementsForbidden( bool f ) { noGlobStatements = f; }
00149 
00150     QString globalName( const QString &name ) const;
00151 
00152     int varBlockCount() const { return vbCount; }
00153     void setVarBlockCount( int ct ) { vbCount = ct; }
00154 
00155     void setDirectLookupEnabled( bool en ) { directLookup = en; }
00156     bool directLookupEnabled() { return directLookup; }
00157 
00158 private:
00159     QSEnv *currenv;
00160     //    QString currfunc;
00161     QString currpack;   // current package definition name
00162     QString lastlab;            // last label seen
00163     QStringList lablist;        // list of label for iteration statements
00164     //    QStringList flist;
00165     QSTypeMap tmap;
00166     QSScopeResolutionList scopeStack;
00167 
00168     // last something
00169     int lattrs;
00170     QSClass *ltype;
00171     int vbCount;
00172     int switchLevel;
00173 
00174     QValueList<QSErrorCode> ecodes;
00175     QValueList<uint> elines;
00176     QStringList emsgs;
00177 
00178     uint noGlobStatements : 1;
00179     uint directLookup : 1;
00180 };
00181 
00182 inline bool QSCheckData::inClass() const
00183 {
00184     return scopeStack.size()>0 && scopeStack.first().isClassScope();
00185 }
00186 
00187 inline bool QSCheckData::inFunction() const
00188 {
00189     return scopeStack.size()>0 && scopeStack.first().isFunctionScope();
00190 }
00191 
00192 inline bool QSCheckData::inLoop() const
00193 {
00194     return !lablist.isEmpty();
00195 }
00196 
00197 inline bool QSCheckData::inSwitch() const
00198 {
00199     return switchLevel>0;
00200 }
00201 
00202 inline bool QSCheckData::inPackage() const
00203 {
00204     return !currpack.isEmpty();
00205 }
00206 
00207 inline bool QSCheckData::hasError() const
00208 {
00209     return !ecodes.isEmpty();
00210 }
00211 
00212 inline QSErrorCode QSCheckData::errorCode() const
00213 {
00214     return ecodes.first();
00215 }
00216 
00217 inline QValueList<uint> QSCheckData::errorLines() const
00218 {
00219     return elines;
00220 }
00221 
00222 inline QStringList QSCheckData::errorMessages() const
00223 {
00224     return emsgs;
00225 }
00226 
00227 #endif
00228 
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'