# HG changeset patch # User William Roberts # Date 1269294069 0 # Node ID fe474e3b08fb8c0013e887b4cf7816ff7fadc659 Created the examples directory, containing components called "before" and "after" The before directory is a component which illustrates typical issues that GCC has with the Symbian source code. Compiling this component (sbs -b bld.inf -k -c armv5_udeb_gcce4_4_1) will produce multiple errors, hence the use of "-k" to keep going. The after directory is the same component with fixes applied - compiling in the after directory should produce no errors. The aim is to keep the code very closely aligned to the before component, so that they can be compared with visual diff tools such as Beyond Compare. Sometimes it's valuable to be able to compile this code with the default production compiler, (currently RVCT 2.2) so the MMP files will switch the name of the generated executable if a different compiler is used. diff -r 000000000000 -r fe474e3b08fb examples/after/bld.inf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/after/bld.inf Mon Mar 22 21:41:09 2010 +0000 @@ -0,0 +1,18 @@ +// Copyright (c) 2010 Symbian Foundation Ltd. +// All rights reserved. +// This component and the accompanying materials are made available +// under the terms of the License "Eclipse Public License v1.0" +// which accompanies this distribution, and is available +// at the URL "http://www.eclipse.org/legal/epl-v10.html". +// +// Initial Contributors: +// Symbian Foundation - Initial contribution +// +// Description: +// BLD.INF file to build the example code + +PRJ_PLATFORMS +ARMV5 + +PRJ_MMPFILES +exe.mmp diff -r 000000000000 -r fe474e3b08fb examples/after/e32main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/after/e32main.cpp Mon Mar 22 21:41:09 2010 +0000 @@ -0,0 +1,26 @@ +// Copyright (c) 2010 Symbian Foundation Ltd. +// All rights reserved. +// This component and the accompanying materials are made available +// under the terms of the License "Eclipse Public License v1.0" +// which accompanies this distribution, and is available +// at the URL "http://www.eclipse.org/legal/epl-v10.html". +// +// Initial Contributors: +// Symbian Foundation - Initial contribution +// +// Description: +// Entrypoint for Symbian .exe, keeps the compiler & linker happy + +#include + +// helper function for other files which need to confuse the optimiser +int unknown(void) { return 42; } + +extern int source1(void); // from source1.cpp + +GLDEF_C TInt E32Main() + { + // Call trivial functions in other source files, to stop them being optimised away + return source1(); + } + diff -r 000000000000 -r fe474e3b08fb examples/after/example_classes.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/after/example_classes.h Mon Mar 22 21:41:09 2010 +0000 @@ -0,0 +1,25 @@ +// Copyright (c) 2010 Symbian Foundation Ltd. +// All rights reserved. +// This component and the accompanying materials are made available +// under the terms of the License "Eclipse Public License v1.0" +// which accompanies this distribution, and is available +// at the URL "http://www.eclipse.org/legal/epl-v10.html". +// +// Initial Contributors: +// Symbian Foundation - Initial contribution +// +// Description: +// Examples of things which GCC does not like in the Symbian codebase. + +// Various problems with classes + +class TClass1 + { + public: + TClass1(int a, int b); + int Average(); // Removed classname + + private: + int iA; + int iB; + }; diff -r 000000000000 -r fe474e3b08fb examples/after/exe.mmp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/after/exe.mmp Mon Mar 22 21:41:09 2010 +0000 @@ -0,0 +1,31 @@ +// Copyright (c) 2010 Symbian Foundation Ltd. +// All rights reserved. +// This component and the accompanying materials are made available +// under the terms of the License "Eclipse Public License v1.0" +// which accompanies this distribution, and is available +// at the URL "http://www.eclipse.org/legal/epl-v10.html". +// +// Initial Contributors: +// Symbian Foundation - Initial contribution +// +// Description: +// MMP file to build the example EXE + +#ifdef ARMCC_2_2 +#define TARGETNAME rvct22_exe.exe // for checking the RVCT2 compilation +#endif + + +#ifndef TARGETNAME +#define TARGETNAME gcce_exe.exe +#endif + +TARGET TARGETNAME +TARGETTYPE EXE + +SOURCE e32main.cpp +SOURCE source1.cpp + +SYSTEMINCLUDE /epoc32/include + +LIBRARY euser.lib diff -r 000000000000 -r fe474e3b08fb examples/after/source1.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/after/source1.cpp Mon Mar 22 21:41:09 2010 +0000 @@ -0,0 +1,41 @@ +// Copyright (c) 2010 Symbian Foundation Ltd. +// All rights reserved. +// This component and the accompanying materials are made available +// under the terms of the License "Eclipse Public License v1.0" +// which accompanies this distribution, and is available +// at the URL "http://www.eclipse.org/legal/epl-v10.html". +// +// Initial Contributors: +// Symbian Foundation - Initial contribution +// +// Description: +// Examples of things which GCC does not like in the Symbian codebase. +// See the corresponding file in "after" for the preferred way to do it + +// Over-qualified class names + +#include "example_classes.h" + +TClass1::TClass1(int a, int b) + : iA(a), iB(b) + {} + +int TClass1::Average() + { + return (iA+iB)/2; + } + +int helper1(int a) + { + TClass1 c(a,11); + return c.Average(); + } + + +//------------------------- +// Helper function to avoid things being optimised away +int source1(void) + { + extern int unknown(void); + return helper1(unknown()); + } diff -r 000000000000 -r fe474e3b08fb examples/before/bld.inf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/before/bld.inf Mon Mar 22 21:41:09 2010 +0000 @@ -0,0 +1,18 @@ +// Copyright (c) 2010 Symbian Foundation Ltd. +// All rights reserved. +// This component and the accompanying materials are made available +// under the terms of the License "Eclipse Public License v1.0" +// which accompanies this distribution, and is available +// at the URL "http://www.eclipse.org/legal/epl-v10.html". +// +// Initial Contributors: +// Symbian Foundation - Initial contribution +// +// Description: +// BLD.INF file to build the example code + +PRJ_PLATFORMS +ARMV5 + +PRJ_MMPFILES +exe.mmp diff -r 000000000000 -r fe474e3b08fb examples/before/e32main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/before/e32main.cpp Mon Mar 22 21:41:09 2010 +0000 @@ -0,0 +1,26 @@ +// Copyright (c) 2010 Symbian Foundation Ltd. +// All rights reserved. +// This component and the accompanying materials are made available +// under the terms of the License "Eclipse Public License v1.0" +// which accompanies this distribution, and is available +// at the URL "http://www.eclipse.org/legal/epl-v10.html". +// +// Initial Contributors: +// Symbian Foundation - Initial contribution +// +// Description: +// Entrypoint for Symbian .exe, keeps the compiler & linker happy + +#include + +// helper function for other files which need to confuse the optimiser +int unknown(void) { return 42; } + +extern int source1(void); // from source1.cpp + +GLDEF_C TInt E32Main() + { + // Call trivial functions in other source files, to stop them being optimised away + return source1(); + } + diff -r 000000000000 -r fe474e3b08fb examples/before/example_classes.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/before/example_classes.h Mon Mar 22 21:41:09 2010 +0000 @@ -0,0 +1,25 @@ +// Copyright (c) 2010 Symbian Foundation Ltd. +// All rights reserved. +// This component and the accompanying materials are made available +// under the terms of the License "Eclipse Public License v1.0" +// which accompanies this distribution, and is available +// at the URL "http://www.eclipse.org/legal/epl-v10.html". +// +// Initial Contributors: +// Symbian Foundation - Initial contribution +// +// Description: +// Examples of things which GCC does not like in the Symbian codebase. + +// Various problems with classes + +class TClass1 + { + public: + TClass1(int a, int b); + int TClass1::Average(); // Error! Member function name should not be qualified + + private: + int iA; + int iB; + }; diff -r 000000000000 -r fe474e3b08fb examples/before/exe.mmp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/before/exe.mmp Mon Mar 22 21:41:09 2010 +0000 @@ -0,0 +1,31 @@ +// Copyright (c) 2010 Symbian Foundation Ltd. +// All rights reserved. +// This component and the accompanying materials are made available +// under the terms of the License "Eclipse Public License v1.0" +// which accompanies this distribution, and is available +// at the URL "http://www.eclipse.org/legal/epl-v10.html". +// +// Initial Contributors: +// Symbian Foundation - Initial contribution +// +// Description: +// MMP file to build the example EXE + +#ifdef ARMCC_2_2 +#define TARGETNAME rvct22_exe.exe // for checking the RVCT2 compilation +#endif + + +#ifndef TARGETNAME +#define TARGETNAME gcce_exe.exe +#endif + +TARGET TARGETNAME +TARGETTYPE EXE + +SOURCE e32main.cpp +SOURCE source1.cpp + +SYSTEMINCLUDE /epoc32/include + +LIBRARY euser.lib diff -r 000000000000 -r fe474e3b08fb examples/before/source1.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/before/source1.cpp Mon Mar 22 21:41:09 2010 +0000 @@ -0,0 +1,41 @@ +// Copyright (c) 2010 Symbian Foundation Ltd. +// All rights reserved. +// This component and the accompanying materials are made available +// under the terms of the License "Eclipse Public License v1.0" +// which accompanies this distribution, and is available +// at the URL "http://www.eclipse.org/legal/epl-v10.html". +// +// Initial Contributors: +// Symbian Foundation - Initial contribution +// +// Description: +// Examples of things which GCC does not like in the Symbian codebase. +// See the corresponding file in "after" for the preferred way to do it + +// Over-qualified class names + +#include "example_classes.h" + +TClass1::TClass1(int a, int b) + : iA(a), iB(b) + {} + +int TClass1::Average() + { + return (iA+iB)/2; + } + +int helper1(int a) + { + TClass1 c(a,11); + return c.Average(); + } + + +//------------------------- +// Helper function to avoid things being optimised away +int source1(void) + { + extern int unknown(void); + return helper1(unknown()); + }