Esempio n. 1
0
        public static AST.Range makeRangeForA1(string rng, AST.Env e)
        {
            var addrs = rng.Split(':');

            return(new AST.Range(
                       makeAddressForA1(addrs[0], e),
                       makeAddressForA1(addrs[1], e)
                       ));
        }
Esempio n. 2
0
        public void TestUnion()
        {
            String src = "union MyUnion { int a; int b; } my_union;";
            List<Token> tokens = Parser.GetTokensFromString(src);
            Declaration decln;
            Int32 r = _declaration.Parse(tokens, 0, out decln);

            AST.Env env = new AST.Env();
            Tuple<AST.Env, List<Tuple<AST.Env, AST.Decln>>> r_decln = decln.GetDeclns(env);
        }
Esempio n. 3
0
        public static AST.Range makeUnionRangeFromA1Addrs(string[] addrs, AST.Env e)
        {
            // note that we reverse the array because this is how it is parsed
            var addr_pairs = addrs.Zip(
                addrs,
                (a1, a2) => new Tuple <AST.Address, AST.Address>(makeAddressForA1(a1, e), makeAddressForA1(a2, e))).Reverse().ToArray();
            var addr_pairs_fs = makeFSList <Tuple <AST.Address, AST.Address> >(addr_pairs);

            return(new AST.Range(addr_pairs_fs));
        }
Esempio n. 4
0
        public void TestInt()
        {
            String src = "int a, *b, c(int haha, int), d[];";
            List<Token> tokens = Parser.GetTokensFromString(src);
            Declaration decln;
            Int32 r = _declaration.Parse(tokens, 0, out decln);

            AST.Env env = new AST.Env();
            Tuple<AST.Env, List<Tuple<AST.Env, AST.Decln>>> r_decln = decln.GetDeclns(env);
            //AST.ExprType type = new AST.TDouble(true, true);
            //type = type.GetQualifiedType(false, false);
        }
Esempio n. 5
0
 public static AST.Address makeAddressForA1(string col, int row, AST.Env env)
 {
     return(AST.Address.fromA1withMode(
                row,
                col,
                AST.AddressMode.Relative,
                AST.AddressMode.Relative,
                env.WorksheetName,
                env.WorkbookName,
                env.Path
                ));
 }
Esempio n. 6
0
        public static AST.Address makeAddressForA1(string addr, AST.Env e)
        {
            var r = new System.Text.RegularExpressions.Regex(@"(\$?)([A-Z]+)(\$?)([0-9]+)");

            var matches = r.Match(addr);

            var colMode = String.IsNullOrEmpty(matches.Groups[1].Value) ? AST.AddressMode.Relative : AST.AddressMode.Absolute;
            var col     = matches.Groups[2].Value;
            var rowMode = String.IsNullOrEmpty(matches.Groups[3].Value) ? AST.AddressMode.Relative : AST.AddressMode.Absolute;
            var row     = Convert.ToInt32(matches.Groups[4].Value);

            return(AST.Address.fromA1withMode(row, col, rowMode, colMode, e.WorksheetName, e.WorkbookName, e.Path));
        }
Esempio n. 7
0
        public void TestShadow()
        {
            AST.Env env = new AST.Env();
            env = env.PushEntry(AST.Env.EntryLoc.GLOBAL, "c", new AST.TChar());
            env = env.InScope();
            env = env.PushEntry(AST.Env.EntryLoc.STACK, "c", new AST.TLong());

            String log = env.Dump();
            System.Diagnostics.Debug.WriteLine(log);

            AST.Env.Entry entry = env.Find("c");

            System.Diagnostics.Debug.WriteLine("c : " + entry.entry_loc + " " + entry.entry_type);
        }
Esempio n. 8
0
 /// <summary>
 /// Push a function scope
 /// </summary>
 /// <param name="type"></param>
 public void PushFuncScope(string name, TFunc type, IEnumerable <Tuple <string, T> > parameters, Position pos)
 {
     // Clear the dynamic id.
     dynamicId = 0;
     scopes.Push(new FuncScope(name, string.Format("__{0}_return", name), type));
     ASTEnv = new AST.Env();
     /// Add all the parameter to the environment.
     foreach (var p in parameters)
     {
         scopes.Peek().AddSymbol(new EObj(dynamicId.ToString(), p.Item1, p.Item2, pos, SymbolEntry.Link.NONE, EObj.Storage.AUTO));
         ASTEnv.AddParam(dynamicId.ToString(), p.Item1, p.Item2);
         dynamicId++;
     }
 }
Esempio n. 9
0
        public void TestEnv()
        {
            AST.Env env = new AST.Env();

            env = env.PushEntry(AST.Env.EntryLoc.GLOBAL, "global_var", new AST.TLong());

            env = env.InScope();
            List<Tuple<String, AST.ExprType>> args = new List<Tuple<String, AST.ExprType>>();
            args.Add(new Tuple<String, AST.ExprType>("some_char", new AST.TChar()));
            args.Add(new Tuple<String, AST.ExprType>("another_char", new AST.TChar()));
            args.Add(new Tuple<String, AST.ExprType>("some_double", new AST.TDouble()));
            args.Add(new Tuple<String, AST.ExprType>("another_double", new AST.TDouble()));
            args.Add(new Tuple<String, AST.ExprType>("some_int", new AST.TLong()));
            AST.TFunction func = AST.TFunction.Create(new AST.TVoid(), args, false);
            AST.Env env2 = env.SetCurrentFunction(func);

            String log = env.Dump();
            System.Diagnostics.Debug.WriteLine(log);
        }
