idx
int64
0
165k
question
stringlengths
73
4.15k
target
stringlengths
5
918
len_question
int64
21
890
len_target
int64
3
255
35,200
private String readInput ( PrintStream out , boolean echo ) throws InterruptedException { StringBuilder sb = new StringBuilder ( ) ; Key inputKey ; do { CommandOperation input = commandInvocation . getInput ( ) ; inputKey = input . getInputKey ( ) ; if ( inputKey == Key . CTRL_C || inputKey == Key . CTRL_D ) { throw ne...
Performs the hard work
297
5
35,201
public void preconfigureInput ( InputComponent < ? , ? > input , WithAttributes atts ) { if ( atts != null ) { input . setEnabled ( atts . enabled ( ) ) ; input . setLabel ( atts . label ( ) ) ; input . setRequired ( atts . required ( ) ) ; input . setRequiredMessage ( atts . requiredMessage ( ) ) ; input . setDescript...
Pre - configure input based on WithAttributes info if annotation exists
267
12
35,202
public DTOCollection from ( Project project , JavaClass < ? > entity , String dtoPackage ) { DTOCollection dtoCollection = new DTOCollection ( ) ; if ( entity == null ) { throw new IllegalArgumentException ( "The argument entity was null." ) ; } generatedDTOGraphForEntity ( project , entity , dtoPackage , true , false ...
Creates a collection of DTOs for the provided JPA entity and any JPA entities referenced in the JPA entity .
93
26
35,203
@ Override public void start ( ) { synchronized ( this . lifecycleMonitor ) { if ( ! isRunning ( ) ) { log . info ( "start: Starting ConnectorManager" ) ; try { connector . start ( ) ; } catch ( ConfigError | RuntimeError ex ) { throw new ConfigurationException ( ex . getMessage ( ) , ex ) ; } catch ( Throwable ex ) { ...
Start the connector accepting new connections
108
6
35,204
@ Override public void stop ( ) { synchronized ( this . lifecycleMonitor ) { if ( isRunning ( ) ) { log . info ( "stop: Stopping ConnectorManager" ) ; try { connector . stop ( ) ; } finally { running = false ; } } } }
Stop this connector logging out existing sessions closing their connections and stopping to accept new connections .
60
17
35,205
public void visitBracketedExpression ( Expr expr , Integer indent ) { boolean needsBrackets = needsBrackets ( expr ) ; if ( needsBrackets ) { out . print ( "(" ) ; } visitExpression ( expr , indent ) ; if ( needsBrackets ) { out . print ( ")" ) ; } }
Write a bracketed operand if necessary . Any operand whose human - readable representation can contain whitespace must have brackets around it .
71
27
35,206
public < T extends Type > T selectCandidate ( T candidate , T next , T actual , Environment environment ) { // Found a viable candidate boolean left = subtypeOperator . isSubtype ( candidate , next , environment ) ; boolean right = subtypeOperator . isSubtype ( next , candidate , environment ) ; if ( left && ! right ) ...
Given two candidates return the more precise one . If no viable candidate return null ;
173
16
35,207
public static Type . Callable substitute ( Type . Callable fmp , Tuple < Template . Variable > templateParameters , Tuple < SyntacticItem > templateArguments ) { Function < Identifier , SyntacticItem > binding = WyilFile . bindingFunction ( templateParameters , templateArguments ) ; // Proceed with the potentially upda...
Apply an explicit binding to a given function method or property declaration via substitution . Observe we cannot just use the existing Type . substitute method as this accounts for lifetime captures . Therefore we first build the binding and then apply it to each of the parameters and returns .
221
52
35,208
public static < T extends SyntacticItem > java . util . function . Function < Identifier , SyntacticItem > bindingFunction ( Tuple < Template . Variable > variables , Tuple < T > arguments ) { // return ( Identifier var ) -> { for ( int i = 0 ; i != variables . size ( ) ; ++ i ) { if ( var . equals ( variables . get ( ...
Create a simple binding function from two tuples representing the key set and value set respectively .
108
18
35,209
public static java . util . function . Function < Identifier , SyntacticItem > removeFromBinding ( java . util . function . Function < Identifier , SyntacticItem > binding , Tuple < Identifier > variables ) { return ( Identifier var ) -> { // Sanity check whether this is a variable which is being removed for ( int i = ...
Construct a binding function from another binding where a given set of variables are removed . This is necessary in situations where the given variables are captured .
127
28
35,210
protected < T extends SemanticType . Atom > T construct ( Disjunct type , LifetimeRelation lifetimes , Combinator < T > kind ) { T result = null ; Conjunct [ ] conjuncts = type . conjuncts ; for ( int i = 0 ; i != conjuncts . length ; ++ i ) { Conjunct conjunct = conjuncts [ i ] ; if ( ! isVoid ( conjunct , lifetimes )...
Construct a given target type from a given type in DisjunctiveNormalForm .
183
16
35,211
protected static int countMatchingFields ( Tuple < ? extends SemanticType . Field > lhsFields , Tuple < ? extends SemanticType . Field > rhsFields ) { int count = 0 ; for ( int i = 0 ; i != lhsFields . size ( ) ; ++ i ) { for ( int j = 0 ; j != rhsFields . size ( ) ; ++ j ) { SemanticType . Field lhsField = lhsFields ....
Count the number of matching fields . That is fields with the same name .
190
15
35,212
private Stmt parseHeadlessStatement ( EnclosingScope scope ) { int start = index ; // See if it is a named block Identifier blockName = parseOptionalIdentifier ( scope ) ; if ( blockName != null ) { if ( tryAndMatch ( true , Colon ) != null && isAtEOL ( ) ) { int end = index ; matchEndLine ( ) ; scope = scope . newEncl...
A headless statement is one which has no identifying keyword . The set of headless statements include assignments invocations variable declarations and named blocks .
399
28
35,213
public Tuple < Expr > parseExpressions ( EnclosingScope scope , boolean terminated ) { ArrayList < Expr > returns = new ArrayList <> ( ) ; // A return statement may optionally have a return expression. // Therefore, we first skip all whitespace on the given line. int next = skipLineSpace ( index ) ; // Then, we check w...
Parse a multi - expression ; that is a sequence of one or more expressions separated by comma s
184
20
35,214
private Expr parseBitwiseOrExpression ( EnclosingScope scope , boolean terminated ) { int start = index ; Expr lhs = parseBitwiseXorExpression ( scope , terminated ) ; if ( tryAndMatch ( terminated , VerticalBar ) != null ) { Expr rhs = parseExpression ( scope , terminated ) ; return annotateSourceLocation ( new Expr ....
Parse an bitwise inclusive or expression
113
8
35,215
private Expr parseBitwiseXorExpression ( EnclosingScope scope , boolean terminated ) { int start = index ; Expr lhs = parseBitwiseAndExpression ( scope , terminated ) ; if ( tryAndMatch ( terminated , Caret ) != null ) { Expr rhs = parseExpression ( scope , terminated ) ; return annotateSourceLocation ( new Expr . Bitw...
Parse an bitwise exclusive or expression
114
8
35,216
private Expr parseBitwiseAndExpression ( EnclosingScope scope , boolean terminated ) { int start = index ; Expr lhs = parseConditionExpression ( scope , terminated ) ; if ( tryAndMatch ( terminated , Ampersand ) != null ) { Expr rhs = parseExpression ( scope , terminated ) ; return annotateSourceLocation ( new Expr . B...
Parse an bitwise and expression
111
7
35,217
private Expr parseConditionExpression ( EnclosingScope scope , boolean terminated ) { int start = index ; Token lookahead ; // First, attempt to parse quantifiers (e.g. some, all, no, etc) if ( ( lookahead = tryAndMatch ( terminated , Some , All ) ) != null ) { return parseQuantifierExpression ( lookahead , scope , ter...
Parse a condition expression .
435
6
35,218
private Expr parseAdditiveExpression ( EnclosingScope scope , boolean terminated ) { int start = index ; Expr lhs = parseMultiplicativeExpression ( scope , terminated ) ; Token lookahead ; while ( ( lookahead = tryAndMatch ( terminated , Plus , Minus ) ) != null ) { Expr rhs = parseMultiplicativeExpression ( scope , te...
Parse an additive expression .
186
6
35,219
private Expr parseMultiplicativeExpression ( EnclosingScope scope , boolean terminated ) { int start = index ; Expr lhs = parseAccessExpression ( scope , terminated ) ; Token lookahead = tryAndMatch ( terminated , Star , RightSlash , Percent ) ; if ( lookahead != null ) { Expr rhs = parseAccessExpression ( scope , term...
Parse a multiplicative expression .
213
7
35,220
private Expr parseQualifiedAccess ( EnclosingScope scope , boolean terminated ) { int start = index ; // Parse qualified name Name name = parseName ( scope ) ; // Construct link to be resolved Decl . Link link = new Decl . Link <> ( name ) ; // Decide what we've got int mid = index ; Expr expr ; if ( skipTemplate ( sco...
Attempt to parse a possible module identifier . This will reflect a true module identifier only if the root variable is not in the given environment .
265
27
35,221
public boolean skipTemplate ( EnclosingScope scope ) { int start = index ; if ( tryAndMatch ( false , LeftAngle ) == null ) { return true ; } else { boolean firstTime = true ; while ( tryAndMatch ( false , RightAngle ) == null ) { if ( ! firstTime && tryAndMatch ( false , Comma ) == null ) { // Failed to match a comma....
Decide whether we have a template argument list ahead . This actually requires infinite lookahead but in practice is pretty minimal work .
140
25
35,222
private Identifier parseLifetime ( EnclosingScope scope , boolean terminated ) { Identifier id = parseOptionalLifetimeIdentifier ( scope , terminated ) ; if ( id != null ) { return id ; } else { syntaxError ( "expecting lifetime identifier" , tokens . get ( index ) ) ; } throw new RuntimeException ( "deadcode" ) ; // d...
Parse a currently declared lifetime .
83
7
35,223
private Token match ( Token . Kind kind ) { checkNotEof ( ) ; Token token = tokens . get ( index ++ ) ; if ( token . kind != kind ) { syntaxError ( "expecting \"" + kind + "\" here" , token ) ; } return token ; }
Match a given token kind whilst moving passed any whitespace encountered inbetween . In the case that meet the end of the stream or we don t match the expected token then an error is thrown .
61
39
35,224
private Token [ ] match ( Token . Kind ... kinds ) { Token [ ] result = new Token [ kinds . length ] ; for ( int i = 0 ; i != result . length ; ++ i ) { checkNotEof ( ) ; Token token = tokens . get ( index ++ ) ; if ( token . kind == kinds [ i ] ) { result [ i ] = token ; } else { syntaxError ( "Expected \"" + kinds [ ...
Match a given sequence of tokens whilst moving passed any whitespace encountered inbetween . In the case that meet the end of the stream or we don t match the expected tokens in the expected order then an error is thrown .
111
44
35,225
private boolean lookaheadSequence ( boolean terminated , Token . Kind ... kinds ) { int next = index ; for ( Token . Kind k : kinds ) { next = terminated ? skipWhiteSpace ( next ) : skipLineSpace ( next ) ; if ( next >= tokens . size ( ) || tokens . get ( next ++ ) . kind != k ) { return false ; } } return true ; }
Attempt to match a given sequence of tokens in the given order whilst ignoring any whitespace in between . Note that in any case the index will be unchanged!
82
31
35,226
private boolean isAtEOL ( ) { int next = skipLineSpace ( index ) ; return next >= tokens . size ( ) || tokens . get ( next ) . kind == NewLine ; }
Check whether the current index is after skipping all line spaces at the end of a line . This method does not change the state!
41
26
35,227
private void matchEndLine ( ) { // First, parse all whitespace characters except for new lines index = skipLineSpace ( index ) ; // Second, check whether we've reached the end-of-file (as signaled by // running out of tokens), or we've encountered some token which not a // newline. if ( index >= tokens . size ( ) ) { r...
Match a the end of a line . This is required to signal for example the end of the current statement .
130
22
35,228
private int skipWhiteSpace ( int index ) { while ( index < tokens . size ( ) && isWhiteSpace ( tokens . get ( index ) ) ) { index ++ ; } return index ; }
Skip over any whitespace characters starting from a given index and returning the first index passed any whitespace encountered .
41
22
35,229
private void skipEmptyLines ( ) { int tmp = index ; do { tmp = skipLineSpace ( tmp ) ; if ( tmp < tokens . size ( ) && tokens . get ( tmp ) . kind != Token . Kind . NewLine ) { return ; // done } else if ( tmp >= tokens . size ( ) ) { index = tmp ; return ; // end-of-file reached } // otherwise, skip newline and contin...
Skip over any empty lines . That is lines which contain only whitespace and comments .
111
17
35,230
private boolean isWhiteSpace ( Token token ) { return token . kind == Token . Kind . NewLine || isLineSpace ( token ) ; }
Define what is considered to be whitespace .
30
10
35,231
private BigInteger parseCharacter ( String input ) { int pos = 1 ; char c = input . charAt ( pos ++ ) ; if ( c == ' ' ) { // escape code switch ( input . charAt ( pos ++ ) ) { case ' ' : c = ' ' ; break ; case ' ' : c = ' ' ; break ; case ' ' : c = ' ' ; break ; case ' ' : c = ' ' ; break ; case ' ' : c = ' ' ; break ;...
Parse a character from a string of the form c or \ c .
167
15
35,232
protected byte [ ] parseUnicodeString ( Token token ) { String v = token . text ; /* * Parsing a string requires several steps to be taken. First, we need * to strip quotes from the ends of the string. */ v = v . substring ( 1 , v . length ( ) - 1 ) ; StringBuffer result = new StringBuffer ( ) ; // Second, step through...
Parse a string constant whilst interpreting all escape characters .
453
11
35,233
private byte parseBinaryLiteral ( Token input ) { String text = input . text ; if ( text . length ( ) > 11 ) { // FIXME: this will be deprecated! syntaxError ( "invalid binary literal (too long)" , input ) ; } int val = 0 ; // Start past 0b for ( int i = 2 ; i != text . length ( ) ; ++ i ) { char c = text . charAt ( i ...
Parse a token representing a binary literal such as 0b0110 0b1111_0101 etc .
170
22
35,234
private BigInteger parseHexLiteral ( Token input ) { String text = input . text ; // Start past 0x for ( int i = 2 ; i != text . length ( ) ; ++ i ) { char c = text . charAt ( i ) ; if ( c != ' ' && ! isHexDigit ( c ) ) { syntaxError ( "invalid hex literal (invalid characters)" , input ) ; } } // Remove "0x" and "_" te...
Parse a token representing a hex literal such as 0x
133
12
35,235
public static Environment declareThisWithin ( Decl . FunctionOrMethod decl , Environment environment ) { if ( decl instanceof Decl . Method ) { Decl . Method method = ( Decl . Method ) decl ; environment = environment . declareWithin ( "this" , method . getLifetimes ( ) ) ; } return environment ; }
Update the environment to reflect the fact that the special this lifetime is contained within all declared lifetime parameters . Observe that this only makes sense if the enclosing declaration is for a method .
66
37
35,236
public static Tuple < Decl . Variable > determineModifiedVariables ( Stmt . Block block ) { HashSet < Decl . Variable > modified = new HashSet <> ( ) ; determineModifiedVariables ( block , modified ) ; return new Tuple <> ( modified ) ; }
Determine the set of modifier variables for a given statement block . A modified variable is one which is assigned .
61
23
35,237
public static Expr . VariableAccess extractAssignedVariable ( LVal lval ) { if ( lval instanceof Expr . VariableAccess ) { return ( Expr . VariableAccess ) lval ; } else if ( lval instanceof Expr . RecordAccess ) { Expr . RecordAccess e = ( Expr . RecordAccess ) lval ; return extractAssignedVariable ( ( LVal ) e . getO...
Determine the modified variable for a given LVal . Almost all lvals modify exactly one variable though dereferences don t .
197
27
35,238
public static boolean isPure ( SyntacticItem item ) { // Examine expression to determine whether this expression is impure. if ( item instanceof Expr . StaticVariableAccess || item instanceof Expr . Dereference || item instanceof Expr . New ) { return false ; } else if ( item instanceof Expr . Invoke ) { Expr . Invoke ...
Determine whether a given expression calls an impure method dereferences a reference or accesses a static variable . This is done by exploiting the uniform nature of syntactic items . Essentially we just traverse the entire tree representing the syntactic item looking for expressions of any kind .
265
56
35,239
private void translateConstantDeclaration ( WyilFile . Decl . StaticVariable decl ) { if ( decl . hasInitialiser ( ) ) { // The environments are needed to prevent clashes between variable // versions across verification conditions, and also to type variables // used in verification conditions. GlobalEnvironment globalE...
Translate a constant declaration into WyAL . At the moment this does nothing because constant declarations are not supported in WyAL files .
218
26
35,240
private void translateTypeDeclaration ( WyilFile . Decl . Type declaration ) { WyilFile . Tuple < WyilFile . Expr > invariants = declaration . getInvariant ( ) ; WyalFile . Stmt . Block [ ] invariant = new WyalFile . Stmt . Block [ invariants . size ( ) ] ; WyalFile . Type type = convert ( declaration . getType ( ) , d...
Transform a type declaration into verification conditions as necessary . In particular the type should be inhabitable . This means for example that the invariant does not contradict itself . Furthermore we need to translate the type invariant into a macro block .
318
46
35,241
private void translateFunctionOrMethodDeclaration ( WyilFile . Decl . FunctionOrMethod declaration ) { // Create the prototype for this function or method. This is the // function or method declaration which can be used within verification // conditions to refer to this function or method. This does not include // a bo...
Transform a function or method declaration into verification conditions as necessary . This is done by traversing the control - flow graph of the function or method in question . Verifications are emitted when conditions are encountered which must be checked . For example that the preconditions are met at a function in...
409
58
35,242
private void translatePreconditionMacros ( WyilFile . Decl . FunctionOrMethod declaration ) { Tuple < WyilFile . Expr > invariants = declaration . getRequires ( ) ; // for ( int i = 0 ; i != invariants . size ( ) ; ++ i ) { // Construct fresh environment for this macro. This is necessary to // avoid name clashes with s...
Translate the sequence of invariant expressions which constitute the precondition of a function or method into corresponding macro declarations .
281
24
35,243
private Context translateAssert ( WyilFile . Stmt . Assert stmt , Context context ) { Pair < Expr , Context > p = translateExpressionWithChecks ( stmt . getCondition ( ) , null , context ) ; Expr condition = p . first ( ) ; context = p . second ( ) ; // VerificationCondition verificationCondition = new VerificationCond...
Translate an assert statement . This emits a verification condition which ensures the assert condition holds given the current context .
135
22
35,244
private Context translateAssign ( WyilFile . Stmt . Assign stmt , Context context ) { Tuple < WyilFile . LVal > lhs = stmt . getLeftHandSide ( ) ; Tuple < WyilFile . Expr > rhs = stmt . getRightHandSide ( ) ; WyilFile . LVal [ ] [ ] lvals = new LVal [ rhs . size ( ) ] [ ] ; Expr [ ] [ ] rvals = new Expr [ rhs . size ( ...
Translate an assign statement . This updates the version number of the underlying assigned variable .
303
17
35,245
private Context translateAssign ( WyilFile . LVal [ ] lval , Expr [ ] rval , Context context ) { Expr [ ] ls = new Expr [ lval . length ] ; for ( int i = 0 ; i != ls . length ; ++ i ) { WyilFile . LVal lhs = lval [ i ] ; generateTypeInvariantCheck ( lhs . getType ( ) , rval [ i ] , context ) ; context = translateSingle...
Translate an individual assignment from one rval to one or more lvals . If there are multiple lvals then a tuple is created to represent the left - hand side .
127
35
35,246
private Context translateSingleAssignment ( WyilFile . LVal lval , Expr rval , Context context ) { // FIXME: this method is a bit of a kludge. It would be nicer, // eventually, to have all right-hand side expression represented in // WyTP directly. This could potentially be done by including an update // operation in W...
Translate an individual assignment from one rval to exactly one lval .
318
15
35,247
private Context translateRecordAssign ( WyilFile . Expr . RecordAccess lval , Expr rval , Context context ) { // Translate src expression Pair < Expr , Context > p1 = translateExpressionWithChecks ( lval . getOperand ( ) , null , context ) ; Expr source = p1 . first ( ) ; WyalFile . Identifier field = new WyalFile . Id...
Translate an assignment to a field .
167
8
35,248
private Context translateArrayAssign ( WyilFile . Expr . ArrayAccess lval , Expr rval , Context context ) { // Translate src and index expressions Pair < Expr , Context > p1 = translateExpressionWithChecks ( lval . getFirstOperand ( ) , null , context ) ; Pair < Expr , Context > p2 = translateExpressionWithChecks ( lva...
Translate an assignment to an array element .
215
9
35,249
private Context translateDereference ( WyilFile . Expr . Dereference lval , Expr rval , Context context ) { Expr e = translateDereference ( lval , context . getEnvironment ( ) ) ; return context . assume ( new Expr . Equal ( e , rval ) ) ; }
Translate an indirect assignment through a reference .
68
9
35,250
private Context translateVariableAssign ( WyilFile . Expr . VariableAccess lval , Expr rval , Context context ) { WyilFile . Decl . Variable decl = lval . getVariableDeclaration ( ) ; context = context . havoc ( decl ) ; WyalFile . VariableDeclaration nVersionedVar = context . read ( decl ) ; Expr . VariableAccess var ...
Translate an assignment to a variable
114
7
35,251
private WyilFile . Expr . VariableAccess extractAssignedVariable ( WyilFile . LVal lval ) { // switch ( lval . getOpcode ( ) ) { case WyilFile . EXPR_arrayaccess : case WyilFile . EXPR_arrayborrow : Expr . ArrayAccess ae = ( Expr . ArrayAccess ) lval ; return extractAssignedVariable ( ( LVal ) ae . getSource ( ) ) ; ca...
Determine the variable at the root of a given sequence of assignments or return null if there is no statically determinable variable .
256
26
35,252
private Context translateBreak ( WyilFile . Stmt . Break stmt , Context context ) { LoopScope enclosingLoop = context . getEnclosingLoopScope ( ) ; enclosingLoop . addBreakContext ( context ) ; return null ; }
Translate a break statement . This takes the current context and pushes it into the enclosing loop scope . It will then be extracted later and used .
52
30
35,253
private Context translateContinue ( WyilFile . Stmt . Continue stmt , Context context ) { LoopScope enclosingLoop = context . getEnclosingLoopScope ( ) ; enclosingLoop . addContinueContext ( context ) ; return null ; }
Translate a continue statement . This takes the current context and pushes it into the enclosing loop scope . It will then be extracted later and used .
52
30
35,254
private Context translateDoWhile ( WyilFile . Stmt . DoWhile stmt , Context context ) { WyilFile . Decl . FunctionOrMethod declaration = ( WyilFile . Decl . FunctionOrMethod ) context . getEnvironment ( ) . getParent ( ) . enclosingDeclaration ; // Translate the loop invariant and generate appropriate macro translateLo...
Translate a DoWhile statement .
653
7
35,255
private Context translateFail ( WyilFile . Stmt . Fail stmt , Context context ) { Expr condition = new Expr . Constant ( new Value . Bool ( false ) ) ; // VerificationCondition verificationCondition = new VerificationCondition ( "possible panic" , context . assumptions , condition , stmt . getParent ( WyilFile . Attrib...
Translate a fail statement . Execution should never reach such a statement . Hence we need to emit a verification condition to ensure this is the case .
96
29
35,256
private Context translateIf ( WyilFile . Stmt . IfElse stmt , Context context ) { // Pair < Expr , Context > p = translateExpressionWithChecks ( stmt . getCondition ( ) , null , context ) ; Expr trueCondition = p . first ( ) ; // FIXME: this is broken as includes assumptions propagated through // logical &&'s context =...
Translate an if statement . This translates the true and false branches and then recombines them together to form an updated environment . This is challenging when the environments are updated independently in both branches .
236
38
35,257
private Context translateNamedBlock ( WyilFile . Stmt . NamedBlock stmt , Context context ) { return translateStatementBlock ( stmt . getBlock ( ) , context ) ; }
Translate a named block
40
5
35,258
private Context translateReturn ( WyilFile . Stmt . Return stmt , Context context ) { // Tuple < WyilFile . Expr > returns = stmt . getReturns ( ) ; // if ( returns . size ( ) > 0 ) { // There is at least one return value. Therefore, we need to check // any preconditions for those return expressions and, potentially, /...
Translate a return statement . If a return value is given then this must ensure that the post - condition of the enclosing function or method is met
197
30
35,259
private void generateReturnTypeInvariantCheck ( WyilFile . Stmt . Return stmt , Expr [ ] exprs , Context context ) { WyilFile . Decl . FunctionOrMethod declaration = ( WyilFile . Decl . FunctionOrMethod ) context . getEnvironment ( ) . getParent ( ) . enclosingDeclaration ; Tuple < WyilFile . Type > returnTypes = decla...
Generate a return type check in the case that it is necessary . For example if the return type contains a type invariant then it is likely to be necessary . However in the special case that the value being returned is already of appropriate type then it is not .
196
53
35,260
private void generatePostconditionChecks ( WyilFile . Stmt . Return stmt , Expr [ ] exprs , Context context ) { WyilFile . Decl . FunctionOrMethod declaration = ( WyilFile . Decl . FunctionOrMethod ) context . getEnvironment ( ) . getParent ( ) . enclosingDeclaration ; WyilFile . Tuple < WyilFile . Expr > postcondition...
Generate the post - condition checks necessary at a return statement in a function or method .
503
18
35,261
private Context translateSwitch ( WyilFile . Stmt . Switch stmt , Context context ) { Tuple < WyilFile . Stmt . Case > cases = stmt . getCases ( ) ; // Pair < Expr , Context > p = translateExpressionWithChecks ( stmt . getCondition ( ) , null , context ) ; Expr value = p . first ( ) ; context = p . second ( ) ; // Wyal...
Translate a switch statement .
444
6
35,262
private Context translateWhile ( WyilFile . Stmt . While stmt , Context context ) { WyilFile . Decl . FunctionOrMethod declaration = ( WyilFile . Decl . FunctionOrMethod ) context . getEnvironment ( ) . getParent ( ) . enclosingDeclaration ; // Translate the loop invariant and generate appropriate macro translateLoopIn...
Translate a While statement .
493
6
35,263
private void translateLoopInvariantMacros ( Stmt . Loop stmt , WyilFile . Decl . FunctionOrMethod declaration , WyalFile wyalFile ) { // Identifier [ ] prefix = declaration . getQualifiedName ( ) . toName ( ) . getAll ( ) ; Tuple < WyilFile . Expr > loopInvariant = stmt . getInvariant ( ) ; // for ( int i = 0 ; i != lo...
Translate the sequence of invariant expressions which constitute the loop invariant of a loop into one or more macros
293
22
35,264
private Context translateVariableDeclaration ( WyilFile . Decl . Variable stmt , Context context ) { if ( stmt . hasInitialiser ( ) ) { Pair < Expr , Context > p = translateExpressionWithChecks ( stmt . getInitialiser ( ) , null , context ) ; context = p . second ( ) ; generateTypeInvariantCheck ( stmt . getType ( ) , ...
Translate a variable declaration .
117
6
35,265
private Expr translateAsUnknown ( WyilFile . Expr expr , LocalEnvironment environment ) { // What we're doing here is creating a completely fresh variable to // represent the return value. This is basically saying the return value // could be anything, and we don't care what. String name = "r" + Integer . toString ( ex...
Translating as unknown basically means we re not representing the operation in question at the verification level . This could be something that we ll implement in the future or maybe not .
191
35
35,266
private WyalFile . VariableDeclaration [ ] generateQuantifierTypePattern ( WyilFile . Expr . Quantifier expr , LocalEnvironment environment ) { // Tuple < WyilFile . Decl . Variable > params = expr . getParameters ( ) ; WyalFile . VariableDeclaration [ ] vardecls = new WyalFile . VariableDeclaration [ params . size ( )...
Generate a type pattern representing the type and name of all quantifier variables described by this quantifier .
141
21
35,267
private WyalFile . Stmt implies ( WyalFile . Stmt antecedent , WyalFile . Stmt consequent ) { if ( antecedent == null ) { return consequent ; } else { WyalFile . Stmt . Block antecedentBlock = new WyalFile . Stmt . Block ( antecedent ) ; WyalFile . Stmt . Block consequentBlock = new WyalFile . Stmt . Block ( consequent...
Construct an implication from one expression to another
123
8
35,268
private WyalFile . Stmt and ( WyalFile . Stmt lhs , WyalFile . Stmt rhs ) { if ( lhs == null ) { return rhs ; } else if ( rhs == null ) { return rhs ; } else { return new WyalFile . Stmt . Block ( lhs , rhs ) ; } }
Construct a conjunction of two expressions
77
6
35,269
private WyalFile . Stmt or ( WyalFile . Stmt lhs , WyalFile . Stmt rhs ) { if ( lhs == null ) { return rhs ; } else if ( rhs == null ) { return rhs ; } else { WyalFile . Stmt . Block lhsBlock = new WyalFile . Stmt . Block ( lhs ) ; WyalFile . Stmt . Block rhsBlock = new WyalFile . Stmt . Block ( rhs ) ; return new Wyal...
Construct a disjunct of two expressions
132
8
35,270
private AssumptionSet updateVariableVersions ( AssumptionSet assumptions , LocalEnvironment original , LocalEnvironment updated ) { for ( Map . Entry < WyilFile . Decl . Variable , WyalFile . VariableDeclaration > e : updated . locals . entrySet ( ) ) { WyilFile . Decl . Variable var = e . getKey ( ) ; WyalFile . Varia...
Bring a given assumption set which is consistent with an original environment up - to - date with a new environment .
211
22
35,271
private LocalEnvironment joinEnvironments ( Context ... contexts ) { // Context head = contexts [ 0 ] ; GlobalEnvironment global = head . getEnvironment ( ) . getParent ( ) ; HashSet < WyilFile . Decl . Variable > modified = new HashSet <> ( ) ; HashSet < WyilFile . Decl . Variable > deleted = new HashSet <> ( ) ; Map ...
Join the local environments of one or more context s together . This means retaining variable versions which are the same for all context s allocating new versions for those which are different in at least one case and removing those which aren t present it at least one .
647
51
35,272
private void createFunctionOrMethodPrototype ( WyilFile . Decl . FunctionOrMethod declaration ) { Tuple < WyilFile . Decl . Variable > params = declaration . getParameters ( ) ; Tuple < WyilFile . Decl . Variable > returns = declaration . getReturns ( ) ; // WyalFile . VariableDeclaration [ ] parameters = new WyalFile ...
Construct a function or method prototype with a given name and type . The function or method can then be called elsewhere as an uninterpreted function . The function or method doesn t have a body but is used as a name to be referred to from assertions .
390
51
35,273
private void createAssertions ( WyilFile . Decl declaration , List < VerificationCondition > vcs , GlobalEnvironment environment ) { // FIXME: should be logged somehow? for ( int i = 0 ; i != vcs . size ( ) ; ++ i ) { VerificationCondition vc = vcs . get ( i ) ; // Build the actual verification condition WyalFile . Stm...
Turn each verification condition into an assertion in the underlying WyalFile being generated . The main challenge here is to ensure that all variables used in the assertion are properly typed .
233
34
35,274
public WyalFile . Stmt . Block buildVerificationCondition ( WyilFile . Decl declaration , GlobalEnvironment environment , VerificationCondition vc ) { WyalFile . Stmt antecedent = flatten ( vc . antecedent ) ; Expr consequent = vc . consequent ; HashSet < WyalFile . VariableDeclaration > freeVariables = new HashSet <> ...
Construct a fully typed and quantified expression for representing a verification condition . Aside from flattening the various components it must also determine appropriate variable types including those for aliased variables .
332
35
35,275
private WyalFile . Stmt flatten ( AssumptionSet assumptions ) { WyalFile . Stmt result = flattenUpto ( assumptions , null ) ; if ( result == null ) { return new Expr . Constant ( new Value . Bool ( true ) ) ; } else { return result ; } }
Flatten a given assumption set into a single logical condition . The key challenge here is to try and do this as efficiency as possible .
67
27
35,276
private WyalFile . Stmt flattenUpto ( AssumptionSet assumptions , AssumptionSet ancestor ) { if ( assumptions == ancestor ) { // We have reached the ancestor return null ; } else { // Flattern parent assumptions AssumptionSet [ ] parents = assumptions . parents ; WyalFile . Stmt e = null ; switch ( parents . length ) {...
Flatten an assumption set upto a given ancestor . That is do not include the ancestor or any of its ancestors in the results . This is a little like taking the difference of the given assumptions and the given ancestor s assumptions .
253
46
35,277
private Expr determineVariableAliases ( GlobalEnvironment environment , Set < WyalFile . VariableDeclaration > freeVariables ) { Expr aliases = null ; for ( WyalFile . VariableDeclaration var : freeVariables ) { WyalFile . VariableDeclaration parent = environment . getParent ( var ) ; if ( parent != null ) { // This in...
Determine any variable aliases which need to be accounted for . This is done by adding an equality between the aliased variables to ensure they have the same value .
160
33
35,278
private WyalFile . VariableDeclaration [ ] generatePreconditionParameters ( WyilFile . Decl . Callable declaration , LocalEnvironment environment ) { Tuple < WyilFile . Decl . Variable > params = declaration . getParameters ( ) ; WyalFile . VariableDeclaration [ ] vars = new WyalFile . VariableDeclaration [ params . si...
Convert the parameter types for a given function or method declaration into a corresponding list of type patterns . This is primarily useful for generating declarations from functions or method .
138
32
35,279
private WyalFile . VariableDeclaration [ ] generatePostconditionTypePattern ( WyilFile . Decl . FunctionOrMethod declaration , LocalEnvironment environment ) { Tuple < Decl . Variable > params = declaration . getParameters ( ) ; Tuple < Decl . Variable > returns = declaration . getReturns ( ) ; WyalFile . VariableDecla...
Convert the return types for a given function or method declaration into a corresponding list of type patterns . This is primarily useful for generating declarations from functions or method .
214
32
35,280
private WyalFile . VariableDeclaration [ ] generateLoopInvariantParameterDeclarations ( Stmt . Loop loop , LocalEnvironment environment ) { // Extract all used variables within the loop invariant. This is necessary to // determine what parameters are required for the loop invariant macros. Tuple < Decl . Variable > mod...
Convert the types of local variables in scope at a given position within a function or method into a type pattern . This is primarily useful for determining the types for a loop invariant macro .
170
38
35,281
public Tuple < Decl . Variable > determineUsedVariables ( Tuple < WyilFile . Expr > exprs ) { HashSet < Decl . Variable > used = new HashSet <> ( ) ; usedVariableExtractor . visitExpressions ( exprs , used ) ; return new Tuple <> ( used ) ; }
Determine the set of used variables in a given set of expressions . A used variable is one referred to by a VariableAccess expression .
70
28
35,282
public WyalFile . Name convert ( QualifiedName id , SyntacticItem context ) { return convert ( id . getUnit ( ) , id . getName ( ) . get ( ) , context ) ; }
Convert a Name identifier from a WyIL into one suitable for a WyAL file .
44
18
35,283
public WyalFile . Name convert ( QualifiedName id , String suffix , SyntacticItem context ) { return convert ( id . getUnit ( ) , id . getName ( ) . get ( ) . concat ( suffix ) , context ) ; }
Convert a qualified name along with an additional suffix into one suitable for a WyAL file .
53
19
35,284
private static boolean typeMayHaveInvariant ( Type type , Context context ) { if ( type instanceof Type . Void ) { return false ; } else if ( type instanceof Type . Null ) { return false ; } else if ( type instanceof Type . Bool ) { return false ; } else if ( type instanceof Type . Byte ) { return false ; } else if ( t...
Perform a simple check to see whether or not a given type may have an invariant or not .
497
21
35,285
public void freeVariables ( SyntacticItem e , Set < WyalFile . VariableDeclaration > freeVars ) { if ( e instanceof Expr . VariableAccess ) { Expr . VariableAccess va = ( Expr . VariableAccess ) e ; freeVars . add ( va . getVariableDeclaration ( ) ) ; } else if ( e instanceof Expr . Quantifier ) { Expr . Quantifier q =...
Determine all free variables which are used within the given expression . A free variable is one which is not bound within the expression itself .
208
28
35,286
private static < T > T [ ] removeNull ( T [ ] items ) { int count = 0 ; for ( int i = 0 ; i != items . length ; ++ i ) { if ( items [ i ] == null ) { count = count + 1 ; } } if ( count == 0 ) { return items ; } else { T [ ] rs = java . util . Arrays . copyOf ( items , items . length - count ) ; for ( int i = 0 , j = 0 ...
Create exact copy of a given array but with evey null element removed .
145
15
35,287
private boolean isApplicable ( Type . Callable candidate , LifetimeRelation lifetimes , Tuple < ? extends SemanticType > args ) { Tuple < Type > parameters = candidate . getParameters ( ) ; if ( parameters . size ( ) != args . size ( ) ) { // Differing number of parameters / arguments. Since we don't // support variabl...
Determine whether a given function or method declaration is applicable to a given set of argument types . If there number of arguments differs it s definitely not applicable . Otherwise we need every argument type to be a subtype of its corresponding parameter type .
189
49
35,288
private Binding selectCallableCandidate ( Name name , List < Binding > candidates , LifetimeRelation lifetimes ) { Binding best = null ; Type . Callable bestType = null ; boolean bestValidWinner = false ; // for ( int i = 0 ; i != candidates . size ( ) ; ++ i ) { Binding candidate = candidates . get ( i ) ; Type . Call...
Given a list of candidate function or method declarations determine the most precise match for the supplied argument types . The given argument types must be applicable to this function or macro declaration and it must be a subtype of all other applicable candidates .
481
46
35,289
private boolean isSubtype ( Type . Callable lhs , Type . Callable rhs , LifetimeRelation lifetimes ) { Tuple < Type > parentParams = lhs . getParameters ( ) ; Tuple < Type > childParams = rhs . getParameters ( ) ; if ( parentParams . size ( ) != childParams . size ( ) ) { // Differing number of parameters / arguments. ...
Check whether the type signature for a given function or method declaration is a super type of a given child declaration .
224
22
35,290
private static int extractNonMatchingFields ( Tuple < Type . Field > lhsFields , Tuple < Type . Field > rhsFields , Type . Field [ ] result , int index ) { outer : for ( int i = 0 ; i != lhsFields . size ( ) ; ++ i ) { for ( int j = 0 ; j != rhsFields . size ( ) ; ++ j ) { Type . Field lhsField = lhsFields . get ( i ) ...
Extract fields from lhs which do not match any field in the rhs . That is there is no field in the rhs with the same name .
217
32
35,291
public boolean apply ( ) { // FIXME: need to make this incremental // Create initial set of patches. List < Patch > patches = resolver . apply ( target ) ; // Keep iterating until all patches are resolved while ( patches . size ( ) > 0 ) { // Create importer Importer importer = new Importer ( target , true ) ; // Now c...
Apply this name resolver to a given WyilFile .
167
12
35,292
private List < WyilFile > getExternals ( ) throws IOException { ArrayList < WyilFile > externals = new ArrayList <> ( ) ; List < Build . Package > pkgs = project . getPackages ( ) ; // Consider each package in turn and identify all contained WyilFiles for ( int i = 0 ; i != pkgs . size ( ) ; ++ i ) { Build . Package p ...
Read in all external packages so they can be used for name resolution . This amounts to loading in every WyilFile contained within an external package dependency .
217
30
35,293
public void checkTypeDeclaration ( Decl . Type decl ) { Environment environment = new Environment ( ) ; // Check type is contractive checkContractive ( decl ) ; // Check variable declaration is not empty checkVariableDeclaration ( decl . getVariableDeclaration ( ) , environment ) ; // Check the type invariant checkCond...
Resolve types for a given type declaration . If an invariant expression is given then we have to check and resolve types throughout the expression .
83
28
35,294
public void checkStaticVariableDeclaration ( Decl . StaticVariable decl ) { Environment environment = new Environment ( ) ; // Check type not void checkVariableDeclaration ( decl , environment ) ; }
check and check types for a given constant declaration .
39
10
35,295
public void checkFunctionOrMethodDeclaration ( Decl . FunctionOrMethod d ) { // Construct initial environment Environment environment = new Environment ( ) ; // Update environment so this within declared lifetimes environment = FlowTypeUtils . declareThisWithin ( d , environment ) ; // Check parameters and returns are ...
Type check a given function or method declaration .
313
9
35,296
private void checkReturnValue ( Decl . FunctionOrMethod d , Environment last ) { if ( d . match ( Modifier . Native . class ) == null && last != FlowTypeUtils . BOTTOM && d . getReturns ( ) . size ( ) != 0 ) { // In this case, code reaches the end of the function or method and, // furthermore, that this requires a retu...
Check that a return value is provided when it is needed . For example a return value is not required for a method that has no return type . Likewise we don t expect one from a native method since there was no body to analyse .
122
47
35,297
private Environment checkBlock ( Stmt . Block block , Environment environment , EnclosingScope scope ) { for ( int i = 0 ; i != block . size ( ) ; ++ i ) { Stmt stmt = block . get ( i ) ; environment = checkStatement ( stmt , environment , scope ) ; } return environment ; }
check type information in a flow - sensitive fashion through a block of statements whilst type checking each statement and expression .
70
22
35,298
private Environment checkFail ( Stmt . Fail stmt , Environment environment , EnclosingScope scope ) { return FlowTypeUtils . BOTTOM ; }
Type check a fail statement . The environment after a fail statement is bottom because that represents an unreachable program point .
33
23
35,299
private Environment checkVariableDeclarations ( Tuple < Decl . Variable > decls , Environment environment ) { for ( int i = 0 ; i != decls . size ( ) ; ++ i ) { environment = checkVariableDeclaration ( decls . get ( i ) , environment ) ; } return environment ; }
Type check a given sequence of variable declarations .
64
9