예제 #1
0
 public void Accept(UseNode node)
 {
 }
예제 #2
0
        public void Accept(UseNode node)
        {
            string name = node.GetName();
            string path = locateFile(name, ".has");
            if (path == string.Empty)
                path = locateFile(name, ".dll");
            HassiumObject mod;
            if (path.EndsWith(".dll"))
            {
                importModules(path);
            module.Imports.Add(path);
                return;
            }
            else if (path != string.Empty)
            {
                mod = CompileModuleFromSource(File.ReadAllText(path));
                module.Imports.Add(path);
            }
            else if (InternalModule.InternalModules.ContainsKey(name))
            {
                mod = InternalModule.InternalModules[name];
                module.Imports.Add(name);
            }
            else
                throw new CompileException(node.SourceLocation, "Could not find path or module for use \"{0}\"!", name);

            foreach (var pair in mod.Attributes)
            {
                if (module.Attributes.ContainsKey(pair.Key))
                    module.Attributes.Remove(pair.Key);
                module.Attributes.Add(pair.Key, pair.Value);
            }
            if (mod is HassiumModule)
            {
                foreach (var constant in ((HassiumModule)mod).ConstantPool)
                {
                    if (module.ConstantPool.ContainsKey(constant.Key))
                        module.ConstantPool.Remove(constant.Key);
                    module.ConstantPool.Add(constant.Key, constant.Value);
                }
                foreach (var obj in ((HassiumModule)mod).ObjectPool)
                {
                    if (module.ObjectPool.ContainsKey(obj.Key))
                        module.ObjectPool.Remove(obj.Key);
                    module.ObjectPool.Add(obj.Key, obj.Value);
                }
            }
        }