示例#1
0
        public Module load()
        {
            Module module = null;

            try
            {
                globalSymbols = new Dictionary <string, Declaration>();
                localSymbols  = new Dictionary <string, Declaration>();

                oilcan = EnamlData.loadFromFile(filename);

                string oilVersion = oilcan.getStringValue("OILCan.version", "");
                string modname    = oilcan.getStringValue("module.name", "");

                module = new Module(modname);

                List <String> funcs = oilcan.getPathKeys("module.funcs");
                foreach (String funcname in funcs)
                {
                    FuncDefNode func = loadFuncDef("module.funcs." + funcname);
                    module.funcs.Add(func);
                    globalSymbols[funcname] = func;
                }
            }
            catch (ENAMLException e)
            {
                return(null);
            }

            return(module);
        }
示例#2
0
        //- writing declarations ------------------------------------

        public void saveFuncDef(int fnum, FuncDefNode func)
        {
            string fname = "module.funcs." + func.OILname;

            oilcan.setStringValue(fname + ".name", func.name);
            saveTypeDecl(fname + ".return-type", func.returnType);

            string pname = fname + ".params.";
            int    pnum  = 0;

            foreach (ParamDeclNode param in func.paramList)
            {
                saveParamDecl(pname + param.OILname, param);
                pnum++;
            }

            string lname = fname + ".locals.";
            int    lnum  = 0;

            foreach (VarDeclNode local in func.locals)
            {
                saveVarDecl(lname + local.OILname, local);
                lnum++;
            }

            string bname = fname + ".body";

            saveStatementList(bname, func.body);
        }
示例#3
0
        //- reading declarations ------------------------------------

        public FuncDefNode loadFuncDef(String path)
        {
            localSymbols.Clear();
            FuncDefNode func = new FuncDefNode();

            func.name       = oilcan.getStringValue(path + ".name", "");
            func.returnType = loadTypeDecl(path + ".return-type");

            List <String> paramnames = oilcan.getPathKeys(path + ".params");

            foreach (String pname in paramnames)
            {
                ParamDeclNode p = loadParamDecl(path + ".params." + pname);
                func.paramList.Add(p);
                localSymbols[pname] = p;
            }

            List <String> localnames = oilcan.getPathKeys(path + ".locals");

            foreach (String lname in localnames)
            {
                VarDeclNode l = loadVarDecl(path + ".locals." + lname);
                func.locals.Add(l);
                localSymbols[lname] = l;
            }

            func.body = loadStatementList(path + ".body");

            return(func);
        }
示例#4
0
        public void generateFunctionNames(FuncDefNode func)
        {
            for (int pnum = 0; pnum < func.paramList.Count; pnum++)
            {
                func.paramList[pnum].OILname = "p" + pnum.ToString();
            }

            for (int lnum = 0; lnum < func.locals.Count; lnum++)
            {
                func.locals[lnum].OILname = "l" + lnum.ToString();
            }
        }