private FixedOffsetVariable ProcessVariableDeclaration(Token variableType, DataGroup container, Token parent, Modifiers modifiers) { FixedOffsetVariable newVariable; int thisSize = 0; if (variableType.Type == TokenType.StructType) { ScriptStruct childStruct = (ScriptStruct)variableType.Value; if (childStruct.IsManaged) { thisSize = FixedOffsetVariable.POINTER_SIZE_IN_BYTES; newVariable = new FixedOffsetVariable(variableType, container.SizeInBytes, true); if ((childStruct != container) && (parent != null) && (childStruct.HasNonImportedMemberOfType(parent))) { throw new CompilerMessage(ErrorCode.CircularReference, "The type '" + childStruct.Name + "' has a reference to this struct, so you cannot also have a reference this way round"); } } else if (childStruct == container) { throw new CompilerMessage(ErrorCode.StructInsideItself, "A struct cannot be contained within itself"); } else { thisSize = childStruct.SizeInBytes; newVariable = new FixedOffsetVariable(variableType, container.SizeInBytes, thisSize); } } else if (variableType is ScalarVariableTypeToken) { thisSize = ((ScalarVariableTypeToken)variableType).SizeInBytes; newVariable = new FixedOffsetVariable(variableType, container.SizeInBytes, thisSize); } else if (variableType.Type == TokenType.EnumType) { thisSize = FixedOffsetVariable.ENUM_SIZE_IN_BYTES; newVariable = new FixedOffsetVariable(variableType, container.SizeInBytes, thisSize); } else { throw new CompilerMessage(ErrorCode.CannotUseTypeInStruct, "Cannot add variable of type '" + variableType.Name + "' to struct"); } newVariable.IsAttributeProperty = modifiers.HasModifier(Modifiers.ATTRIBUTE); newVariable.IsImported = modifiers.HasModifier(Modifiers.IMPORT); if ((newVariable.IsAttributeProperty) && (!newVariable.IsImported)) { throw new CompilerMessage(ErrorCode.AttributesMustBeImported, "Attribute types must be imported"); } if ((newVariable.IsImported) && (!newVariable.IsAttributeProperty) && (parent != null)) { throw new CompilerMessage(ErrorCode.InvalidUseOfKeyword, "'import' is invalid in this context"); } if (newVariable.IsImported) { // No memory needed for imported vars newVariable.Offset = 0; thisSize = 0; } container.Members.Add(newVariable); container.SizeInBytes += thisSize; return(newVariable); }
private FixedOffsetVariable ProcessVariableDeclaration(Token variableType, DataGroup container, Token parent, Modifiers modifiers) { FixedOffsetVariable newVariable; int thisSize = 0; if (variableType.Type == TokenType.StructType) { ScriptStruct childStruct = (ScriptStruct)variableType.Value; if (childStruct.IsManaged) { thisSize = FixedOffsetVariable.POINTER_SIZE_IN_BYTES; newVariable = new FixedOffsetVariable(variableType, container.SizeInBytes, true); if ((childStruct != container) && (parent != null) && (childStruct.HasNonImportedMemberOfType(parent))) { throw new CompilerMessage(ErrorCode.CircularReference, "The type '" + childStruct.Name + "' has a reference to this struct, so you cannot also have a reference this way round"); } } else if (childStruct == container) { throw new CompilerMessage(ErrorCode.StructInsideItself, "A struct cannot be contained within itself"); } else { thisSize = childStruct.SizeInBytes; newVariable = new FixedOffsetVariable(variableType, container.SizeInBytes, thisSize); } } else if (variableType is ScalarVariableTypeToken) { thisSize = ((ScalarVariableTypeToken)variableType).SizeInBytes; newVariable = new FixedOffsetVariable(variableType, container.SizeInBytes, thisSize); } else if (variableType.Type == TokenType.EnumType) { thisSize = FixedOffsetVariable.ENUM_SIZE_IN_BYTES; newVariable = new FixedOffsetVariable(variableType, container.SizeInBytes, thisSize); } else { throw new CompilerMessage(ErrorCode.CannotUseTypeInStruct, "Cannot add variable of type '" + variableType.Name + "' to struct"); } newVariable.IsAttributeProperty = modifiers.HasModifier(Modifiers.ATTRIBUTE); newVariable.IsImported = modifiers.HasModifier(Modifiers.IMPORT); if ((newVariable.IsAttributeProperty) && (!newVariable.IsImported)) { throw new CompilerMessage(ErrorCode.AttributesMustBeImported, "Attribute types must be imported"); } if ((newVariable.IsImported) && (!newVariable.IsAttributeProperty) && (parent != null)) { throw new CompilerMessage(ErrorCode.InvalidUseOfKeyword, "'import' is invalid in this context"); } if (newVariable.IsImported) { // No memory needed for imported vars newVariable.Offset = 0; thisSize = 0; } container.Members.Add(newVariable); container.SizeInBytes += thisSize; return newVariable; }