- Main Page
- Modules
- Classes
- Files
- Directories

- File List
- File Members

# nedcompiler.h

Go to the documentation of this file.

    00001 //==========================================================================
    00002 // nedcompiler.h -
    00003 //
    00004 //                     OMNeT++/OMNEST
    00005 //            Discrete System Simulation in C++
    00006 //
    00007 // Contents:
    00008 //   class NEDCompiler
    00009 //
    00010 //==========================================================================
    00011
    00012 /*--------------------------------------------------------------*
    00013   Copyright (C) 2002-2005 Andras Varga
    00014
    00015   This file is distributed WITHOUT ANY WARRANTY. See the file
    00016   `license' for details on this and other legal matters.
    00017 *--------------------------------------------------------------*/
    00018
    00019
    00020 #ifndef __NEDCOMPILER_H
    00021 #define __NEDCOMPILER_H
    00022
    00023 #include <map>
    00024 #include <vector>
    00025 #include <string>
    00026 #include "nedelements.h"
    00027
    00028
    00029 struct ltstr
    00030 {
    00031   bool operator()(const char* s1, const char* s2) const  {return strcmp(s1,s2)<0;}
    00032 };
    00033 typedef std::map<const char *,NEDElement *,ltstr> NEDMap;
    00034
    00035 typedef std::vector<std::string> NEDStringVector;
    00036
    00037
    00045 class NEDFileCache
    00046 {
    00047   protected:
    00048     NEDMap importedfiles;
    00049
    00050   public:
    00052     NEDFileCache();
    00053
    00055     ~NEDFileCache();
    00056
    00058     void addFile(const char *name, NEDElement *node);
    00059
    00061     NEDElement *getFile(const char *name);
    00062 };
    00063
    00064
    00071 class NEDSymbolTable
    00072 {
    00073   protected:
    00074     // hash tables for channel, module and network declarations:
    00075     NEDMap channels;
    00076     NEDMap modules;
    00077     NEDMap networks;
    00078
    00079     // subclassing: enums, classes, messages, objects
    00080     NEDMap enums;
    00081     NEDMap classes;
    00082
    00083   public:
    00085     NEDSymbolTable();
    00086
    00088     ~NEDSymbolTable();
    00089
    00095     void add(NEDElement *node);
    00096
    00100     NEDElement *getChannelDeclaration(const char *name);
    00101
    00103     NEDElement *getModuleDeclaration(const char *name);
    00104
    00106     NEDElement *getNetworkDeclaration(const char *name);
    00107
    00109     NEDElement *getEnumDeclaration(const char *name);
    00110
    00112     NEDElement *getClassDeclaration(const char *name);
    00114 };
    00115
    00116
    00122 class NEDImportResolver
    00123 {
    00124   public:
    00126     NEDImportResolver() {}
    00127
    00129     virtual ~NEDImportResolver() {}
    00130
    00134     virtual NEDElement *loadImport(const char *import) = 0;
    00135 };
    00136
    00137
    00145 class NEDClassicImportResolver : public NEDImportResolver
    00146 {
    00147   protected:
    00148     NEDStringVector importpath;
    00149
    00150   public:
    00152     NEDClassicImportResolver() {}
    00153
    00155     virtual ~NEDClassicImportResolver() {}
    00156
    00160     void addImportPath(const char *dir);
    00161
    00165     virtual NEDElement *loadImport(const char *import);
    00166 };
    00167
    00168
    00186 class NEDCompiler
    00187 {
    00188   protected:
    00189     NEDMap imports;  // list of already imported modules (to avoid double importing)
    00190
    00191     NEDFileCache *filecache;
    00192     NEDSymbolTable *symboltable;
    00193     NEDImportResolver *importresolver;
    00194
    00195     void addImport(const char *name);
    00196     bool isImported(const char *name);
    00197     void doValidate(NEDElement *tree);
    00198
    00199   public:
    00201     NEDCompiler(NEDFileCache *fcache, NEDSymbolTable *symtab, NEDImportResolver *importres);
    00202
    00204     virtual ~NEDCompiler();
    00205
    00210     void validate(NEDElement *tree);
    00211 };
    00212
    00213 #endif
    00214