Пример #1
0
 public operand(operandMode mode = default, ast.Expr expr = default, Type typ = default, constant.Value val = default, builtinId id = default)
 {
     this.mode = mode;
     this.expr = expr;
     this.typ  = typ;
     this.val  = val;
     this.id   = id;
 }
Пример #2
0
 public DebugRef(anInstruction anInstruction = default, ast.Expr Expr = default, types.Object @object = default, bool IsAddr = default, Value X = default)
 {
     this.m_anInstructionRef = new ptr <anInstruction>(anInstruction);
     this.Expr    = Expr;
     this.@object = @object;
     this.IsAddr  = IsAddr;
     this.X       = X;
 }
Пример #3
0
 // Unparen returns e with any enclosing parentheses stripped.
 public static ast.Expr Unparen(ast.Expr e)
 {
     while (true)
     {
         ptr <ast.ParenExpr> (p, ok) = e._ <ptr <ast.ParenExpr> >();
         if (!ok)
         {
             return(e);
         }
         e = p.X;
     }
 }
Пример #4
0
 public typeConv(map <@string, ptr <Type> > m = default, map <@string, slice <ptr <Type> > > ptrs = default, slice <dwarf.Type> ptrKeys = default, map <@string, bool> getTypeIDs = default, ast.Expr @bool = default, ast.Expr @byte = default, ast.Expr int8 = default, ast.Expr int16 = default, ast.Expr int32 = default, ast.Expr int64 = default, ast.Expr uint8 = default, ast.Expr uint16 = default, ast.Expr uint32 = default, ast.Expr uint64 = default, ast.Expr uintptr = default, ast.Expr float32 = default, ast.Expr float64 = default, ast.Expr complex64 = default, ast.Expr complex128 = default, ast.Expr @void = default, ast.Expr @string = default, ast.Expr goVoid = default, ast.Expr goVoidPtr = default, long ptrSize = default, long intSize = default)
 {
     this.m          = m;
     this.ptrs       = ptrs;
     this.ptrKeys    = ptrKeys;
     this.getTypeIDs = getTypeIDs;
     this.@bool      = @bool;
     this.@byte      = @byte;
     this.int8       = int8;
     this.int16      = int16;
     this.int32      = int32;
     this.int64      = int64;
     this.uint8      = uint8;
     this.uint16     = uint16;
     this.uint32     = uint32;
     this.uint64     = uint64;
     this.uintptr    = uintptr;
     this.float32    = float32;
     this.float64    = float64;
     this.complex64  = complex64;
     this.complex128 = complex128;
     this.@void      = @void;
     this.@string    = @string;
     this.goVoid     = goVoid;
     this.goVoidPtr  = goVoidPtr;
     this.ptrSize    = ptrSize;
     this.intSize    = intSize;
 }
