00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __NEDCOMPILER_H
00018 #define __NEDCOMPILER_H
00019
00020 #include <map>
00021 #include <vector>
00022 #include <string>
00023 #include "nedelements.h"
00024
00025
00026 struct ltstr
00027 {
00028 bool operator()(const char* s1, const char* s2) const {return strcmp(s1,s2)<0;}
00029 };
00030 typedef std::map<const char *,NEDElement *,ltstr> NEDMap;
00031
00032 typedef std::vector<std::string> NEDStringVector;
00033
00034
00042 class NEDFileCache
00043 {
00044 protected:
00045 NEDMap importedfiles;
00046
00047 public:
00048 NEDFileCache();
00049 ~NEDFileCache();
00050 void addFile(const char *name, NEDElement *node);
00051 NEDElement *getFile(const char *name);
00052 };
00053
00054
00061 class NEDSymbolTable
00062 {
00063 protected:
00064
00065 NEDMap channels;
00066 NEDMap modules;
00067 NEDMap networks;
00068
00069
00070 NEDMap enums;
00071 NEDMap classes;
00072
00073 public:
00074 NEDSymbolTable();
00075 ~NEDSymbolTable();
00076
00077 void add(NEDElement *node);
00078 NEDElement *getChannelDeclaration(const char *name);
00079 NEDElement *getModuleDeclaration(const char *name);
00080 NEDElement *getNetworkDeclaration(const char *name);
00081 NEDElement *getEnumDeclaration(const char *name);
00082 NEDElement *getClassDeclaration(const char *name);
00083 };
00084
00085
00091 class NEDImportResolver
00092 {
00093 public:
00094 NEDImportResolver() {}
00095 virtual ~NEDImportResolver() {}
00096 virtual NEDElement *loadImport(const char *import) = 0;
00097 };
00098
00099
00107 class NEDClassicImportResolver : public NEDImportResolver
00108 {
00109 protected:
00110 NEDStringVector importpath;
00111 public:
00112 NEDClassicImportResolver() {}
00113 virtual ~NEDClassicImportResolver() {}
00114 void addImportPath(const char *dir);
00115 virtual NEDElement *loadImport(const char *import);
00116 };
00117
00118
00131 class NEDCompiler
00132 {
00133 protected:
00134 NEDMap imports;
00135
00136 NEDFileCache *filecache;
00137 NEDSymbolTable *symboltable;
00138 NEDImportResolver *importresolver;
00139
00140 void addImport(const char *name);
00141 bool isImported(const char *name);
00142 void doValidate(NEDElement *tree);
00143
00144 public:
00148 NEDCompiler(NEDFileCache *fcache, NEDSymbolTable *symtab, NEDImportResolver *importres);
00149
00153 virtual ~NEDCompiler();
00154
00158 void validate(NEDElement *tree);
00159 };
00160
00161 #endif
00162