package com.oracle.truffle.llvm.parser.metadata;
import com.oracle.truffle.llvm.parser.listeners.Metadata;
public final class MDGlobalVariable extends MDVariable implements MDBaseNode {
private final boolean isLocalToCompileUnit;
private final boolean isDefinedInCompileUnit;
private MDBaseNode displayName;
private MDBaseNode linkageName;
private MDBaseNode staticMemberDeclaration;
private MDBaseNode variable;
private MDBaseNode compileUnit;
private MDGlobalVariable(long line, boolean isLocalToCompileUnit, boolean isDefinedInCompileUnit) {
super(line);
this.isLocalToCompileUnit = isLocalToCompileUnit;
this.isDefinedInCompileUnit = isDefinedInCompileUnit;
this.displayName = MDVoidNode.INSTANCE;
this.linkageName = MDVoidNode.INSTANCE;
this.staticMemberDeclaration = MDVoidNode.INSTANCE;
this.variable = MDVoidNode.INSTANCE;
this.compileUnit = MDVoidNode.INSTANCE;
}
@Override
public void accept(MetadataVisitor visitor) {
visitor.visit(this);
}
public MDBaseNode getDisplayName() {
return displayName;
}
public MDBaseNode getLinkageName() {
return linkageName;
}
public boolean isLocalToCompileUnit() {
return isLocalToCompileUnit;
}
public boolean isDefinedInCompileUnit() {
return isDefinedInCompileUnit;
}
public MDBaseNode getStaticMemberDeclaration() {
return staticMemberDeclaration;
}
public MDBaseNode getVariable() {
return variable;
}
public MDBaseNode getCompileUnit() {
return compileUnit;
}
public void setCompileUnit(MDBaseNode compileUnit) {
this.compileUnit = compileUnit;
}
@Override
public void replace(MDBaseNode oldValue, MDBaseNode newValue) {
super.replace(oldValue, newValue);
if (displayName == oldValue) {
displayName = newValue;
}
if (linkageName == oldValue) {
linkageName = newValue;
}
if (staticMemberDeclaration == oldValue) {
staticMemberDeclaration = newValue;
}
if (variable == oldValue) {
variable = newValue;
}
if (compileUnit == oldValue) {
compileUnit = newValue;
}
}
private static final int ARGINDEX_38_SCOPE = 1;
private static final int ARGINDEX_38_NAME = 2;
private static final int ARGINDEX_38_LINKAGENAME = 3;
private static final int ARGINDEX_38_FILE = 4;
private static final int ARGINDEX_38_LINE = 5;
private static final int ARGINDEX_38_TYPE = 6;
private static final int ARGINDEX_38_LOCALTOCOMPILEUNIT = 7;
private static final int ARGINDEX_38_DEFINEDINCOMPILEUNIT = 8;
public static MDGlobalVariable create38(long[] args, MetadataValueList md) {
final long version = args[0] >> 1;
final long line = args[ARGINDEX_38_LINE];
final boolean localToCompileUnit = args[ARGINDEX_38_LOCALTOCOMPILEUNIT] == 1;
final boolean definedInCompileUnit = args[ARGINDEX_38_DEFINEDINCOMPILEUNIT] == 1;
final MDGlobalVariable globalVariable = new MDGlobalVariable(line, localToCompileUnit, definedInCompileUnit);
globalVariable.setScope(md.getNullable(args[ARGINDEX_38_SCOPE], globalVariable));
globalVariable.setFile(md.getNullable(args[ARGINDEX_38_FILE], globalVariable));
globalVariable.setType(md.getNullable(args[ARGINDEX_38_TYPE], globalVariable));
final MDBaseNode name = md.getNullable(args[ARGINDEX_38_NAME], globalVariable);
globalVariable.setName(name);
globalVariable.displayName = name;
if (version == 2) {
globalVariable.staticMemberDeclaration = md.getNullable(args[9], globalVariable);
} else {
globalVariable.staticMemberDeclaration = md.getNullable(args[10], globalVariable);
globalVariable.variable = md.getNullable(args[9], globalVariable);
}
globalVariable.linkageName = md.getNullable(args[ARGINDEX_38_LINKAGENAME], globalVariable);
return globalVariable;
}
private static final int ARGINDEX_32_SCOPE = 2;
private static final int ARGINDEX_32_NAME = 3;
private static final int ARGINDEX_32_DISPLAYNAME = 4;
private static final int ARGINDEX_32_LINKAGENAME = 5;
private static final int ARGINDEX_32_FILE = 6;
private static final int ARGINDEX_32_LINE = 7;
private static final int ARGINDEX_32_TYPE = 8;
private static final int ARGINDEX_32_LOCALTOCOMPILEUNIT = 9;
private static final int ARGINDEX_32_DEFINEDINCOMPILEUNIT = 10;
private static final int ARGINDEX_32_VARIABLE = 11;
public static MDGlobalVariable create32(long[] args, Metadata md) {
final long line = ParseUtil.asInt(args, ARGINDEX_32_LINE, md);
final boolean localToCompileUnit = ParseUtil.asBoolean(args, ARGINDEX_32_LOCALTOCOMPILEUNIT, md);
final boolean inCompileUnit = ParseUtil.asBoolean(args, ARGINDEX_32_DEFINEDINCOMPILEUNIT, md);
final MDGlobalVariable globalVariable = new MDGlobalVariable(line, localToCompileUnit, inCompileUnit);
globalVariable.setScope(ParseUtil.resolveReference(args, ARGINDEX_32_SCOPE, globalVariable, md));
globalVariable.setFile(ParseUtil.resolveReference(args, ARGINDEX_32_FILE, globalVariable, md));
globalVariable.setType(ParseUtil.resolveReference(args, ARGINDEX_32_TYPE, globalVariable, md));
globalVariable.setName(ParseUtil.resolveReference(args, ARGINDEX_32_NAME, globalVariable, md));
globalVariable.displayName = ParseUtil.resolveReference(args, ARGINDEX_32_DISPLAYNAME, globalVariable, md);
globalVariable.linkageName = ParseUtil.resolveReference(args, ARGINDEX_32_LINKAGENAME, globalVariable, md);
globalVariable.variable = ParseUtil.resolveSymbol(args, ARGINDEX_32_VARIABLE, md);
return globalVariable;
}
}