Example #1
0
        /// <summary>
        /// Emit this code to load the identifier to the stack.
        /// </summary>
        /// <param name="cg">A CodeGenerator object</param>
        /// <param name="returnType">The type required by the caller</param>
        /// <returns>The symbol type of the value generated</returns>
        public override SymType Generate(CodeGenerator cg, SymType returnType)
        {
            if (cg == null) {
                throw new ArgumentNullException("cg");
            }
            Symbol sym = Symbol;
            SymType thisType;

            if (sym.Class == SymClass.INLINE) {
                GenerateInline(cg);
                thisType = sym.Type;
            } else if (sym.IsArray) {
                thisType = cg.GenerateLoadFromArray(this, false);
            } else if (sym.IsIntrinsic || sym.IsExternal) {
                cg.Emitter.LoadFunction(sym);
                thisType = SymType.INTEGER;
            } else if (sym.IsParameter) {
                cg.GenerateLoadArgument(sym);
                thisType = sym.Type;
            } else if (sym.Class == SymClass.FUNCTION) {
                cg.Emitter.LoadFunction(sym);
                thisType = SymType.INTEGER;
            } else if (sym.IsLocal) {
                cg.LoadLocal(sym);
                thisType = sym.Type;
            } else {
                Debug.Assert(false, "Unknown identifier type (not local OR parameter)");
                thisType = SymType.NONE;
            }
            if (HasSubstring) {
                thisType = GenerateLoadSubstring(cg);
            }
            return thisType;
        }