Exemple #1
0
        internal static void ExportDef(string tag, MakeState s)
        {
            Expression.EvalResult e     = s.GetDefine(tag);
            MakeState             cur_s = s.parent;

            while (cur_s != null)
            {
                cur_s.SetDefine(tag, e);
                cur_s = cur_s.parent;
            }
        }
Exemple #2
0
        public override EvalResult Evaluate(MakeState s)
        {
            /* First, parse variables in the shell command */
            StringBuilder sb = new StringBuilder();
            int           i  = 0;

            while (i < val.Length)
            {
                if (val[i] == '\\' && i < (val.Length - 1))
                {
                    sb.Append(val[i++]);
                    sb.Append(val[i++]);
                }
                else if (val[i] == '$')
                {
                    /* Now try and match the largest possible variable we can */
                    int j = i + 1;

                    string match = null;

                    while (j < (val.Length) && val[j] != '$')
                    {
                        string test = val.Substring(i + 1, j - i);

                        if (s.IsDefined(test))
                        {
                            match = test;
                        }
                        j++;
                    }

                    if (match != null)
                    {
                        sb.Append(s.GetDefine(match).strval);
                        i++;
                        i += match.Length;
                    }
                    else
                    {
                        sb.Append(val[i++]);
                    }
                }
                else
                {
                    sb.Append(val[i++]);
                }
            }
            return(new EvalResult(sb.ToString()));
        }
Exemple #3
0
        public override Expression.EvalResult Execute(MakeState s)
        {
            if (s.IsDefined(v) == false)
            {
                throw new Exception("export: variable " + v + " is not defined in this scope");
            }

            Expression.EvalResult e = s.GetDefine(v);
            s.SetDefine(v, e);
            MakeState cur_s = s.parent;

            while (cur_s != null)
            {
                cur_s.SetDefine(v, e);
                cur_s = cur_s.parent;
            }

            return(new Expression.EvalResult(0));
        }
Exemple #4
0
 public override EvalResult Evaluate(MakeState s)
 {
     if (s.IsDefined(val))
     {
         return(s.GetDefine(val));
     }
     else if (s.funcs.ContainsKey(val))
     {
         return new EvalResult
                {
                    Type    = EvalResult.ResultType.Function,
                    funcval = new FunctionStatement
                    {
                        name = val
                    }
                }
     }
     ;
     else
     {
         return(new EvalResult());
     }
 }
Exemple #5
0
        public override Expression.EvalResult Execute(MakeState s)
        {
            Expression.EvalResult e = val.Evaluate(s);

            if (tok_name is LabelExpression)
            {
                var tn = ((LabelExpression)tok_name).val;
                s.SetLocalDefine(tn, e);
                if (export)
                {
                    ExportDef(tn, s);
                }
            }
            else if (tok_name is LabelMemberExpression)
            {
                // left-most member must be a define
                var lme = tok_name as LabelMemberExpression;
                if (!(lme.label is LabelExpression))
                {
                    throw new Exception("unable to assign to " + tok_name.ToString());
                }

                var o = s.GetDefine(((LabelExpression)lme.label).val);

                // Now iterate through the various members, looking for
                //  what to set
                Expression cur_member_lval = lme.member;
                while (true)
                {
                    if (cur_member_lval is LabelExpression)
                    {
                        // we've reached the end of the chain
                        break;
                    }
                    else if (cur_member_lval is LabelMemberExpression)
                    {
                        var new_lme = cur_member_lval as LabelMemberExpression;

                        if (!(new_lme.label is LabelExpression))
                        {
                            throw new Exception("unable to assign to " + tok_name.ToString());
                        }
                        lme             = new_lme;
                        cur_member_lval = lme.member;

                        if (o.Type != Expression.EvalResult.ResultType.Object)
                        {
                            throw new Exception();
                        }

                        o = o.objval[((LabelExpression)lme.label).val];
                    }
                    else
                    {
                        throw new NotImplementedException();
                    }
                }

                string member_name = ((LabelExpression)cur_member_lval).val;
                o.objval[member_name] = e;
            }
            else if (tok_name is LabelIndexedExpression)
            {
                var chain = get_chain(tok_name);

                // left-most member must be a define
                var lme = chain[0];
                if (!(lme is LabelExpression))
                {
                    throw new Exception("unable to assign to " + tok_name.ToString());
                }

                var o = s.GetDefine(((LabelExpression)lme).val);

                // Now iterate through the various members, looking for
                //  what to set
                o = follow_chain(o, chain, 1, chain.Count - 1, s);

                if (o.Type != Expression.EvalResult.ResultType.Array)
                {
                    throw new Exception("unable to assign to " + tok_name.ToString());
                }

                var idx = ((LabelIndexedExpression)tok_name).index.Evaluate(s).AsInt;

                // increase the array size as appropriate
                if (idx >= o.arrval.Count)
                {
                    o.arrval.Capacity = (int)idx * 3 / 2;
                    while (idx >= o.arrval.Count)
                    {
                        o.arrval.Add(new Expression.EvalResult {
                            Type = Expression.EvalResult.ResultType.Null
                        });
                    }
                }
                o.arrval[(int)idx] = e;
            }
            else
            {
                throw new NotImplementedException();
            }
            return(new Expression.EvalResult(0));
        }