Esempio n. 10
0
 /// <summary>
 /// Initialize the environment with the file scope.
 /// </summary>
 public Env()
 {
     scopes = new Stack <Scope>();
     scopes.Push(new Scope(ScopeKind.FILE));
     IsFuncDef   = false;
     IsFuncParam = false;
     ASTEnv      = new AST.Env();
     loopId      = 0;
     ifId        = 0;
     condId      = 0;
     switchId    = 0;
     caseId      = 0;
     defaultId   = 0;
     staticId    = 0;
     dynamicId   = 0;
     logicalId   = 0;
     strId       = 0;
     realId      = 0;
     breakables  = new Stack <Breakable>();
 }
Esempio n. 11
0
        private FSharpOption <BugClass> DualsFor(AST.Address addr)
        {
            // extract address environment
            var env = new AST.Env(addr.Path, addr.WorkbookName, addr.WorksheetName);

            // duals regexp
            var r = new Regex(@".*dual\s*=\s*((?<AddrOrRange>[A-Z]+[0-9]+(:?:[A-Z]+[0-9]+)?)(:?\s*,\s*)?)+", RegexOptions.Compiled);

            // get note for this address
            var note = _notes[addr];

            Match m = r.Match(note);

            if (!m.Success)
            {
                if (note.Contains("dual"))
                {
                    Console.Out.WriteLine("Malformed dual annotation for cell " + addr.A1FullyQualified() + " : " + note);
                }
                return(FSharpOption <BugClass> .None);
            }
            else
            {
                // init duals list
                var duals = new List <AST.Address>();

                var cs = m.Groups["AddrOrRange"].Captures;

                foreach (Capture c in cs)
                {
                    // get string value
                    string addrOrRange = c.Value;

                    AST.Reference xlref = null;

                    try
                    {
                        // parse
                        xlref = Parcel.simpleReferenceParser(addrOrRange, env);
                    } catch (Exception e)
                    {
                        var msg = "Bad reference: '" + addrOrRange + "'";
                        Console.Out.WriteLine(msg);
                        throw new Exception(msg);
                    }

                    // figure out the reference type
                    if (xlref.Type == AST.ReferenceType.ReferenceRange)
                    {
                        var rrref = (AST.ReferenceRange)xlref;
                        duals.AddRange(rrref.Range.Addresses());
                    }
                    else if (xlref.Type == AST.ReferenceType.ReferenceAddress)
                    {
                        var aref = (AST.ReferenceAddress)xlref;
                        duals.Add(aref.Address);
                    }
                    else
                    {
                        throw new Exception("Unsupported address reference type.");
                    }
                }

                var bugclass = new BugClass(duals);

                return(FSharpOption <BugClass> .Some(bugclass));
            }
        }
Esempio n. 12
0
 public void TestEnum2()
 {
     String src = "enum MyEnum";
     List<Token> tokens = Parser.GetTokensFromString(src);
     DeclarationSpecifiers decln_specs;
     Int32 r = _declaration_specifiers.Parse(tokens, 0, out decln_specs);
     AST.Env env = new AST.Env();
     Tuple<AST.Env, AST.ExprType> t = decln_specs.GetExprType(env);
 }
Esempio n. 13
0
 public void TestArray()
 {
     String src = "int a[] = 3;";
     List<Token> tokens = Parser.GetTokensFromString(src);
     Declaration decln;
     Int32 r = _declaration.Parse(tokens, 0, out decln);
     AST.Env env = new AST.Env();
     Tuple<AST.Env, List<Tuple<AST.Env, AST.Decln>>> t = decln.GetDeclns(env);
 }
Esempio n. 14
0
 public void TestVariable()
 {
     String src = "{int *a; a; }";
     List<Token> tokens = Parser.GetTokensFromString(src);
     CompoundStatement stmt;
     Int32 r = _compound_statement.Parse(tokens, 0, out stmt);
     AST.Env env = new AST.Env();
     Tuple<AST.Env, AST.Stmt> r_stmt = stmt.GetStmt(env);
 }
Esempio n. 15
0
        public void TestMult()
        {
            String src = "3.0 * 5.0f;";
            List<Token> tokens = Parser.GetTokensFromString(src);
            Expression expr;
            Int32 r = _multiplicative_expression.Parse(tokens, 0, out expr);

            AST.Env env = new AST.Env();
            Tuple<AST.Env, AST.Expr> r_expr = expr.GetExpr(env);
        }
        public Tuple<AST.Env, AST.TranslnUnit> GetTranslationUnit()
        {
            List<Tuple<AST.Env, AST.ExternDecln>> declns = new List<Tuple<AST.Env, AST.ExternDecln>>();
            AST.Env env = new AST.Env();

            foreach (ExternDecln decln in this.declns) {
                Tuple<AST.Env, List<Tuple<AST.Env, AST.ExternDecln>>> r_decln = decln.GetExternDecln(env);
                env = r_decln.Item1;
                declns.AddRange(r_decln.Item2);
            }

            return new Tuple<AST.Env, AST.TranslnUnit>(env, new AST.TranslnUnit(declns));
        }