diff options
Diffstat (limited to 'core/org.eclipse.cdt.ui.tests/resources/formatter')
8 files changed, 352 insertions, 0 deletions
diff --git a/core/org.eclipse.cdt.ui.tests/resources/formatter/complex/After.cpp b/core/org.eclipse.cdt.ui.tests/resources/formatter/complex/After.cpp new file mode 100644 index 00000000000..8c3235d3a91 --- /dev/null +++ b/core/org.eclipse.cdt.ui.tests/resources/formatter/complex/After.cpp @@ -0,0 +1,26 @@ + +/* This is sample code to test the formatter */ + +class Complex { +private: + float re; + float im; +public: + Complex(float re, float im) : + re(re), im(im) { + } + float GetRe() { + return re; + } + float GetIm() { + return im; + } + void Set(float r, float i); + /* Set real part */ + void SetRe(float r); + /* + * Set imaginary part + */ + void SetIm(float i); + void Print(); +}; diff --git a/core/org.eclipse.cdt.ui.tests/resources/formatter/complex/Before.cpp b/core/org.eclipse.cdt.ui.tests/resources/formatter/complex/Before.cpp new file mode 100644 index 00000000000..7a307a77d04 --- /dev/null +++ b/core/org.eclipse.cdt.ui.tests/resources/formatter/complex/Before.cpp @@ -0,0 +1,24 @@ + + + /* This is sample code to test the formatter */ + + + + class Complex { + private : + float re ; float im; + public: + Complex(float re, float im) : + re(re), im(im) {} + float GetRe() { return re;} +float GetIm() { + return im; + } + void Set(float r, float i); + /* Set real part */ + void SetRe(float r) ; + /* + * Set imaginary part + */ + void SetIm(float i);void Print(); + }; diff --git a/core/org.eclipse.cdt.ui.tests/resources/formatter/preview/After.cpp b/core/org.eclipse.cdt.ui.tests/resources/formatter/preview/After.cpp new file mode 100644 index 00000000000..d595123b02e --- /dev/null +++ b/core/org.eclipse.cdt.ui.tests/resources/formatter/preview/After.cpp @@ -0,0 +1,43 @@ +/* + * Indentation + */ +#include <math.h> +class Point { +public: + Point(double xc, double yc) : + x(xc), y(yc) { + } + double distance(const Point& other) const; + int compareX(const Point& other) const; + double x; + double y; +}; +double Point::distance(const Point& other) const { + double dx = x - other.x; + double dy = y - other.y; + return sqrt(dx * dx + dy * dy); +} +int Point::compareX(const Point& other) const { + if (x < other.x) { + return -1; + } else if (x > other.x) { + return 1; + } else { + return 0; + } +} +namespace FOO { +int foo(int bar) const { + switch (bar) { + case 0: + ++bar; + break; + case 1: + --bar; + default: { + bar += bar; + break; + } + } +} +} // end namespace FOO diff --git a/core/org.eclipse.cdt.ui.tests/resources/formatter/preview/Before.cpp b/core/org.eclipse.cdt.ui.tests/resources/formatter/preview/Before.cpp new file mode 100644 index 00000000000..a48488347f2 --- /dev/null +++ b/core/org.eclipse.cdt.ui.tests/resources/formatter/preview/Before.cpp @@ -0,0 +1,5 @@ +/* + * Indentation + */ +#include <math.h> +class Point {public:Point(double xc, double yc) : x(xc), y(yc) {}double distance(const Point& other) const;int compareX(const Point& other) const;double x;double y;};double Point::distance(const Point& other) const {double dx = x - other.x;double dy = y - other.y;return sqrt(dx * dx + dy * dy);}int Point::compareX(const Point& other) const {if (x < other.x) {return -1;} else if (x > other.x) {return 1;} else {return 0;}}namespace FOO {int foo(int bar) const {switch (bar) {case 0:++bar;break;case 1:--bar;default: {bar += bar;break;}}}} // end namespace FOO diff --git a/core/org.eclipse.cdt.ui.tests/resources/formatter/sample/After.cpp b/core/org.eclipse.cdt.ui.tests/resources/formatter/sample/After.cpp new file mode 100644 index 00000000000..4fac3784e72 --- /dev/null +++ b/core/org.eclipse.cdt.ui.tests/resources/formatter/sample/After.cpp @@ -0,0 +1,55 @@ +#include <Simple.h> + +const SimpleStruct simpleStruct = + { + 1 + , "mySimple" + , 0.1232 +}; + +#define SIZEOF( A, B ) sizeof( A.B ) + +#define FOREVER \ + for(;;)\ +{\ + \ + } + +const OtherStruct array[] = + { + { +#if FOO + "foo" +# else + "bar" +#endif + , SIZEOF( simpleStruct, num ) + , &t_int + , 0 + } + , { + "name" + , SIZEOF( simpleStruct, floatnum ) + , &t_float + , 1 + } +}; + +// single line outside scope + +void SimpleStruct_construct( + struct SimpleStruct * const this ) + { + // single line + this->num = 1; + this->name = "boo"; + this->floatNum = 1.5; +} + +int ConnectParams_doSomething(const struct SimpleStruct * const this ) + { +/* + * multiline + */ + return 1; + } diff --git a/core/org.eclipse.cdt.ui.tests/resources/formatter/sample/Before.cpp b/core/org.eclipse.cdt.ui.tests/resources/formatter/sample/Before.cpp new file mode 100644 index 00000000000..e1578fe118a --- /dev/null +++ b/core/org.eclipse.cdt.ui.tests/resources/formatter/sample/Before.cpp @@ -0,0 +1,55 @@ +#include <Simple.h> + +const SimpleStruct simpleStruct = +{ + 1 + , "mySimple" + , 0.1232 +}; + +#define SIZEOF( A, B ) sizeof( A.B ) + + #define FOREVER \ + for(;;)\ +{\ + \ + } + +const OtherStruct array[] = +{ + { +#if FOO + "foo" + # else + "bar" +#endif + , SIZEOF( simpleStruct, num ) + , &t_int + , 0 + } + , { + "name" + , SIZEOF( simpleStruct, floatnum ) + , &t_float + , 1 + } +}; + +// single line outside scope + +void SimpleStruct_construct( +struct SimpleStruct * const this ) + { +// single line +this->num = 1; +this->name = "boo"; +this->floatNum = 1.5; + } + +int ConnectParams_doSomething( const struct SimpleStruct * const this ) + { +/* + * multiline + */ + return 1; + } diff --git a/core/org.eclipse.cdt.ui.tests/resources/formatter/templates/After.cpp b/core/org.eclipse.cdt.ui.tests/resources/formatter/templates/After.cpp new file mode 100644 index 00000000000..fdfe7fe0d5a --- /dev/null +++ b/core/org.eclipse.cdt.ui.tests/resources/formatter/templates/After.cpp @@ -0,0 +1,74 @@ +class Key; +class Value; +class SortAlgorithm; +class DefaultSort; +class T; +class X; +class Y; +class Bar; +class Foo { + template<class Bar> void fum(int i); +}; + +// TEMPLATE_STRUCT +template<class Key, class Value, class SortAlgorithm=DefaultSort> struct Map { + Key * keys; + Value * values; + SortAlgorithm * sortAlgorithm; + Map(); +}; + +// TEMPLATE_CLASS +template<class T> class nonVector { +private: + T * head; + +public: + nonVector() { + head =new T(); + } + int length() { + return 1; + } + const T &first() const; +}; + +// TEMPLATE_UNION +template<class X, class Y, int size=16> union ArrayOverlay { +public: + X x[size]; + Y y[size]; + + static int numArrays; +}; + +// TEMPLATE_METHODS +class TemplateContainer { + // these are in an enclosing class + template<class Bar> void fum(int i); + template<int> void scrum(void) { + } + ; +}; + +// TEMPLATE_FUNCTION +template<class T> const T &nonVector<T>::first() const { + return *head; +} + +template<class X> bool IsGreaterThan(X, X); + +template<class Bar> void Foo::fum(int i) { +} + +// TEMPLATE_VARIABLES +template<bool threads, int inst> char + * default_alloc_template<threads, inst>::S_start_free = 0; + +// an instantiation, not a template: +complex +<float> cf(0,0); +//template<class Language, class CharacterSet, class SortAlgorithm<CharacterSet> > +//Dictionary* TheSpellCheckDictionary; + +int success; diff --git a/core/org.eclipse.cdt.ui.tests/resources/formatter/templates/Before.cpp b/core/org.eclipse.cdt.ui.tests/resources/formatter/templates/Before.cpp new file mode 100644 index 00000000000..10e180dc5fd --- /dev/null +++ b/core/org.eclipse.cdt.ui.tests/resources/formatter/templates/Before.cpp @@ -0,0 +1,70 @@ +class Key; +class Value; +class SortAlgorithm; +class DefaultSort; +class T; +class X; +class Y; +class Bar; +class Foo { + template<class Bar> void fum(int i); +}; + +// TEMPLATE_STRUCT +template<class Key, class Value, class SortAlgorithm=DefaultSort> +struct Map +{ + Key* keys; + Value* values; + SortAlgorithm* sortAlgorithm; + Map(); +}; + +// TEMPLATE_CLASS +template<class T> class nonVector { +private: T* head; + +public: + nonVector() {head =new T();} + int length() {return 1;} + const T& first() const; +}; + +// TEMPLATE_UNION +template<class X, class Y, int size=16> +union ArrayOverlay { +public: + X x[size]; Y y[size]; + + static int numArrays; +}; + +// TEMPLATE_METHODS +class TemplateContainer { + // these are in an enclosing class + template<class Bar> void fum(int i); + template<int> + void scrum(void) {} + ; +}; + +// TEMPLATE_FUNCTION +template<class T> const T& nonVector<T>::first() const + { + return *head; +} + +template<class X> bool IsGreaterThan(X,X); + +template<class Bar> void Foo::fum(int i) {} + +// TEMPLATE_VARIABLES +template <bool threads, int inst> char* default_alloc_template<threads, inst>::S_start_free = 0; + +// an instantiation, not a template: +complex +<float> cf(0,0); +//template<class Language, class CharacterSet, class SortAlgorithm<CharacterSet> > +//Dictionary* TheSpellCheckDictionary; + +int success; |