2121import it .unive .lisa .program .cfg .CodeMemberDescriptor ;
2222import it .unive .lisa .program .cfg .NativeCFG ;
2323import it .unive .lisa .program .cfg .Parameter ;
24+ import it .unive .lisa .program .cfg .statement .BinaryExpression ;
2425import it .unive .lisa .program .cfg .statement .Expression ;
2526import it .unive .lisa .program .cfg .statement .PluggableStatement ;
2627import it .unive .lisa .program .cfg .statement .Statement ;
@@ -45,7 +46,8 @@ public class DecodeString extends NativeCFG {
4546 * @param unit the unit to which this native cfg belongs to
4647 */
4748 public DecodeString (CodeLocation location , CompilationUnit unit ) {
48- super (new CodeMemberDescriptor (location , unit , false , "DecodeString" , GoErrorType .INSTANCE ,
49+ super (new CodeMemberDescriptor (location , unit , true , "DecodeString" , GoErrorType .INSTANCE ,
50+ new Parameter (location , "encoding" , Encoding .getEncodingType (unit .getProgram ())),
4951 new Parameter (location , "s" , GoStringType .INSTANCE )),
5052 DecodeStringImpl .class );
5153 }
@@ -55,7 +57,7 @@ public DecodeString(CodeLocation location, CompilationUnit unit) {
5557 *
5658 * @author <a href="mailto:[email protected] ">Luca Olivieri</a> 5759 */
58- public static class DecodeStringImpl extends UnaryExpression
60+ public static class DecodeStringImpl extends BinaryExpression
5961 implements PluggableStatement {
6062
6163 private Statement original ;
@@ -65,23 +67,19 @@ public void setOriginatingStatement(Statement st) {
6567 original = st ;
6668 }
6769
68- @ Override
69- protected int compareSameClassAndParams (Statement o ) {
70- return 0 ; // nothing else to compare
71- }
7270
7371 /**
7472 * Builds the pluggable statement.
7573 *
7674 * @param cfg the {@link CFG} where this pluggable statement lies
7775 * @param location the location where this pluggable statement is
7876 * defined
79- * @param par the parameter
77+ * @param params the parameters
8078 *
8179 * @return the pluggable statement
8280 */
83- public static DecodeStringImpl build (CFG cfg , CodeLocation location , Expression par ) {
84- return new DecodeStringImpl (cfg , location , par );
81+ public static DecodeStringImpl build (CFG cfg , CodeLocation location , Expression [] params ) {
82+ return new DecodeStringImpl (cfg , location , params [ 0 ], params [ 1 ] );
8583 }
8684
8785 /**
@@ -92,48 +90,58 @@ public static DecodeStringImpl build(CFG cfg, CodeLocation location, Expression
9290 * defined
9391 * @param par the par of this expression
9492 */
95- public DecodeStringImpl (CFG cfg , CodeLocation location , Expression par ) {
96- super (cfg , location , "DecodeStringImpl" , GoErrorType .INSTANCE , par );
93+ public DecodeStringImpl (CFG cfg , CodeLocation location , Expression left , Expression right ) {
94+ super (cfg , location , "DecodeStringImpl" , GoErrorType .INSTANCE , left , right );
9795 }
9896
9997
10098 @ Override
101- public <A extends AbstractState <A >> AnalysisState <A > fwdUnarySemantics (
102- InterproceduralAnalysis <A > interprocedural , AnalysisState <A > state , SymbolicExpression expr ,
103- StatementStore <A > expressions ) throws SemanticException {
104- Type sliceBytes = GoSliceType .getSliceOfBytes ();
105-
106- GoTupleType tupleType = GoTupleType .getTupleTypeOf (original .getLocation (), sliceBytes , GoErrorType .INSTANCE );
107-
108- Annotations annots = new Annotations ();
109- if (original instanceof ResolvedCall )
110- for (CodeMember target : ((ResolvedCall ) original ).getTargets ())
111- for (Annotation ann : target .getDescriptor ().getAnnotations ())
112- annots .addAnnotation (ann );
113-
114-
115- AnalysisState <A > pState = state .smallStepSemantics (expr , original );
116-
117- ExpressionSet computeExprs = pState .getComputedExpressions ();
118- AnalysisState <A > ret = state .bottom ();
119-
120- for (SymbolicExpression exp : pState .getState ().rewrite (computeExprs , original , state .getState ())) {
121- if (exp instanceof Identifier ) {
122- Identifier v = (Identifier ) exp ;
123- for (Annotation ann : annots )
124- v .addAnnotation (ann );
125- }
126- ret = ret .lub (GoTupleExpression .allocateTupleExpression (pState ,
127- annots ,
128- this ,
129- getLocation (),
130- tupleType ,
131- exp ,
132- new Constant (GoErrorType .INSTANCE , "error" , getLocation ())));
133- }
134-
135-
136- return ret ;
99+ public <A extends AbstractState <A >> AnalysisState <A > fwdBinarySemantics (
100+ InterproceduralAnalysis <A > interprocedural , AnalysisState <A > state , SymbolicExpression left ,
101+ SymbolicExpression right , StatementStore <A > expressions ) throws SemanticException {
102+ Type sliceBytes = GoSliceType .getSliceOfBytes ();
103+
104+ GoTupleType tupleType = GoTupleType .getTupleTypeOf (original .getLocation (), sliceBytes , GoErrorType .INSTANCE );
105+
106+ Annotations annots = new Annotations ();
107+ if (original instanceof ResolvedCall )
108+ for (CodeMember target : ((ResolvedCall ) original ).getTargets ())
109+ for (Annotation ann : target .getDescriptor ().getAnnotations ())
110+ annots .addAnnotation (ann );
111+
112+
113+ AnalysisState <A > pState = state .smallStepSemantics (right , original );
114+
115+ ExpressionSet computeExprs = pState .getComputedExpressions ();
116+ AnalysisState <A > ret = state .bottom ();
117+
118+ for (SymbolicExpression exp : pState .getState ().rewrite (computeExprs , original , state .getState ())) {
119+ if (exp instanceof Identifier ) {
120+ Identifier v = (Identifier ) exp ;
121+ for (Annotation ann : annots )
122+ v .addAnnotation (ann );
123+ }
124+ ret = ret .lub (GoTupleExpression .allocateTupleExpression (pState ,
125+ annots ,
126+ this ,
127+ getLocation (),
128+ tupleType ,
129+ exp ,
130+ new Constant (GoErrorType .INSTANCE , "error" , getLocation ())));
131+ }
132+
133+
134+ return ret ;
137135 }
136+
137+
138+ @ Override
139+ protected int compareSameClassAndParams (Statement o ) {
140+ // TODO Auto-generated method stub
141+ return 0 ;
142+ }
143+
144+
145+
138146 }
139147}
0 commit comments