use of org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.FIELD in project ballerina by ballerina-lang.
the class TaintAnalyzer method visit.
public void visit(BLangStruct structNode) {
BSymbol structSymbol = structNode.symbol;
SymbolEnv structEnv = SymbolEnv.createPkgLevelSymbolEnv(structNode, structSymbol.scope, env);
structNode.fields.forEach(field -> analyzeNode(field, structEnv));
}
use of org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.FIELD in project ballerina by ballerina-lang.
the class SemanticAnalyzer method visit.
public void visit(BLangObject objectNode) {
BSymbol objectSymbol = objectNode.symbol;
SymbolEnv objectEnv = SymbolEnv.createPkgLevelSymbolEnv(objectNode, objectSymbol.scope, env);
objectNode.fields.forEach(field -> analyzeDef(field, objectEnv));
objectNode.annAttachments.forEach(annotationAttachment -> {
annotationAttachment.attachmentPoint = new BLangAnnotationAttachmentPoint(BLangAnnotationAttachmentPoint.AttachmentPoint.STRUCT);
annotationAttachment.accept(this);
});
objectNode.docAttachments.forEach(doc -> analyzeDef(doc, objectEnv));
analyzeDef(objectNode.initFunction, objectEnv);
// Visit temporary init statements in the init function
SymbolEnv funcEnv = SymbolEnv.createFunctionEnv(objectNode.initFunction, objectNode.initFunction.symbol.scope, objectEnv);
objectNode.initFunction.initFunctionStmts.values().forEach(s -> analyzeNode(s, funcEnv));
objectNode.functions.forEach(f -> analyzeDef(f, objectEnv));
}
use of org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.FIELD in project ballerina by ballerina-lang.
the class TypeChecker method checkStructLiteralKeyExpr.
private BType checkStructLiteralKeyExpr(BLangRecordKey key, BType recordType, RecordKind recKind) {
Name fieldName;
BLangExpression keyExpr = key.expr;
if (keyExpr.getKind() == NodeKind.SIMPLE_VARIABLE_REF) {
BLangSimpleVarRef varRef = (BLangSimpleVarRef) keyExpr;
fieldName = names.fromIdNode(varRef.variableName);
} else {
// keys of the struct literal can only be a varRef (identifier)
dlog.error(keyExpr.pos, DiagnosticCode.INVALID_STRUCT_LITERAL_KEY);
return symTable.errType;
}
// Check weather the struct field exists
BSymbol fieldSymbol = symResolver.resolveStructField(keyExpr.pos, this.env, fieldName, recordType.tsymbol);
if (fieldSymbol == symTable.notFoundSymbol) {
dlog.error(keyExpr.pos, DiagnosticCode.UNDEFINED_STRUCT_FIELD, fieldName, recordType.tsymbol);
return symTable.errType;
}
// Setting the struct field symbol for future use in Desugar and code generator.
key.fieldSymbol = (BVarSymbol) fieldSymbol;
return fieldSymbol.type;
}
use of org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.FIELD in project ballerina by ballerina-lang.
the class TypeChecker method checkRecLiteralKeyValue.
private void checkRecLiteralKeyValue(BLangRecordKeyValue keyValuePair, BType recType) {
BType fieldType = symTable.errType;
BLangExpression valueExpr = keyValuePair.valueExpr;
switch(recType.tag) {
case TypeTags.STRUCT:
fieldType = checkStructLiteralKeyExpr(keyValuePair.key, recType, RecordKind.STRUCT);
break;
case TypeTags.MAP:
fieldType = checkMapLiteralKeyExpr(keyValuePair.key.expr, recType, RecordKind.MAP);
break;
case TypeTags.JSON:
fieldType = checkJSONLiteralKeyExpr(keyValuePair.key, recType, RecordKind.JSON);
// If the field is again a struct, treat that literal expression as another constraint JSON.
if (fieldType.tag == TypeTags.STRUCT) {
fieldType = new BJSONType(TypeTags.JSON, fieldType, symTable.jsonType.tsymbol);
}
// First visit the expression having field type, as the expected type.
checkExpr(valueExpr, this.env, Lists.of(fieldType));
// Again check the type compatibility with JSON
if (valueExpr.impConversionExpr == null) {
types.checkTypes(valueExpr, Lists.of(valueExpr.type), Lists.of(symTable.jsonType));
} else {
BType valueType = valueExpr.type;
types.checkTypes(valueExpr, valueExpr.impConversionExpr.types, Lists.of(symTable.jsonType));
valueExpr.type = valueType;
}
resultTypes = Lists.of(valueExpr.type);
return;
}
checkExpr(valueExpr, this.env, Lists.of(fieldType));
}
use of org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.FIELD in project ballerina by ballerina-lang.
the class CodeGenerator method getRegIndexInternal.
private RegIndex getRegIndexInternal(int typeTag, VariableIndex.Kind varIndexKind) {
int index;
switch(varIndexKind) {
case REG:
return new RegIndex(getNextIndex(typeTag, regIndexes), typeTag);
case PACKAGE:
index = getNextIndex(typeTag, pvIndexes);
break;
case FIELD:
index = getNextIndex(typeTag, fieldIndexes);
break;
default:
index = getNextIndex(typeTag, lvIndexes);
break;
}
RegIndex regIndex = new RegIndex(index, typeTag);
regIndex.isVarIndex = true;
return regIndex;
}
Aggregations