use of org.wso2.ballerinalang.compiler.tree.expressions.BLangIndexBasedAccess in project ballerina by ballerina-lang.
the class TaintAnalyzer method updatedVarRefTaintedState.
private void updatedVarRefTaintedState(BLangVariableReference varRef, boolean taintedState) {
if (varRef instanceof BLangSimpleVarRef) {
setTaintedStatus(varRef, taintedState);
} else if (varRef instanceof BLangIndexBasedAccess) {
BLangIndexBasedAccess indexBasedAccessExpr = (BLangIndexBasedAccess) varRef;
updatedVarRefTaintedState(indexBasedAccessExpr.expr, taintedState);
} else if (varRef instanceof BLangFieldBasedAccess) {
BLangFieldBasedAccess fieldBasedAccessExpr = (BLangFieldBasedAccess) varRef;
updatedVarRefTaintedState(fieldBasedAccessExpr.expr, taintedState);
}
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangIndexBasedAccess in project ballerina by ballerina-lang.
the class ASTBuilderUtil method createIndexBasesAccessExpr.
static BLangIndexBasedAccess createIndexBasesAccessExpr(DiagnosticPos pos, BType type, BVarSymbol varSymbol, BLangExpression indexExpr) {
final BLangIndexBasedAccess arrayAccess = (BLangIndexBasedAccess) TreeBuilder.createIndexBasedAccessNode();
arrayAccess.pos = pos;
arrayAccess.expr = createVariableRef(pos, varSymbol);
arrayAccess.indexExpr = indexExpr;
arrayAccess.type = type;
return arrayAccess;
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangIndexBasedAccess in project ballerina by ballerina-lang.
the class AnnotationDesugar method createAnnotationMapEntryVar.
private BLangVariable createAnnotationMapEntryVar(String key, BLangVariable annotationMapVar, BLangBlockStmt target, BSymbol parentSymbol) {
// create: map key = {};
final BLangRecordLiteral recordLiteralNode = ASTBuilderUtil.createEmptyRecordLiteral(target.pos, symTable.mapType);
BLangVariable entryVariable = ASTBuilderUtil.createVariable(target.pos, key, recordLiteralNode.type);
entryVariable.expr = recordLiteralNode;
ASTBuilderUtil.defineVariable(entryVariable, parentSymbol, names);
ASTBuilderUtil.createVariableDefStmt(target.pos, target).var = entryVariable;
// create: annotationMapVar["key"] = key;
BLangAssignment assignmentStmt = ASTBuilderUtil.createAssignmentStmt(target.pos, target);
assignmentStmt.expr = ASTBuilderUtil.createVariableRef(target.pos, entryVariable.symbol);
BLangIndexBasedAccess indexAccessNode = (BLangIndexBasedAccess) TreeBuilder.createIndexBasedAccessNode();
indexAccessNode.pos = target.pos;
indexAccessNode.indexExpr = ASTBuilderUtil.createLiteral(target.pos, symTable.stringType, key);
indexAccessNode.expr = ASTBuilderUtil.createVariableRef(target.pos, annotationMapVar.symbol);
indexAccessNode.type = recordLiteralNode.type;
assignmentStmt.varRefs.add(indexAccessNode);
return entryVariable;
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangIndexBasedAccess in project ballerina by ballerina-lang.
the class AnnotationDesugar method initAnnotation.
private void initAnnotation(BLangAnnotationAttachment attachment, BLangVariable annotationMapEntryVar, BLangBlockStmt target, BSymbol parentSymbol, int index) {
BLangVariable annotationVar = null;
if (attachment.annotationSymbol.attachedType != null) {
// create: AttachedType annotationVar = { annotation-expression }
annotationVar = ASTBuilderUtil.createVariable(attachment.pos, attachment.annotationName.value, attachment.annotationSymbol.attachedType.type);
annotationVar.expr = attachment.expr;
ASTBuilderUtil.defineVariable(annotationVar, parentSymbol, names);
ASTBuilderUtil.createVariableDefStmt(attachment.pos, target).var = annotationVar;
}
// create: annotationMapEntryVar["name$index"] = annotationVar;
BLangAssignment assignmentStmt = ASTBuilderUtil.createAssignmentStmt(target.pos, target);
if (annotationVar != null) {
assignmentStmt.expr = ASTBuilderUtil.createVariableRef(target.pos, annotationVar.symbol);
} else {
assignmentStmt.expr = ASTBuilderUtil.createLiteral(target.pos, symTable.nullType, null);
}
BLangIndexBasedAccess indexAccessNode = (BLangIndexBasedAccess) TreeBuilder.createIndexBasedAccessNode();
indexAccessNode.pos = target.pos;
indexAccessNode.indexExpr = ASTBuilderUtil.createLiteral(target.pos, symTable.stringType, attachment.annotationSymbol.bvmAlias() + "$" + index);
indexAccessNode.expr = ASTBuilderUtil.createVariableRef(target.pos, annotationMapEntryVar.symbol);
indexAccessNode.type = annotationMapEntryVar.symbol.type;
assignmentStmt.varRefs.add(indexAccessNode);
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangIndexBasedAccess in project ballerina by ballerina-lang.
the class IterableCodeDesugar method generateMapAggregator.
/**
* Generates following.
*
* result[key] = value;
*
* @param blockStmt target
* @param ctx current context
*/
private void generateMapAggregator(BLangBlockStmt blockStmt, IterableContext ctx) {
final DiagnosticPos pos = blockStmt.pos;
// create assignment result[key] = value
final BLangIndexBasedAccess indexAccessNode = (BLangIndexBasedAccess) TreeBuilder.createIndexBasedAccessNode();
indexAccessNode.pos = pos;
indexAccessNode.indexExpr = ASTBuilderUtil.createVariableRef(pos, ctx.iteratorResultVariables.get(0).symbol);
indexAccessNode.expr = ASTBuilderUtil.createVariableRef(pos, ctx.resultVar.symbol);
indexAccessNode.type = ctx.iteratorResultVariables.get(1).symbol.type;
final BLangAssignment valueAssign = ASTBuilderUtil.createAssignmentStmt(pos, blockStmt);
valueAssign.varRefs.add(indexAccessNode);
valueAssign.expr = ASTBuilderUtil.generateConversionExpr(ASTBuilderUtil.createVariableRef(pos, ctx.iteratorResultVariables.get(1).symbol), symTable.anyType, symResolver);
}
Aggregations