public override void OutAUnopExp(AUnopExp node) { if (folding) { if (node.GetUnop() is ANegateUnop) { value = -value; } /* else if (node.GetUnop() is AComplementUnop) value = !value;*/ } base.OutAUnopExp(node); }
public virtual void InAUnopExp(AUnopExp node) { DefaultIn(node); }
public virtual void OutAUnopExp(AUnopExp node) { DefaultOut(node); }
public virtual void CaseAUnopExp(AUnopExp node) { DefaultCase(node); }
public override void CaseAUnopExp(AUnopExp node) { InAUnopExp(node); if (node.GetExp() != null) { node.GetExp().Apply(this); } if (node.GetUnop() != null) { node.GetUnop().Apply(this); } OutAUnopExp(node); }
public override void OutAUnopExp(AUnopExp node) { PUnop unop = node.GetUnop(); PExp exp = node.GetExp(); PType expType = data.ExpTypes[exp]; string expTypeString = Util.TypeToString(expType); //! okay for int and bool. - okay for int and fixed if (unop is ANegateUnop) { Token token = ((ANegateUnop)unop).GetToken(); if (expTypeString != "int" && expTypeString != "fixed" && expTypeString != "byte") { errors.Add(new ErrorCollection.Error(token, currentSourceFile, LocRM.GetString("ErrorText110") + expTypeString)); throw new ParserException(null, null); } data.ExpTypes[node] = expType; } else if (unop is AComplementUnop) { Token token = ((AComplementUnop)unop).GetToken(); if (expTypeString != "int" && expTypeString != "byte" && expTypeString != "bool" && expTypeString != "point" && expTypeString != "order" && expTypeString != "string") { errors.Add(new ErrorCollection.Error(token, currentSourceFile, LocRM.GetString("ErrorText111") + expTypeString)); throw new ParserException(null, null); } data.ExpTypes[node] = expType; } else throw new Exception("Unexpected unop (This should never happen)"); base.OutAUnopExp(node); }
public override void OutAUnopExp(AUnopExp node) { if (node.GetExp() is AIntConstExp && node.GetUnop() is ANegateUnop) { AIntConstExp intConst = (AIntConstExp) node.GetExp(); intConst.GetIntegerLiteral().Text = "-" + intConst.GetIntegerLiteral().Text; node.ReplaceBy(intConst); return; } base.OutAUnopExp(node); }
ArrayList New460() { ArrayList nodeList = new ArrayList(); ArrayList nodeArrayList2 = (ArrayList) Pop(); ArrayList nodeArrayList1 = (ArrayList) Pop(); TMinus tminusNode3 = (TMinus)nodeArrayList1[0]; ANegateUnop punopNode2 = new ANegateUnop ( tminusNode3 ); PExp pexpNode4 = (PExp)nodeArrayList2[0]; AUnopExp pexpNode1 = new AUnopExp ( punopNode2, pexpNode4 ); nodeList.Add(pexpNode1); return nodeList; }
ArrayList New454() { ArrayList nodeList = new ArrayList(); ArrayList nodeArrayList2 = (ArrayList) Pop(); ArrayList nodeArrayList1 = (ArrayList) Pop(); TComplement tcomplementNode3 = (TComplement)nodeArrayList1[0]; AComplementUnop punopNode2 = new AComplementUnop ( tcomplementNode3 ); PExp pexpNode4 = (PExp)nodeArrayList2[0]; AUnopExp pexpNode1 = new AUnopExp ( punopNode2, pexpNode4 ); nodeList.Add(pexpNode1); return nodeList; }
private static AMethodDecl CreateGeneralNullCheckMethod(Node node, SharedData data) { if (generalCompareNullMethod != null) return generalCompareNullMethod; /* * bool IsNull(string pointer) * { * if (pointer == null) * { * return true; * } * return !DataTableGetBool(true, pointer + "\\Exists"); * } */ AALocalDecl pointerDecl = new AALocalDecl(new APublicVisibilityModifier(), null, null, null, null, new ANamedType(new TIdentifier("string"), null), new TIdentifier("pointer"), null); ALocalLvalue pointerRef1 = new ALocalLvalue(new TIdentifier("pointer")); ALocalLvalue pointerRef2 = new ALocalLvalue(new TIdentifier("pointer")); ALvalueExp pointerRef1Exp = new ALvalueExp(pointerRef1); ALvalueExp pointerRef2Exp = new ALvalueExp(pointerRef2); ANullExp nullExp = new ANullExp(); ABooleanConstExp boolConst1 = new ABooleanConstExp(new ATrueBool()); ABooleanConstExp boolConst2 = new ABooleanConstExp(new ATrueBool()); AStringConstExp stringConst = new AStringConstExp(new TStringLiteral("\"\\\\Exists\"")); ABinopExp binop1 = new ABinopExp(pointerRef1Exp, new AEqBinop(new TEq("==")), nullExp); ABinopExp binop2 = new ABinopExp(pointerRef2Exp, new APlusBinop(new TPlus("+")), stringConst); ASimpleInvokeExp dataTableGetBoolCall = new ASimpleInvokeExp(new TIdentifier("DataTableGetBool"), new ArrayList(){boolConst2, binop2}); AUnopExp unopExp = new AUnopExp(new AComplementUnop(new TComplement("!")), dataTableGetBoolCall); generalCompareNullMethod = new AMethodDecl(new APublicVisibilityModifier(), null, null, null, null, null, new ANamedType(new TIdentifier("bool"), null), new TIdentifier("IsNull"), new ArrayList() {pointerDecl}, new AABlock( new ArrayList() { new AIfThenStm(new TLParen("("), binop1, new ABlockStm(new TLBrace("{"), new AABlock( new ArrayList() { new AValueReturnStm (new TReturn ("return"), boolConst1) }, new TRBrace("}")))), new AValueReturnStm(new TReturn("return"), unopExp) }, new TRBrace("}"))); AASourceFile sourceFile = Util.GetAncestor<AASourceFile>(node); sourceFile.GetDecl().Add(generalCompareNullMethod); data.LocalLinks[pointerRef1] = data.LocalLinks[pointerRef2] = pointerDecl; data.LvalueTypes[pointerRef1] = data.LvalueTypes[pointerRef2] = data.ExpTypes[pointerRef1Exp] = data.ExpTypes[pointerRef2Exp] = data.ExpTypes[stringConst] = data.ExpTypes[binop2] = new ANamedType(new TIdentifier("string"), null); data.ExpTypes[binop1] = data.ExpTypes[boolConst1] = data.ExpTypes[boolConst2] = data.ExpTypes[dataTableGetBoolCall] = data.ExpTypes[unopExp] = new ANamedType(new TIdentifier("string"), null); foreach (AMethodDecl methodDecl in data.Libraries.Methods) { if (methodDecl.GetName().Text == dataTableGetBoolCall.GetName().Text) { data.SimpleMethodLinks[dataTableGetBoolCall] = methodDecl; break; } } return generalCompareNullMethod; }
public static AMethodDecl CreateDeleteStructMethodGlobalArrayP(Node node, TIntegerLiteral intDim, string prefix, GlobalStructVars vars, SharedData data) { /* void DeleteStr(int i) { if (!(Str_used[i / 31] & Power2(i % 31))) { return; } Str_used[i / 31] = Str_used[i / 31] - Power2(i % 31); stack[freeCount] = i; freeCount += 1; /*if (i == Str_index) { while (!(Str_used[i / 31] & Power2(i % 31))) { i = i - 1; if (i < 0) { i = 41; } if (i == Str_index) { //Everything is free break; } } Str_index = i; }* / } */ AASourceFile file = Util.GetAncestor<AASourceFile>(node); AIntConstExp intConst1 = new AIntConstExp(new TIntegerLiteral("31")); AIntConstExp intConst2 = new AIntConstExp(new TIntegerLiteral("31")); AIntConstExp intConst3 = new AIntConstExp(new TIntegerLiteral("31")); AIntConstExp intConst4 = new AIntConstExp(new TIntegerLiteral("31")); AIntConstExp intConst5 = new AIntConstExp(new TIntegerLiteral("31")); AIntConstExp intConst6 = new AIntConstExp(new TIntegerLiteral("31")); AIntConstExp intConst7 = new AIntConstExp(new TIntegerLiteral("31")); AIntConstExp intConst8 = new AIntConstExp(new TIntegerLiteral("1")); AIntConstExp intConst9 = new AIntConstExp(new TIntegerLiteral("0")); AIntConstExp intConst10 = new AIntConstExp(new TIntegerLiteral((int.Parse(intDim.Text) - 1).ToString())); AIntConstExp intConst11 = new AIntConstExp(new TIntegerLiteral("1")); AIntConstExp intConst12 = new AIntConstExp(new TIntegerLiteral("1")); AIntConstExp intConst13 = new AIntConstExp(new TIntegerLiteral("1")); AFieldLvalue strUsedRef1 = new AFieldLvalue(new TIdentifier(vars.Used.GetName().Text)); AFieldLvalue strUsedRef2 = new AFieldLvalue(new TIdentifier(vars.Used.GetName().Text)); AFieldLvalue strUsedRef3 = new AFieldLvalue(new TIdentifier(vars.Used.GetName().Text)); AFieldLvalue strUsedRef4 = new AFieldLvalue(new TIdentifier(vars.Used.GetName().Text)); ALvalueExp strUsedRef1Exp = new ALvalueExp(strUsedRef1); ALvalueExp strUsedRef2Exp = new ALvalueExp(strUsedRef2); ALvalueExp strUsedRef3Exp = new ALvalueExp(strUsedRef3); ALvalueExp strUsedRef4Exp = new ALvalueExp(strUsedRef4); AFieldLvalue strIndexRef1 = new AFieldLvalue(new TIdentifier(vars.Index.GetName().Text)); AFieldLvalue strIndexRef2 = new AFieldLvalue(new TIdentifier(vars.Index.GetName().Text)); AFieldLvalue strIndexRef3 = new AFieldLvalue(new TIdentifier(vars.Index.GetName().Text)); ALvalueExp strIndexRef1Exp = new ALvalueExp(strIndexRef1); ALvalueExp strIndexRef2Exp = new ALvalueExp(strIndexRef2); AALocalDecl iDecl = new AALocalDecl(new APublicVisibilityModifier(), null, null, null, null, new ANamedType(new TIdentifier("int"), null), new TIdentifier("i"), null); ALocalLvalue iRef1 = new ALocalLvalue(new TIdentifier("i")); ALocalLvalue iRef2 = new ALocalLvalue(new TIdentifier("i")); ALocalLvalue iRef3 = new ALocalLvalue(new TIdentifier("i")); ALocalLvalue iRef4 = new ALocalLvalue(new TIdentifier("i")); ALocalLvalue iRef5 = new ALocalLvalue(new TIdentifier("i")); ALocalLvalue iRef6 = new ALocalLvalue(new TIdentifier("i")); ALocalLvalue iRef7 = new ALocalLvalue(new TIdentifier("i")); ALocalLvalue iRef8 = new ALocalLvalue(new TIdentifier("i")); ALocalLvalue iRef9 = new ALocalLvalue(new TIdentifier("i")); ALocalLvalue iRef10 = new ALocalLvalue(new TIdentifier("i")); ALocalLvalue iRef11 = new ALocalLvalue(new TIdentifier("i")); ALocalLvalue iRef12 = new ALocalLvalue(new TIdentifier("i")); ALocalLvalue iRef13 = new ALocalLvalue(new TIdentifier("i")); ALocalLvalue iRef14 = new ALocalLvalue(new TIdentifier("i")); ALvalueExp iRef1Exp = new ALvalueExp(iRef1); ALvalueExp iRef2Exp = new ALvalueExp(iRef2); ALvalueExp iRef3Exp = new ALvalueExp(iRef3); ALvalueExp iRef4Exp = new ALvalueExp(iRef4); ALvalueExp iRef5Exp = new ALvalueExp(iRef5); ALvalueExp iRef6Exp = new ALvalueExp(iRef6); ALvalueExp iRef7Exp = new ALvalueExp(iRef7); ALvalueExp iRef8Exp = new ALvalueExp(iRef8); ALvalueExp iRef10Exp = new ALvalueExp(iRef10); ALvalueExp iRef11Exp = new ALvalueExp(iRef11); ALvalueExp iRef13Exp = new ALvalueExp(iRef13); ALvalueExp iRef14Exp = new ALvalueExp(iRef14); ABinopExp binop1 = new ABinopExp(iRef1Exp, new ADivideBinop(new TDiv("/")), intConst1); ABinopExp binop2 = new ABinopExp(iRef2Exp, new AModuloBinop(new TMod("%")), intConst2); ABinopExp binop3 = new ABinopExp(null, new AAndBinop(new TAnd("&")), null); ABinopExp binop4 = new ABinopExp(iRef3Exp, new ADivideBinop(new TDiv("/")), intConst3); ABinopExp binop5 = new ABinopExp(iRef4Exp, new ADivideBinop(new TDiv("/")), intConst4); ABinopExp binop6 = new ABinopExp(iRef5Exp, new AModuloBinop(new TMod("%")), intConst5); ABinopExp binop7 = new ABinopExp(null, new AMinusBinop(new TMinus("-")), null); ABinopExp binop8 = new ABinopExp(iRef6Exp, new AEqBinop(new TEq("==")), strIndexRef1Exp); ABinopExp binop9 = new ABinopExp(iRef7Exp, new ADivideBinop(new TDiv("/")), intConst6); ABinopExp binop10 = new ABinopExp(iRef8Exp, new AModuloBinop(new TMod("%")), intConst7); ABinopExp binop11 = new ABinopExp(null, new AAndBinop(new TAnd("&")), null); ABinopExp binop12 = new ABinopExp(iRef10Exp, new AMinusBinop(new TMinus("-")), intConst8); ABinopExp binop13 = new ABinopExp(iRef11Exp, new ALtBinop(new TLt("<")), intConst9); ABinopExp binop14 = new ABinopExp(iRef13Exp, new AEqBinop(new TEq("==")), strIndexRef2Exp); AArrayLvalue arrayIndex1 = new AArrayLvalue(new TLBracket("["), strUsedRef1Exp, binop1); AArrayLvalue arrayIndex2 = new AArrayLvalue(new TLBracket("["), strUsedRef2Exp, binop4); AArrayLvalue arrayIndex3 = new AArrayLvalue(new TLBracket("["), strUsedRef3Exp, binop5); AArrayLvalue arrayIndex4 = new AArrayLvalue(new TLBracket("["), strUsedRef4Exp, binop9); ALvalueExp arrayIndex1Exp = new ALvalueExp(arrayIndex1); ALvalueExp arrayIndex3Exp = new ALvalueExp(arrayIndex3); ALvalueExp arrayIndex4Exp = new ALvalueExp(arrayIndex4); binop3.SetLeft(arrayIndex1Exp); binop7.SetLeft(arrayIndex3Exp); binop11.SetLeft(arrayIndex4Exp); ABinopExp binop15 = new ABinopExp(intConst11, new ALBitShiftBinop(new TLBitShift("<<")), binop2); ABinopExp binop16 = new ABinopExp(intConst12, new ALBitShiftBinop(new TLBitShift("<<")), binop6); ABinopExp binop17 = new ABinopExp(intConst13, new ALBitShiftBinop(new TLBitShift("<<")), binop10); binop3.SetRight(binop15); binop7.SetRight(binop16); binop11.SetRight(binop17); /*ASimpleInvokeExp power2Invoke1 = new ASimpleInvokeExp(new TIdentifier("Power2"), new ArrayList() { binop2 }); ASimpleInvokeExp power2Invoke2 = new ASimpleInvokeExp(new TIdentifier("Power2"), new ArrayList() { binop6 }); ASimpleInvokeExp power2Invoke3 = new ASimpleInvokeExp(new TIdentifier("Power2"), new ArrayList() { binop10 }); binop3.SetRight(power2Invoke1); binop7.SetRight(power2Invoke2); binop11.SetRight(power2Invoke3);*/ AParenExp paren1 = new AParenExp(binop3); AParenExp paren2 = new AParenExp(binop11); AUnopExp unop1 = new AUnopExp(new AComplementUnop(new TComplement("!")), paren1); AUnopExp unop2 = new AUnopExp(new AComplementUnop(new TComplement("!")), paren2); AAssignmentExp assignment1 = new AAssignmentExp(new TAssign("="), arrayIndex2, binop7); AAssignmentExp assignment2 = new AAssignmentExp(new TAssign("="), iRef9, binop12); AAssignmentExp assignment3 = new AAssignmentExp(new TAssign("="), iRef12, intConst10); AAssignmentExp assignment4 = new AAssignmentExp(new TAssign("="), strIndexRef3, iRef14Exp); AMethodDecl method = new AMethodDecl(new APublicVisibilityModifier(), null, null, null, null, null, new AVoidType(new TVoid("void")), new TIdentifier("Delete" + prefix, data.LineCounts[file] + 18, 0), new ArrayList() { iDecl }, new AABlock( new ArrayList() { new AIfThenStm(new TLParen("("), unop1, new ABlockStm( new TLBrace("{"), new AABlock( new ArrayList() { new AVoidReturnStm (new TReturn ("return")) }, new TRBrace("}")))), new AExpStm(new TSemicolon(";"), assignment1), new AIfThenStm(new TLParen("("), binop8, new ABlockStm( new TLBrace("{"), new AABlock( new ArrayList() { new AWhileStm (new TLParen ("("), unop2, new ABlockStm (new TLBrace ("{"), new AABlock (new ArrayList () { new AExpStm (new TSemicolon (";"), assignment2), new AIfThenStm (new TLParen ("("), binop13, new ABlockStm (new TLBrace ("{"), new AABlock (new ArrayList () { new AExpStm (new TSemicolon (";"), assignment3) }, new TRBrace ("}")))), new AIfThenStm (new TLParen ("("), binop14, new ABlockStm (new TLBrace ("{"), new AABlock (new ArrayList () { new ABreakStm (new TBreak ("break")) }, new TRBrace ("}")))) }, new TRBrace ("}")))), new AExpStm( new TSemicolon (";"), assignment4) }, new TRBrace("}")))) }, new TRBrace("}"))); file.GetDecl().Add(method); data.Methods.Add(new SharedData.DeclItem<AMethodDecl>(file, method)); data.FieldLinks[strUsedRef1] = data.FieldLinks[strUsedRef2] = data.FieldLinks[strUsedRef3] = data.FieldLinks[strUsedRef4] = vars.Used; data.FieldLinks[strIndexRef1] = data.FieldLinks[strIndexRef2] = data.FieldLinks[strIndexRef3] = vars.Index; data.LocalLinks[iRef1] = data.LocalLinks[iRef2] = data.LocalLinks[iRef3] = data.LocalLinks[iRef4] = data.LocalLinks[iRef5] = data.LocalLinks[iRef6] = data.LocalLinks[iRef7] = data.LocalLinks[iRef8] = data.LocalLinks[iRef9] = data.LocalLinks[iRef10] = data.LocalLinks[iRef11] = data.LocalLinks[iRef12] = data.LocalLinks[iRef13] = data.LocalLinks[iRef14] = iDecl; //data.SimpleMethodLinks[power2Invoke1] = // data.SimpleMethodLinks[power2Invoke2] = // data.SimpleMethodLinks[power2Invoke3] = CreatePower2Method(node, data); data.ExpTypes[intConst1] = data.ExpTypes[intConst2] = data.ExpTypes[intConst3] = data.ExpTypes[intConst4] = data.ExpTypes[intConst5] = data.ExpTypes[intConst6] = data.ExpTypes[intConst7] = data.ExpTypes[intConst8] = data.ExpTypes[intConst9] = data.ExpTypes[intConst10] = data.ExpTypes[intConst11] = data.ExpTypes[intConst12] = data.ExpTypes[intConst13] = data.LvalueTypes[iRef1] = data.LvalueTypes[iRef2] = data.LvalueTypes[iRef3] = data.LvalueTypes[iRef4] = data.LvalueTypes[iRef5] = data.LvalueTypes[iRef6] = data.LvalueTypes[iRef7] = data.LvalueTypes[iRef8] = data.LvalueTypes[iRef9] = data.LvalueTypes[iRef10] = data.LvalueTypes[iRef11] = data.LvalueTypes[iRef12] = data.LvalueTypes[iRef13] = data.LvalueTypes[iRef14] = data.ExpTypes[iRef1Exp] = data.ExpTypes[iRef2Exp] = data.ExpTypes[iRef3Exp] = data.ExpTypes[iRef4Exp] = data.ExpTypes[iRef5Exp] = data.ExpTypes[iRef6Exp] = data.ExpTypes[iRef7Exp] = data.ExpTypes[iRef8Exp] = data.ExpTypes[iRef10Exp] = data.ExpTypes[iRef11Exp] = data.ExpTypes[iRef13Exp] = data.ExpTypes[iRef14Exp] = data.LvalueTypes[arrayIndex1] = data.LvalueTypes[arrayIndex2] = data.LvalueTypes[arrayIndex3] = data.LvalueTypes[arrayIndex4] = data.ExpTypes[arrayIndex1Exp] = data.ExpTypes[arrayIndex3Exp] = data.ExpTypes[arrayIndex4Exp] = data.ExpTypes[binop1] = data.ExpTypes[binop2] = data.ExpTypes[binop3] = data.ExpTypes[binop4] = data.ExpTypes[binop5] = data.ExpTypes[binop6] = data.ExpTypes[binop7] = data.ExpTypes[binop9] = data.ExpTypes[binop10] = data.ExpTypes[binop11] = data.ExpTypes[binop12] = data.ExpTypes[binop15] = data.ExpTypes[binop16] = data.ExpTypes[binop17] = data.ExpTypes[paren1] = data.ExpTypes[paren2] = data.ExpTypes[assignment1] = data.ExpTypes[assignment2] = data.ExpTypes[assignment3] = data.ExpTypes[assignment4] = /*data.ExpTypes[power2Invoke1] = data.ExpTypes[power2Invoke2] = data.ExpTypes[power2Invoke3] =*/ new ANamedType(new TIdentifier("int"), null); data.ExpTypes[binop8] = data.ExpTypes[binop13] = data.ExpTypes[binop14] = data.ExpTypes[unop1] = data.ExpTypes[unop2] = new ANamedType(new TIdentifier("bool"), null); return method; }
public override void OutABinopExp(ABinopExp node) { if (node.GetBinop() is AEqBinop || node.GetBinop() is ANeBinop) { if (node.GetLeft() is ANullExp || node.GetRight() is ANullExp) { if (node.GetLeft() is ANullExp) { //Swap left and right PExp temp = node.GetLeft(); node.SetLeft(node.GetRight()); node.SetRight(temp); } PExp exp = node.GetLeft(); PType type = data.ExpTypes[exp]; if (type is APointerType) { if (node.GetBinop() is ANeBinop) { //Convert a != null to !(a == null) AUnopExp unop = new AUnopExp(new AComplementUnop(new TComplement("!")), null); node.ReplaceBy(unop); unop.SetExp(node); node.SetBinop(new AEqBinop(new TEq("=="))); data.ExpTypes[unop] = new ANamedType(new TIdentifier("bool"), null); } if (Util.IsIntPointer(node, ((APointerType)type).GetType(), data)) { bool add = true; foreach (PType pType in TypesWithIdentifierArray) { if (Util.TypesEqual(((APointerType)type).GetType(), pType, data)) { add = false; break; } } if (add) TypesWithIdentifierArray.Add(((APointerType)type).GetType()); } } } } }