use of org.ballerinalang.util.codegen.attributes.LocalVariableAttributeInfo in project ballerina by ballerina-lang.
the class ResourceImpl method getParamDetails.
@Override
public List<ParamDetail> getParamDetails() {
LocalVariableAttributeInfo attributeInfo = (LocalVariableAttributeInfo) resourceInfo.getAttributeInfo(AttributeInfo.Kind.LOCAL_VARIABLES_ATTRIBUTE);
List<ParamDetail> paramDetails = new ArrayList<>();
for (LocalVariableInfo variableInfo : attributeInfo.getLocalVariableInfoEntries()) {
paramDetails.add(new ParamDetail(variableInfo.getVariableType(), variableInfo.getVariableName()));
}
return paramDetails;
}
use of org.ballerinalang.util.codegen.attributes.LocalVariableAttributeInfo in project ballerina by ballerina-lang.
the class ProgramFileReader method getAttributeInfo.
private AttributeInfo getAttributeInfo(DataInputStream dataInStream, ConstantPool constantPool) throws IOException {
int attribNameCPIndex = dataInStream.readInt();
UTF8CPEntry attribNameCPEntry = (UTF8CPEntry) constantPool.getCPEntry(attribNameCPIndex);
AttributeInfo.Kind attribKind = AttributeInfo.Kind.fromString(attribNameCPEntry.getValue());
if (attribKind == null) {
throw new ProgramFileFormatException("unknown attribute kind " + attribNameCPEntry.getValue());
}
switch(attribKind) {
case CODE_ATTRIBUTE:
CodeAttributeInfo codeAttributeInfo = new CodeAttributeInfo();
codeAttributeInfo.setAttributeNameIndex(attribNameCPIndex);
codeAttributeInfo.setCodeAddrs(dataInStream.readInt());
codeAttributeInfo.setMaxLongLocalVars(dataInStream.readUnsignedShort());
codeAttributeInfo.setMaxDoubleLocalVars(dataInStream.readShort());
codeAttributeInfo.setMaxStringLocalVars(dataInStream.readShort());
codeAttributeInfo.setMaxIntLocalVars(dataInStream.readShort());
codeAttributeInfo.setMaxByteLocalVars(dataInStream.readShort());
codeAttributeInfo.setMaxRefLocalVars(dataInStream.readShort());
codeAttributeInfo.setMaxLongRegs(dataInStream.readShort());
codeAttributeInfo.setMaxDoubleRegs(dataInStream.readShort());
codeAttributeInfo.setMaxStringRegs(dataInStream.readShort());
codeAttributeInfo.setMaxIntRegs(dataInStream.readShort());
codeAttributeInfo.setMaxByteRegs(dataInStream.readShort());
codeAttributeInfo.setMaxRefRegs(dataInStream.readShort());
return codeAttributeInfo;
case VARIABLE_TYPE_COUNT_ATTRIBUTE:
VarTypeCountAttributeInfo varCountAttributeInfo = new VarTypeCountAttributeInfo(attribNameCPIndex);
varCountAttributeInfo.setMaxLongVars(dataInStream.readShort());
varCountAttributeInfo.setMaxDoubleVars(dataInStream.readShort());
varCountAttributeInfo.setMaxStringVars(dataInStream.readShort());
varCountAttributeInfo.setMaxIntVars(dataInStream.readShort());
varCountAttributeInfo.setMaxByteVars(dataInStream.readShort());
varCountAttributeInfo.setMaxRefVars(dataInStream.readShort());
return varCountAttributeInfo;
case ERROR_TABLE:
ErrorTableAttributeInfo tableAttributeInfo = new ErrorTableAttributeInfo(attribNameCPIndex);
int tableEntryCount = dataInStream.readShort();
for (int i = 0; i < tableEntryCount; i++) {
int ipFrom = dataInStream.readInt();
int ipTo = dataInStream.readInt();
int ipTarget = dataInStream.readInt();
int priority = dataInStream.readInt();
int errorStructCPIndex = dataInStream.readInt();
ErrorTableEntry tableEntry = new ErrorTableEntry(ipFrom, ipTo, ipTarget, priority, errorStructCPIndex);
if (errorStructCPIndex != -1) {
StructureRefCPEntry structureRefCPEntry = (StructureRefCPEntry) constantPool.getCPEntry(errorStructCPIndex);
tableEntry.setError((StructInfo) structureRefCPEntry.getStructureTypeInfo());
}
tableAttributeInfo.addErrorTableEntry(tableEntry);
}
return tableAttributeInfo;
case LOCAL_VARIABLES_ATTRIBUTE:
LocalVariableAttributeInfo localVarAttrInfo = new LocalVariableAttributeInfo(attribNameCPIndex);
int localVarInfoCount = dataInStream.readShort();
for (int i = 0; i < localVarInfoCount; i++) {
LocalVariableInfo localVariableInfo = getLocalVariableInfo(dataInStream, constantPool);
localVarAttrInfo.addLocalVarInfo(localVariableInfo);
}
return localVarAttrInfo;
case LINE_NUMBER_TABLE_ATTRIBUTE:
LineNumberTableAttributeInfo lnNoTblAttrInfo = new LineNumberTableAttributeInfo(attribNameCPIndex);
int lineNoInfoCount = dataInStream.readShort();
for (int i = 0; i < lineNoInfoCount; i++) {
LineNumberInfo lineNumberInfo = getLineNumberInfo(dataInStream, constantPool);
lnNoTblAttrInfo.addLineNumberInfo(lineNumberInfo);
}
return lnNoTblAttrInfo;
case DEFAULT_VALUE_ATTRIBUTE:
DefaultValue defaultValue = getDefaultValue(dataInStream, constantPool);
DefaultValueAttributeInfo defaultValAttrInfo = new DefaultValueAttributeInfo(attribNameCPIndex, defaultValue);
return defaultValAttrInfo;
case PARAMETER_DEFAULTS_ATTRIBUTE:
ParamDefaultValueAttributeInfo paramDefaultValAttrInfo = new ParamDefaultValueAttributeInfo(attribNameCPIndex);
int paramDefaultsInfoCount = dataInStream.readShort();
for (int i = 0; i < paramDefaultsInfoCount; i++) {
DefaultValue paramDefaultValue = getDefaultValue(dataInStream, constantPool);
paramDefaultValAttrInfo.addParamDefaultValueInfo(paramDefaultValue);
}
return paramDefaultValAttrInfo;
default:
throw new ProgramFileFormatException("unsupported attribute kind " + attribNameCPEntry.getValue());
}
}
use of org.ballerinalang.util.codegen.attributes.LocalVariableAttributeInfo in project ballerina by ballerina-lang.
the class Debugger method generateDebugHitMessage.
/**
* Generate debug hit message.
*
* @param ctx Current context.
* @param currentExecLine Current execution line.
* @param workerId Current thread id.
* @return message To be sent.
*/
private MessageDTO generateDebugHitMessage(WorkerExecutionContext ctx, LineNumberInfo currentExecLine, String workerId) {
MessageDTO message = new MessageDTO(DebugConstants.CODE_HIT, DebugConstants.MSG_HIT);
message.setThreadId(workerId);
BreakPointDTO breakPointDTO = new BreakPointDTO(currentExecLine.getPackageInfo().getPkgPath(), currentExecLine.getFileName(), currentExecLine.getLineNumber());
message.setLocation(breakPointDTO);
int callingIp = currentExecLine.getIp();
String pck = ctx.callableUnitInfo.getPackageInfo().getPkgPath();
String functionName = ctx.callableUnitInfo.getName();
LineNumberInfo callingLine = getLineNumber(ctx.callableUnitInfo.getPackageInfo().getPkgPath(), callingIp);
FrameDTO frameDTO = new FrameDTO(pck, functionName, callingLine.getFileName(), callingLine.getLineNumber());
message.addFrame(frameDTO);
LocalVariableAttributeInfo localVarAttrInfo = (LocalVariableAttributeInfo) ctx.workerInfo.getAttributeInfo(AttributeInfo.Kind.LOCAL_VARIABLES_ATTRIBUTE);
localVarAttrInfo.getLocalVariables().forEach(l -> {
VariableDTO variableDTO = new VariableDTO(l.getVariableName(), "Local");
switch(l.getVariableType().getTag()) {
case TypeTags.INT_TAG:
variableDTO.setBValue(new BInteger(ctx.workerLocal.longRegs[l.getVariableIndex()]));
break;
case TypeTags.FLOAT_TAG:
variableDTO.setBValue(new BFloat(ctx.workerLocal.doubleRegs[l.getVariableIndex()]));
break;
case TypeTags.STRING_TAG:
variableDTO.setBValue(new BString(ctx.workerLocal.stringRegs[l.getVariableIndex()]));
break;
case TypeTags.BOOLEAN_TAG:
variableDTO.setBValue(new BBoolean(ctx.workerLocal.intRegs[l.getVariableIndex()] == 1));
break;
case TypeTags.BLOB_TAG:
variableDTO.setBValue(new BBlob(ctx.workerLocal.byteRegs[l.getVariableIndex()]));
break;
default:
variableDTO.setBValue(ctx.workerLocal.refRegs[l.getVariableIndex()]);
break;
}
frameDTO.addVariable(variableDTO);
});
return message;
}
use of org.ballerinalang.util.codegen.attributes.LocalVariableAttributeInfo in project ballerina by ballerina-lang.
the class BLangVMStructs method createBConnector.
/**
* Create BConnector with given values.
*
* @param connectorInfo {@link ConnectorInfo} of the {@link BConnector}
* @param values field values of the connector ( including args ).
* @return BStruct instance.
*/
public static BConnector createBConnector(ConnectorInfo connectorInfo, Object... values) {
BConnector bConnector = new BConnector(connectorInfo.getType());
final LocalVariableAttributeInfo localVar = (LocalVariableAttributeInfo) connectorInfo.getAttributeInfo(AttributeInfo.Kind.LOCAL_VARIABLES_ATTRIBUTE);
int i = 0;
int[] indexes = new int[] { -1, -1, -1, -1, -1, -1 };
for (LocalVariableInfo variableInfo : localVar.getLocalVariables()) {
if (values.length < i + 1) {
break;
}
final BType varType = variableInfo.getVariableType();
setValue(bConnector, indexes, varType.getTag(), values[i]);
}
return bConnector;
}
Aggregations