Ejemplo n.º 1
0
            public override void CaseAPointerLvalue(APointerLvalue node)
            {
                hadPointer = false;
                nameExp = null;
                base.CaseAPointerLvalue(node);
                if (Util.IsIntPointer(node, data.LvalueTypes[node], data))
                {
                    if (nameExp != null)
                    {
                        //Create a data table get string exp
                        nameExp = CreateDynaicGetStm("int");
                    }
                    else
                    {
                        nameExp = node.GetBase();
                    }
                    //Replace by str_Array[<base>];
                    //If this is a compared pointer, replace it by str_Array[<base> >> <<bitsLeft>>]
                    GlobalStructVars vars;
                    int allocateLimit;
                    if (data.EnrichmentTypeLinks.ContainsKey(data.LvalueTypes[node]))
                    {
                        AEnrichmentDecl enrichmentDecl = data.EnrichmentTypeLinks[data.LvalueTypes[node]];
                        vars = CreateEnrichmentFields(node, enrichmentDecl, data);
                        allocateLimit = int.Parse(enrichmentDecl.GetIntDim().Text);
                    }
                    else
                    {
                        AStructDecl structDecl = data.StructTypeLinks[(ANamedType)data.LvalueTypes[node]];
                        vars = CreateStructFields(node, structDecl, data);
                        allocateLimit = int.Parse(structDecl.GetIntDim().Text);
                    }

                    AFieldLvalue array = new AFieldLvalue(new TIdentifier(vars.Array.GetName().Text));
                    ALvalueExp arrayExp = new ALvalueExp(array);

                    PExp arrayIndex = nameExp;
                    if (vars.IdentifierArray != null)
                    {
                        int usedBits = allocateLimit == 0 ? 0 : ((int)Math.Floor(Math.Log(allocateLimit, 2)) + 1);
                        int bitsLeft = 31 - usedBits;
                        int biggestIdentifier = (1 << (bitsLeft + 1)) - 1;

                        AIntConstExp bitsLeftConst = new AIntConstExp(new TIntegerLiteral(bitsLeft.ToString()));
                        arrayIndex = new ABinopExp(arrayIndex, new ARBitShiftBinop(new TRBitShift(">>")), bitsLeftConst);

                        data.ExpTypes[bitsLeftConst] =
                            data.ExpTypes[arrayIndex] = new ANamedType(new TIdentifier("int"), null);
                    }

                    AArrayLvalue replacer = new AArrayLvalue(new TLBracket("["), arrayExp, arrayIndex);
                    node.ReplaceBy(replacer);

                    data.FieldLinks[array] = vars.Array;
                    data.LvalueTypes[array] = data.ExpTypes[arrayExp] = vars.Array.GetType();
                    data.LvalueTypes[replacer] = ((AArrayTempType) vars.Array.GetType()).GetType();

                    hadPointer = false;
                    nameExp = null;
                    return;
                }
                //if (Util.GetAncestor<AAssignmentExp>(node) != null || Util.GetAncestor<APArrayLengthLvalue>(node) != null)
                {
                    if (nameExp != null)
                    {
                        //Create a data table get string exp

                        nameExp = CreateDynaicGetStm("string");
                    }
                    else
                    {
                        nameExp = node.GetBase();
                    }
                }
                hadPointer = true;
                CheckDynamicLvalue(node);
                //Todo: Insert runtime check that the pointer is actually not null / points to a delete object
                //(unless the same pointer was checked before, and it has not been assigned to since, and there has not been a method call since.
            }