use of org.wso2.ballerinalang.compiler.tree.BLangVariable in project ballerina by ballerina-lang.
the class CodeGenerator method createStructInfoEntry.
private void createStructInfoEntry(BLangStruct structNode) {
BStructSymbol structSymbol = (BStructSymbol) structNode.symbol;
// Add Struct name as an UTFCPEntry to the constant pool
int structNameCPIndex = addUTF8CPEntry(currentPkgInfo, structSymbol.name.value);
StructInfo structInfo = new StructInfo(currentPackageRefCPIndex, structNameCPIndex, structSymbol.flags);
currentPkgInfo.addStructInfo(structSymbol.name.value, structInfo);
structInfo.structType = (BStructType) structSymbol.type;
List<BLangVariable> structFields = structNode.fields;
for (BLangVariable structField : structFields) {
// Create StructFieldInfo Entry
int fieldNameCPIndex = addUTF8CPEntry(currentPkgInfo, structField.name.value);
int sigCPIndex = addUTF8CPEntry(currentPkgInfo, structField.type.getDesc());
StructFieldInfo structFieldInfo = new StructFieldInfo(fieldNameCPIndex, sigCPIndex, structField.symbol.flags);
structFieldInfo.fieldType = structField.type;
// Populate default values
if (structField.expr != null && structField.expr.getKind() == NodeKind.LITERAL) {
DefaultValueAttributeInfo defaultVal = getDefaultValueAttributeInfo((BLangLiteral) structField.expr);
structFieldInfo.addAttributeInfo(AttributeInfo.Kind.DEFAULT_VALUE_ATTRIBUTE, defaultVal);
}
structInfo.fieldInfoEntries.add(structFieldInfo);
structField.symbol.varIndex = getFieldIndex(structField.symbol.type.tag);
}
// Create variable count attribute info
prepareIndexes(fieldIndexes);
int[] fieldCount = new int[] { fieldIndexes.tInt, fieldIndexes.tFloat, fieldIndexes.tString, fieldIndexes.tBoolean, fieldIndexes.tBlob, fieldIndexes.tRef };
addVariableCountAttributeInfo(currentPkgInfo, structInfo, fieldCount);
fieldIndexes = new VariableIndex(FIELD);
// Create attached function info entries
for (BAttachedFunction attachedFunc : structSymbol.attachedFuncs) {
int funcNameCPIndex = addUTF8CPEntry(currentPkgInfo, attachedFunc.funcName.value);
// Remove the first type. The first type is always the type to which the function is attached to
BType[] paramTypes = attachedFunc.type.paramTypes.toArray(new BType[0]);
if (paramTypes.length == 1) {
paramTypes = new BType[0];
} else {
paramTypes = attachedFunc.type.paramTypes.toArray(new BType[0]);
paramTypes = Arrays.copyOfRange(paramTypes, 1, paramTypes.length);
}
int sigCPIndex = addUTF8CPEntry(currentPkgInfo, generateFunctionSig(paramTypes, attachedFunc.type.retTypes.toArray(new BType[0])));
int flags = attachedFunc.symbol.flags;
structInfo.attachedFuncInfoEntries.add(new AttachedFunctionInfo(funcNameCPIndex, sigCPIndex, flags));
}
}
use of org.wso2.ballerinalang.compiler.tree.BLangVariable in project ballerina by ballerina-lang.
the class CodeGenerator method setParameterNames.
private void setParameterNames(BLangResource resourceNode, ResourceInfo resourceInfo) {
int paramCount = resourceNode.requiredParams.size();
resourceInfo.paramNameCPIndexes = new int[paramCount];
for (int i = 0; i < paramCount; i++) {
BLangVariable paramVar = resourceNode.requiredParams.get(i);
String paramName = null;
boolean isAnnotated = false;
for (BLangAnnotationAttachment annotationAttachment : paramVar.annAttachments) {
String attachmentName = annotationAttachment.getAnnotationName().getValue();
if ("PathParam".equalsIgnoreCase(attachmentName) || "QueryParam".equalsIgnoreCase(attachmentName)) {
// TODO:
// paramName = annotationAttachment.getAttributeNameValuePairs().get("value")
// .getLiteralValue().stringValue();
isAnnotated = true;
break;
}
}
if (!isAnnotated) {
paramName = paramVar.name.getValue();
}
int paramNameCPIndex = addUTF8CPEntry(currentPkgInfo, paramName);
resourceInfo.paramNameCPIndexes[i] = paramNameCPIndex;
}
}
use of org.wso2.ballerinalang.compiler.tree.BLangVariable in project ballerina by ballerina-lang.
the class CodeGenerator method visit.
public void visit(BLangCatch bLangCatch) {
// Define local variable index for Error.
BLangVariable variable = bLangCatch.param;
RegIndex lvIndex = getLVIndex(variable.symbol.type.tag);
variable.symbol.varIndex = lvIndex;
emit(InstructionFactory.get(InstructionCodes.ERRSTORE, lvIndex));
// Visit Catch Block.
genNode(bLangCatch.body, env);
}
use of org.wso2.ballerinalang.compiler.tree.BLangVariable in project ballerina by ballerina-lang.
the class ASTBuilderUtil method createInvocationExpr.
static BLangInvocation createInvocationExpr(DiagnosticPos pos, BInvokableSymbol invokableSymbol, List<BLangVariable> requiredArgs, List<BLangVariable> namedArgs, List<BLangVariable> restArgs, SymbolResolver symResolver) {
final BLangInvocation invokeLambda = (BLangInvocation) TreeBuilder.createInvocationNode();
invokeLambda.pos = pos;
invokeLambda.requiredArgs.addAll(generateArgExprs(pos, requiredArgs, invokableSymbol.params, symResolver));
invokeLambda.namedArgs.addAll(generateArgExprs(pos, namedArgs, invokableSymbol.defaultableParams, symResolver));
invokeLambda.restArgs.addAll(generateArgExprs(pos, restArgs, Lists.of(invokableSymbol.restParam), symResolver));
invokeLambda.symbol = invokableSymbol;
invokeLambda.types.addAll(((BInvokableType) invokableSymbol.type).retTypes);
if (!invokeLambda.types.isEmpty()) {
invokeLambda.type = invokeLambda.types.get(0);
}
return invokeLambda;
}
use of org.wso2.ballerinalang.compiler.tree.BLangVariable in project ballerina by ballerina-lang.
the class ASTBuilderUtil method defineVariable.
static void defineVariable(BLangVariable variable, BSymbol targetSymbol, Names names) {
variable.symbol = new BVarSymbol(0, names.fromIdNode(variable.name), targetSymbol.pkgID, variable.type, targetSymbol);
targetSymbol.scope.define(variable.symbol.name, variable.symbol);
}
Aggregations