Пример #5
0
 // Format returns a string representation of the expression.
 public static @string Format(ptr <token.FileSet> _addr_fset, ast.Expr x)
 {
     ref token.FileSet fset = ref _addr_fset.val;
Пример #6
0
 public CondBreak(ast.Expr Cond = default, bool InsideCommuteLoop = default)
 {
     this.Cond = Cond;
     this.InsideCommuteLoop = InsideCommuteLoop;
 }
Пример #7
0
 public Initializer(slice <ptr <Var> > Lhs = default, ast.Expr Rhs = default)
 {
     this.Lhs = Lhs;
     this.Rhs = Rhs;
 }
Пример #8
0
        private static ast.Visitor Visit(this simplifier s, ast.Node node)
        {
            switch (node.type())
            {
            case ptr <ast.CompositeLit> n:
                var      outer = n;
                ast.Expr keyType = default;                    ast.Expr eltType = default;

                switch (outer.Type.type())
                {
                case ptr <ast.ArrayType> typ:
                    eltType = typ.Elt;
                    break;

                case ptr <ast.MapType> typ:
                    keyType = typ.Key;
                    eltType = typ.Value;
                    break;
                }

                if (eltType != null)
                {
                    reflect.Value ktyp = default;
                    if (keyType != null)
                    {
                        ktyp = reflect.ValueOf(keyType);
                    }

                    var typ = reflect.ValueOf(eltType);
                    foreach (var(i, x) in outer.Elts)
                    {
                        var px = _addr_outer.Elts[i];
                        // look at value of indexed/named elements
                        {
                            ptr <ast.KeyValueExpr> (t, ok) = x._ <ptr <ast.KeyValueExpr> >();

                            if (ok)
                            {
                                if (keyType != null)
                                {
                                    s.simplifyLiteral(ktyp, keyType, t.Key, _addr_t.Key);
                                }

                                x  = t.Value;
                                px = _addr_t.Value;
                            }
                        }

                        s.simplifyLiteral(typ, eltType, x, px);
                    }
                    // node was simplified - stop walk (there are no subnodes to simplify)
                    return(null);
                }

                break;

            case ptr <ast.SliceExpr> n:
                if (n.Max != null)
                {
                    // - 3-index slices always require the 2nd and 3rd index
                    break;
                }

                {
                    ptr <ast.Ident> (s, _) = n.X._ <ptr <ast.Ident> >();

                    if (s != null && s.Obj != null)
                    {
                        // the array/slice object is a single, resolved identifier
                        {
                            ptr <ast.CallExpr> (call, _) = n.High._ <ptr <ast.CallExpr> >();

                            if (call != null && len(call.Args) == 1L && !call.Ellipsis.IsValid())
                            {
                                // the high expression is a function call with a single argument
                                {
                                    ptr <ast.Ident> (fun, _) = call.Fun._ <ptr <ast.Ident> >();

                                    if (fun != null && fun.Name == "len" && fun.Obj == null)
                                    {
                                        // the function called is "len" and it is not locally defined; and
                                        // because we don't have dot imports, it must be the predefined len()
                                        {
                                            ptr <ast.Ident> (arg, _) = call.Args[0L]._ <ptr <ast.Ident> >();

                                            if (arg != null && arg.Obj == s.Obj)
                                            {
                                                // the len argument is the array/slice object
                                                n.High = null;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    // Note: We could also simplify slice expressions of the form s[0:b] to s[:b]
                    //       but we leave them as is since sometimes we want to be very explicit
                    //       about the lower bound.
                    // An example where the 0 helps:
                    //       x, y, z := b[0:2], b[2:4], b[4:6]
                    // An example where it does not:
                    //       x, y := b[:n], b[n:]
                }
                // Note: We could also simplify slice expressions of the form s[0:b] to s[:b]
                //       but we leave them as is since sometimes we want to be very explicit
                //       about the lower bound.
                // An example where the 0 helps:
                //       x, y, z := b[0:2], b[2:4], b[4:6]
                // An example where it does not:
                //       x, y := b[:n], b[n:]
                break;

            case ptr <ast.RangeStmt> n:
                if (isBlank(n.Value))
                {
                    n.Value = null;
                }

                if (isBlank(n.Key) && n.Value == null)
                {
                    n.Key = null;
                }

                break;
            }

            return(s);
        }
Пример #9
0
 public Case(BodyBase BodyBase = default, ast.Expr Expr = default)
 {
     this.m_BodyBaseRef = new ptr <BodyBase>(BodyBase);
     this.Expr          = Expr;
 }
Пример #10
0
        // Keep this function for debugging.

        /*
         * func dump(msg string, val reflect.Value) {
         *  fmt.Printf("%s:\n", msg)
         *  ast.Print(fileSet, val.Interface())
         *  fmt.Println()
         * }
         */

        // rewriteFile applies the rewrite rule 'pattern -> replace' to an entire file.
        private static ptr <ast.File> rewriteFile(ast.Expr pattern, ast.Expr replace, ptr <ast.File> _addr_p)
        {
            ref ast.File p = ref _addr_p.val;
Пример #11
0
 private static void simplifyLiteral(this simplifier s, reflect.Value typ, ast.Expr astType, ast.Expr x, ptr <ast.Expr> _addr_px)
 {
     ref ast.Expr px = ref _addr_px.val;
Пример #12
0
 public Type(long Size = default, long Align = default, ref ptr <TypeRepr> C = default, ast.Expr Go = default, map <@string, long> EnumValues = default, @string Typedef = default, bool BadPointer = default)
 {
     this.Size       = Size;
     this.Align      = Align;
     this.C          = C;
     this.Go         = Go;
     this.EnumValues = EnumValues;
     this.Typedef    = Typedef;
     this.BadPointer = BadPointer;
 }
Пример #13
0
 // matchArgType reports an error if printf verb t is not appropriate
 // for operand arg.
 //
 // typ is used only for recursive calls; external callers must supply nil.
 //
 // (Recursion arises from the compound types {map,chan,slice} which
 // may be printed with %d etc. if that is appropriate for their element
 // types.)
 private static bool matchArgType(ptr <analysis.Pass> _addr_pass, printfArgType t, types.Type typ, ast.Expr arg)
 {
     ref analysis.Pass pass = ref _addr_pass.val;
Пример #14
0
 public Declare(@string Name = default, ast.Expr Value = default)
 {
     this.Name  = Name;
     this.Value = Value;
 }
Пример #15
0
 public declInfo(ref ptr <Scope> file = default, slice <ptr <Var> > lhs = default, ast.Expr typ = default, ast.Expr init = default, ref ptr <ast.FuncDecl> fdecl = default, bool alias = default, map <Object, bool> deps = default)
 {
     this.file  = file;
     this.lhs   = lhs;
     this.typ   = typ;
     this.init  = init;
     this.fdecl = fdecl;
     this.alias = alias;
     this.deps  = deps;
 }
Пример #16
0
 public address(Value addr = default, token.Pos pos = default, ast.Expr expr = default)
 {
     this.addr = addr;
     this.pos  = pos;
     this.expr = expr;
 }
Пример #17
0
 // ExprString returns the (possibly shortened) string representation for x.
 // Shortened representations are suitable for user interfaces but may not
 // necessarily follow Go syntax.
 public static @string ExprString(ast.Expr x)
 {
     ref bytes.Buffer buf = ref heap(out ptr <bytes.Buffer> _addr_buf);