LCOV - code coverage report
Current view: top level - codemaker/source/javamaker - classfile.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 2 2 100.0 %
Date: 2015-06-13 12:38:46 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #ifndef INCLUDED_CODEMAKER_SOURCE_JAVAMAKER_CLASSFILE_HXX
      21             : #define INCLUDED_CODEMAKER_SOURCE_JAVAMAKER_CLASSFILE_HXX
      22             : 
      23             : #include "codemaker/unotype.hxx"
      24             : #include "sal/types.h"
      25             : 
      26             : #include <list>
      27             : #include <map>
      28             : #include <utility>
      29             : #include <vector>
      30             : 
      31             : class FileStream;
      32             : 
      33             : namespace codemaker { namespace javamaker {
      34             : 
      35             : class ClassFile {
      36             : public:
      37             :     enum AccessFlags {
      38             :         ACC_PUBLIC = 0x0001,
      39             :         ACC_PRIVATE = 0x0002,
      40             :         ACC_STATIC = 0x0008,
      41             :         ACC_FINAL = 0x0010,
      42             :         ACC_SUPER = 0x0020,
      43             :         ACC_VARARGS = 0x0080,
      44             :         ACC_INTERFACE = 0x0200,
      45             :         ACC_ABSTRACT = 0x0400,
      46             :         ACC_SYNTHETIC = 0x1000
      47             :     };
      48             : 
      49             :     class Code {
      50             :     public:
      51             :         typedef std::vector< unsigned char >::size_type Branch;
      52             :         typedef std::vector< unsigned char >::size_type Position;
      53             : 
      54             :         ~Code();
      55             : 
      56             :         void instrAastore();
      57             :         void instrAconstNull();
      58             :         void instrAnewarray(rtl::OString const & type);
      59             :         void instrAreturn();
      60             :         void instrAthrow();
      61             :         void instrCheckcast(rtl::OString const & type);
      62             :         void instrDup();
      63             : 
      64             :         void instrGetstatic(
      65             :             rtl::OString const & type, rtl::OString const & name,
      66             :             rtl::OString const & descriptor);
      67             : 
      68             :         Branch instrIfAcmpne();
      69             :         Branch instrIfeq();
      70             :         Branch instrIfnull();
      71             : 
      72             :         void instrInstanceof(rtl::OString const & type);
      73             : 
      74             :         void instrInvokeinterface(
      75             :             rtl::OString const & type, rtl::OString const & name,
      76             :             rtl::OString const & descriptor, sal_uInt8 args);
      77             : 
      78             :         void instrInvokespecial(
      79             :             rtl::OString const & type, rtl::OString const & name,
      80             :             rtl::OString const & descriptor);
      81             : 
      82             :         void instrInvokestatic(
      83             :             rtl::OString const & type, rtl::OString const & name,
      84             :             rtl::OString const & descriptor);
      85             : 
      86             :         void instrInvokevirtual(
      87             :             rtl::OString const & type, rtl::OString const & name,
      88             :             rtl::OString const & descriptor);
      89             : 
      90             :         void instrLookupswitch(
      91             :             Code const * defaultBlock,
      92             :             std::list< std::pair< sal_Int32, Code * > > const & blocks);
      93             : 
      94             :         void instrNew(rtl::OString const & type);
      95             :         void instrNewarray(codemaker::UnoType::Sort sort);
      96             :         void instrPop();
      97             : 
      98             :         void instrPutfield(
      99             :             rtl::OString const & type, rtl::OString const & name,
     100             :             rtl::OString const & descriptor);
     101             : 
     102             :         void instrPutstatic(
     103             :             rtl::OString const & type, rtl::OString const & name,
     104             :             rtl::OString const & descriptor);
     105             : 
     106             :         void instrReturn();
     107             :         void instrSwap();
     108             : 
     109             :         void instrTableswitch(
     110             :             Code const * defaultBlock, sal_Int32 low,
     111             :             std::list< Code * > const & blocks);
     112             : 
     113             :         void loadIntegerConstant(sal_Int32 value);
     114             :         void loadStringConstant(rtl::OString const & value);
     115             :         void loadLocalInteger(sal_uInt16 index);
     116             :         void loadLocalLong(sal_uInt16 index);
     117             :         void loadLocalFloat(sal_uInt16 index);
     118             :         void loadLocalDouble(sal_uInt16 index);
     119             :         void loadLocalReference(sal_uInt16 index);
     120             :         void storeLocalReference(sal_uInt16 index);
     121             :         void branchHere(Branch branch);
     122             : 
     123             :         void addException(
     124             :             Position start, Position end, Position handler,
     125             :             rtl::OString const & type);
     126             : 
     127        5919 :         void setMaxStackAndLocals(sal_uInt16 maxStack, sal_uInt16 maxLocals)
     128        5919 :         { m_maxStack = maxStack; m_maxLocals = maxLocals; }
     129             : 
     130             :         Position getPosition() const;
     131             : 
     132             :     private:
     133             :         Code(Code &) SAL_DELETED_FUNCTION;
     134             :         void operator =(const Code&) SAL_DELETED_FUNCTION;
     135             : 
     136             :         explicit Code(ClassFile & classFile);
     137             : 
     138             :         void ldc(sal_uInt16 index);
     139             : 
     140             :         void accessLocal(
     141             :             sal_uInt16 index, sal_uInt8 fastOp, sal_uInt8 normalOp);
     142             : 
     143             :         ClassFile & m_classFile;
     144             :         sal_uInt16 m_maxStack;
     145             :         sal_uInt16 m_maxLocals;
     146             :         std::vector< unsigned char > m_code;
     147             :         sal_uInt16 m_exceptionTableLength;
     148             :         std::vector< unsigned char > m_exceptionTable;
     149             : 
     150             :         friend class ClassFile;
     151             :     };
     152             : 
     153             :     ClassFile(
     154             :         AccessFlags accessFlags, rtl::OString const & thisClass,
     155             :         rtl::OString const & superClass, rtl::OString const & signature);
     156             : 
     157             :     ~ClassFile();
     158             : 
     159             :     Code * newCode();
     160             : 
     161             :     sal_uInt16 addIntegerInfo(sal_Int32 value);
     162             :     sal_uInt16 addFloatInfo(float value);
     163             :     sal_uInt16 addLongInfo(sal_Int64 value);
     164             :     sal_uInt16 addDoubleInfo(double value);
     165             : 
     166             :     void addInterface(rtl::OString const & interface);
     167             : 
     168             :     void addField(
     169             :         AccessFlags accessFlags, rtl::OString const & name,
     170             :         rtl::OString const & descriptor, sal_uInt16 constantValueIndex,
     171             :         rtl::OString const & signature);
     172             : 
     173             :     void addMethod(
     174             :         AccessFlags accessFlags, rtl::OString const & name,
     175             :         rtl::OString const & descriptor, Code const * code,
     176             :         std::vector< rtl::OString > const & exceptions,
     177             :         rtl::OString const & signature);
     178             : 
     179             :     void write(FileStream & file) const; //TODO
     180             : 
     181             : private:
     182             :     typedef std::map< rtl::OString, sal_uInt16 > Map;
     183             : 
     184             :     ClassFile(ClassFile &) SAL_DELETED_FUNCTION;
     185             :     void operator =(const ClassFile&) SAL_DELETED_FUNCTION;
     186             : 
     187             :     sal_uInt16 nextConstantPoolIndex(sal_uInt16 width);
     188             :     sal_uInt16 addUtf8Info(rtl::OString const & value);
     189             :     sal_uInt16 addClassInfo(rtl::OString const & type);
     190             :     sal_uInt16 addStringInfo(rtl::OString const & value);
     191             : 
     192             :     sal_uInt16 addFieldrefInfo(
     193             :         rtl::OString const & type, rtl::OString const & name,
     194             :         rtl::OString const & descriptor);
     195             : 
     196             :     sal_uInt16 addMethodrefInfo(
     197             :         rtl::OString const & type, rtl::OString const & name,
     198             :         rtl::OString const & descriptor);
     199             : 
     200             :     sal_uInt16 addInterfaceMethodrefInfo(
     201             :         rtl::OString const & type, rtl::OString const & name,
     202             :         rtl::OString const & descriptor);
     203             : 
     204             :     sal_uInt16 addNameAndTypeInfo(
     205             :         rtl::OString const & name, rtl::OString const & descriptor);
     206             : 
     207             :     void appendSignatureAttribute(
     208             :         std::vector< unsigned char > & stream, rtl::OString const & signature);
     209             : 
     210             :     sal_uInt16 m_constantPoolCount;
     211             :     std::vector< unsigned char > m_constantPool;
     212             :     std::map< rtl::OString, sal_uInt16 > m_utf8Infos;
     213             :     std::map< sal_Int32, sal_uInt16 > m_integerInfos;
     214             :     std::map< sal_Int64, sal_uInt16 > m_longInfos;
     215             :     std::map< float, sal_uInt16 > m_floatInfos;
     216             :     std::map< double, sal_uInt16 > m_doubleInfos;
     217             :     std::map< sal_uInt16, sal_uInt16 > m_classInfos;
     218             :     std::map< sal_uInt16, sal_uInt16 > m_stringInfos;
     219             :     std::map< sal_uInt32, sal_uInt16 > m_fieldrefInfos;
     220             :     std::map< sal_uInt32, sal_uInt16 > m_methodrefInfos;
     221             :     std::map< sal_uInt32, sal_uInt16 > m_interfaceMethodrefInfos;
     222             :     std::map< sal_uInt32, sal_uInt16 > m_nameAndTypeInfos;
     223             :     AccessFlags m_accessFlags;
     224             :     sal_uInt16 m_thisClass;
     225             :     sal_uInt16 m_superClass;
     226             :     sal_uInt16 m_interfacesCount;
     227             :     std::vector< unsigned char > m_interfaces;
     228             :     sal_uInt16 m_fieldsCount;
     229             :     std::vector< unsigned char > m_fields;
     230             :     sal_uInt16 m_methodsCount;
     231             :     std::vector< unsigned char > m_methods;
     232             :     sal_uInt16 m_attributesCount;
     233             :     std::vector< unsigned char > m_attributes;
     234             : 
     235             :     friend class Code;
     236             : };
     237             : 
     238             : } }
     239             : 
     240             : #endif // INCLUDED_CODEMAKER_SOURCE_JAVAMAKER_CLASSFILE_HXX
     241             : 
     242             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11